Mutations are not set up in the schema

Having an issue with setting up mutations in my project using npm, apollo server, and typeorm. Every time I attempt to create a mutation, I receive the error message "Schema is not configured for mutations". Searching for solutions has been fruitless as most explanations involve different libraries that do not apply to my setup. Even after studying examples where importing mutations into resolver files seems successful, the same error persists. Could it be necessary to modify the tsconfig.json file to allow schemas with mutations?

This is what the mutation code looks like:

import {InputType, Field} from "type-graphql";

@InputType()
export class CreateBookInput{
    @Field()
    title: string;

    @Field()
    author: string;
}

The imported class is used in the resolver class:


import { Resolver, Query, Mutation, Arg } from "type-graphql";
import { Book } from "../models/book";
import {CreateBookInput} from "../inputs/createBookInput";

@Resolver()
export class BookResolver {
    @Query(() => [Book])
    books() {
        return Book.find()
    }

    @Mutation(() => Book)
    async createBook(@Arg("data") data: CreateBookInput) {
        const book = Book.create(data);
        await book.save();
        return book;
    }

}

The resolver class is then imported into the index.ts file where the schema is handled:

import "reflect-metadata";
import { createConnection } from "typeorm";
import { ApolloServer } from "apollo-server";
import { BookResolver } from "./resolvers/bookResolver"; // add this
import { buildSchema } from "type-graphql";

async function main() {
  const connection = await createConnection()
  const schema = await buildSchema({
    resolvers: [BookResolver]
  })
  const server = new ApolloServer({ schema })
  await server.listen(4000)
  console.log("Server has started!")
}

main();

Appreciate any assistance or guidance on this matter.

Answer №1

It's finally working!

After recompiling the project using tsc and running it again, everything is functioning as expected without any errors. I mistakenly believed that running npm start would automatically compile the project, but it turns out I was mistaken.

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

Typescript TypeError: Unable to call function this.array[i].greet as it is not defined

When attempting to call my function, I am encountering an error. Interestingly, everything works fine when I create just one object of someClass and then utilize the greet function. This is what does not work (someArray being an array of type someClass): ...

Discover the process of changing a prop with a button click in NextJS

In my NextJs project, I have a video player component that displays videos using a {videoLink} prop: <ReactPlayer playing={true} controls={true} muted={true} loop={true} width="100" height="100" url={videoLinkDeep} poster="ima ...

SolidJS directives utilizing use:___ result in TypeScript errors when used in JSX

As I work on converting the forms example from JS to TS, I came across a typescript error related to directives in HTML: https://i.sstatic.net/Hl8Pv.png It appears that validate and formSubmit are being recognized as unused variables by typescript, result ...

Ways to retrieve dictionary keys as an array in Angular

Here is an example of an Angular dictionary: { ARRAY1: [{...}, {...}, {...}] ARRAY2: [{...}, {...}, {...}] ARRAY3: [{...}, {...}] ARRAY4: [{...}] } I want to show all the keys of arrays from this dictionary on an HTML page. I attempted to do ...

What steps do I need to take in order to execute `npm update -g npm` on Elastic Beanstalk?

Is there a way to automatically update the NPM version on my Elastic Beanstalk instances as they scale up, without having to manually shell into each one? I need a solution that can handle auto-scaling events and consistently ensure the latest version of ...

Issue: Incorrect hook usage. Hooks are designed to be used within the body of a function component. This error may occur due to one of the following reasons: 1

I've reviewed similar questions and attempted to apply the solutions provided, but it seems I'm missing something specific to my situation. My goal is to streamline my code by importing headers from a utils file and using them across different AP ...

Ensuring Data Accuracy in Angular 2 Forms

Currently, I am working on form validation using Angular 2 and encountered an issue with the error message Cannot read property 'valid' of undefined. The HTML file I am working on contains a form structure like this: <form id="commentform" c ...

Can you explain the process by which react-scripts adds additional dependencies?

To replicate the scenario I am describing: Start by creating a new, empty directory Navigate into the directory and initialize npm by running npm init Execute the command npm install react-scripts Inspect the node_modules directory. While react-scripts ca ...

What is the best way to remove a global symlink in npm without impacting local dependencies?

As a developer of an npm package, I often need to use the local version of my package. To achieve this, I utilize the npm link command, which creates a global symlink to my package. However, once I am done working with my package, I need to remove this glo ...

Increase the size of the NativeScript switch component

Here is the code I am working with: .HTML <Switch style="margin-top: 10" (checkedChange)="onFirstChecked1($event)" row="0" col="1" horizontalAlignment="center" class="m-15 firstSwitchStyle"></Switch> .CSS .firstSwitchStyle{ width: 30%; ...

Using sqlite3 on macOS Sierra is a powerful tool for

Each time I attempt to install sqlite3 on my Mac, I encounter the following error message: sh: node-pre-gyp: command not found npm WARN <a href="/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="e095919d8ec4a596928692">[email p ...

Exploring subobjects while fetching observables (typescript/angular)

When retrieving JSON from an API into an Angular service, I am working with a collection of objects structured like this: { "data": { "id": 1, "title": "one" }, "stats" : { "voteCount": 8 } } I am particularly interested in the ' ...

Is there a way to verify a user's authorization status within Next.js 12.1.6 middleware?

I'm implementing a Nextjs middleware to redirect unauthenticated users to the login page. It's currently working locally, but not on the remote server: export async function middleware(req: NextRequest) { const { cookies } = req if (!cook ...

Developing a webpack configuration involving two distinct setups yet utilizing identical plugins

Currently, I am tackling a project based on vue.js where I need to develop two separate SPAs - one for the admin dashboard and another for the public side. My goal is to manage these projects separately but work on them simultaneously. It would be convenie ...

Can I integrate @types/pkg into my custom library to automatically have types included?

Imagine I am creating a library that utilizes types from the Definitely Typed repository (such as @types/pkg). Would it be feasible for my package to automatically include these types when installed, eliminating the need for consumers to separately instal ...

Transferring an array of interfaces between Angular 2 components

Encountering issues with passing an Array of data between components using @Input. Here is the code snippet: public ngOnInit() { this.applications = new Array<ApplicationEntryInterface>(); (...) let shortTermData = new ShortTermApplicationAdapte ...

Implementing TypeScript in an Asp.net Core ReactJS application`s configuration

After using Visual Studio 2022 to create an asp.net core Reactjs project, I discovered that everything was written in javascript instead of typescript. Is there a way to switch this project over to typescript? ...

Jetstream Livewire App does not contain the Tailwind framework

Recently, I set up a Laravel Jetstream Livewire application and successfully hosted it on a VPS managed by Plesk (not locally). Here are the steps I followed to achieve this: Navigate into an empty subdomain folder and execute the command: composer crea ...

Encountering an issue during the installation of OracleDB in a NodeJs environment

When attempting to install oracledb in node js, the following command is run: >npm install oracledb After running these commands: > <a href="/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="5e31...">[email protected]</ ...

The observable HTTP map appears to be more of a representation rather than a concrete entity

I seem to be struggling with understanding Typescript I expected the returned observable to have a method getTitle(), but it seems to be missing. Instead, I am getting an object that resembles AttachableContentModel without that particular method. What is ...