Encountering an Unrecognized Type Error in Apollo Client while performing a mutation

I'm facing an issue with my graphql mutation because of the error below:

"errors": [
        {
            "message": "Unknown type \"GenderInput\".",
            "locations": [
                {
                    "line": 1,
                    "column": 37
                }
            ],
            "extensions": {
                "code": "GRAPHQL_VALIDATION_FAILED",
                "stacktrace": [
                    "GraphQLError: Unknown type \"GenderInput\".",`

This problem arose after I created a custom input type called GenderInput.

Here is the frontend mutation code:

export const CALCULATE_CALORIES = gql`
  mutation calculateCalories(
    $gender: GenderInput!
    $weight: String!
    $activityLevel: Float!
    $goal: GoalInput!
    $user_id: String!
  ) {
    calculateCalories(
      gender: $gender
      weight: $weight
      activityLevel: $activityLevel
      goal: $goal
      user_id: $user_id
    )
  }
`;

On the backend, in the TypeDefinitions File, I have defined GenderInput correctly according to the schema provided. However, despite restarting Apollo server, the error persists. Any insight on resolving this would be helpful.

export const typeDefsWorkout = `#graphql

type exercise {
    id: ID!
    name: String!
    muscletrained: String
    user_id: String!
  }

  // Rest of the Type Definitions...
  
`;

The issue began when I added the custom input type (GenderInput). I'd appreciate any assistance in solving this error.

Answer №1

After some experimentation, I decided to remove the backend ValidationPipe in my scenario and it turned out to be successful.

  async function startApp() {
  const application = await NestFactory.create(AppModule, {
    cors: true,
  });
  // application.useGlobalPipes(
  //   new ValidationPipe({
  //     whitelist: true,
  //     forbidNonWhitelisted: true,
  //     transform: true,
  //   }),
  // );
  await application.listen(application.get(ConfigService).get('port'));
}
startApp();

I hope this solution works for you as well!

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

Properly Incorporating Client Libraries (TypeScript, JQuery, etc.) in Visual Studio 2019

[Updated on 16th July 2019] I'm feeling perplexed at the moment. I am diving into a .NET Core 3.x Web Application and my aim is to incorporate: jQuery TypeScript I've managed to get TypeScript up and running, but I'm facing an issue where ...

Acquire the top-scoring item using React

I retrieved data from the backend Below is the code snippet where I display the data: <div className="pr-0 mt-20" style={{ display: 'flex', justifyContent: 'center' }}> <MuiCardWithAnimation component={AnimateS ...

Finding the perfect pairing: How to align counters with objects?

public counter = 0; x0: any; x1: any; x2: any; x3: any; x4: any; next(){ this.counter += 1; this.storage.set("Count", this.counter); console.log(this.counter); this.logic(); } logic(){ //automatic counter here var xNum = JSON.parse(JSON.stri ...

When using an express TypeScript app, errors that are passed through the next() function may not be properly caught by the error handling

Let's take a closer look at this code snippet: import express from 'express'; // Custom error handling for non-existing routes app.use((req: Request, res: Response, next: NextFunction) => { return next(new Error('Test error)); }); ...

The connections between module dependencies are unable to be resolved

I'm encountering an issue with the npm link command. Here's the scenario: I have two Angular apps - 1) app-core (published locally) 2) app-main The app-core module has the following dependencies (installed via npm): core rxjs z ...

How to toggle code block visibility in Angular's ngOnInit() method

I'm currently analyzing different design patterns to optimize the number of REST calls when implementing a 'save while typing feature'. To provide a general overview, in my ngOnInit() function, I have included the following code snippet (wit ...

What purpose does declaring a global `name` variable serve in TypeScript, and is there a way to work around relying on it?

While working on a coding project, a friend made some changes to the code by moving the definition of a variable named name from the function's top-level scope into a then's body. This unexpected change caused a ReferenceError later on when name ...

Adding a component dynamically to a div in Angular 5

Can anyone help me with this issue? I have successfully managed to dynamically append an element, but it is not getting compiled. I have looked at several tutorials like this one However, these tutorials do not exactly meet my requirements. They often us ...

What's the best way to reset the `react-google-recaptcha` checkbox in a redux application following the submission of a form?

My Redux application consists of two files: LoginForm (which contains the form elements) and LoginFormContainer (which manages form values using Formik). I am facing an issue with resetting the captcha, as the ref is located in the LoginForm file. I attemp ...

Connecting the SelectedItem of a listbox in ngPrime to an Observable Collection in Angular2

I am facing an issue while trying to use the ngPrime listbox in Angular2. I have a scenario where I am fetching an array of objects from Firebase as an observable and attempting to display it correctly in the listbox. <div *ngIf="addContactDialogVisibl ...

Converting a file buffer to upload to Google Cloud Storage

I have been facing an issue while attempting to upload a file to Google Cloud using a buffer and the save function. The problem I am encountering is that even though the files are uploaded to Google Cloud, they are not in the correct format. When I try to ...

What is the most efficient way to check for the presence and truthiness of a nested boolean in Node.js?

There are instances where I must verify the deeply nested boolean value of an object to determine its existence and whether it is set to true or false. For instance, I need to ascertain if payload.options.save is assigned a value of false, yet I am uncert ...

Having trouble with TypeScript in react-select - Error: Generic type 'ValueType' needs 2 type arguments

Looking to implement the react-select package, I have the code snippet below: import React, {useState} from 'react'; import LanguageChange from '../../../Icons/LanguageChange'; import Select, { ValueType } from 'react-select'; ...

What is the best way to retrieve a class property within an arrow function that is passed to a constructor?

On a React login page, I created a class for rendering authentication methods. The class includes a default render function that I need to customize. class AuthMethod { constructor(initializer: Pick<AuthMethod, 'id'> & Partial<A ...

Prisma atomic operations encounter errors when attempting to update undefined values

According to the Prisma Typescript definition for atomic operations, we have: export type IntFieldUpdateOperationsInput = { set?: number increment?: number decrement?: number multiply?: number divide?: number } Let's take a look at the Pris ...

put two elements next to each other in a single row

This specific section contains an image positioned at the top, followed by two other components (within <ItemsContainer/>) at the bottom which display as separate rows. I am trying to place these two items (a grid and a chart) side by side within the ...

Encountering: error TS1128 - Expecting declaration or statement in a ReactJS and TypeScript application

My current code for the new component I created is causing this error to be thrown. Error: Failed to compile ./src/components/Hello.tsx (5,1): error TS1128: Declaration or statement expected. I've reviewed other solutions but haven't pinpointed ...

Unable to alter the input data within the LCJS chart

I have been utilizing LightningChart JS to create scrolling line charts. After following an official tutorial by the developers on YouTube, I was able to successfully implement the automatic generated data. Now, I am looking to modify the input to a JSON f ...

Error encountered: "Injection error: Angular2 + typescript + jspm : No provider found for Http ( App -> Provider -> Http )"

I am in the process of transitioning from Webpack to JSPM with system.js. Our application has a simple App component. I have been following the steps outlined in this article Angular 2 Starter Setup with JSPM, SystemJS and Typescript in atom (Part 1) impo ...

How should a child component specify the type of component being passed in props?

Consider the following snippet from App.tsx : <Layout header={ <Header/> } </layout> Now, let's take a look at the Layout component : export default function Layout({header, body}: any) { return ( <div className="layou ...