AWS GraphQL: Variable 'input' has coerced Null value for NonNull type 'Input!'
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(...);
Related videos on Youtube
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, 2022Comments
-
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 about 2 yearsThanks! This solution helped me figure out that I don't pass 'input' to a query, and instead I just pass 'id'.