AWS GraphQL: Variable 'input' has coerced Null value for NonNull type 'Input!'

Joseph D. picture Joseph D. · Aug 24, 2018 · Viewed 9.6k times · Source

I'm using ReactJS and aws-amplify to execute graphql operations.

CODE:

import {
   API,
   graphqlOperation
} from 'aws-amplify';

import { UpdateInput } from './mutations.js';

// Call mutation
const input = { /* some values */ };
API.graphql(graphqlOperation(UpdateInput, input)).then(...);

GraphQL mutation definition:

export const UpdateInput = `mutation UpdateInput($input: Input!) {
   updateInput(input: $input) {
      id, 
      name
   }   
}`

GraphQL Schema:

input Input {
   id: ID!
   name: String
}

type Mutation {
   updateInput(input: Input!): String
}

However, I get an error:

[Log] Variable 'input' has coerced Null value for NonNull type 'Input!'

Using AWS console my mutation works and input is NonNull (using a debugger)

Any ideas what's causing the error?

Answer

Joseph D. picture Joseph D. · Aug 24, 2018

The key was input in the updateInput mutation.

updateInput(input: Input!): String
         // ^^^^^ input key

Thus, need to specify correct key in the passed variable.

const variables = {
  input: someData, // key is "input" based on the mutation above
};

API.graphql(graphqlOperation(UpdateInput, variables)).then(...);