30

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?

1 Answer 1

57

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(...);
Sign up to request clarification or add additional context in comments.

1 Comment

Thanks! This solution helped me figure out that I don't pass 'input' to a query, and instead I just pass 'id'.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.