Skip to content
Advertisement

aws cdk nextjs graphql mutation cannot return null for non-nullable type after adding in new schema field

I have tried to modify the schema to add a ingredients String line. From this code I am pretty much following it to a tee https://github.com/dabit3/next.js-cdk-amplify-workshop you can look in the backend and frontend folders to see all the code

I have built and deployed with cdk

My error is at the bottom

Any help would be great

Here’s the relevant parts of the schema in the backend

JavaScript

Here is my graphql.js in my frontend code

JavaScript

Then I have tried the following in the create-post.js in my frontend

JavaScript

I then get the following message when trying to create the post

JavaScript

lambda-fns/listPosts.ts

JavaScript

I was missing adding the ingredients in the Post.ts file in my backend

JavaScript

Advertisement

Answer

It seems like there are some debugging details missing from your question. For example, your error message displays the results of a listPosts query, but you don’t show that being called anywhere. Also, that query apparently returns something, so it would be good to see the database entries backing it.

If I had to guess, you have entries in your dynamo table that have missing ingredients fields, which is why you see an error: the query is trying to marshal missing/null fields to a return type of String!, which is by definition non-nullable.

Also, I’m not sure you should be setting id directly on your post state object. Better to copy the object and set the property on the copy, esp since you’re just using it as a parameter.

User contributions licensed under: CC BY-SA
2 People found this is helpful
Advertisement