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

20,481

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(...);
Share:
20,481

Related videos on Youtube

Joseph D.
Author by

Joseph D.

Software craftsman | Minimalist A technologist in pursuit of mastering the art of software craftsmanship. Passionate in designing and building real-time event-driven distributed systems. Loves to design effective and intuitive user interface for better user experience. Tech Stack: React | Redux | Node JS | GraphQL | MongoDB | AWS Babel | Jest | Webpack C++ | Python | OpenCV | Raspberry Pi | FFMPEG | MQTT | IoT devices

Updated on July 09, 2022

Comments

  • Joseph D.
    Joseph D. almost 2 years

    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?

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