Cannot Return null for non-nullable type: 'String' within Parent (Error while adding a new field in the Schema)

773 Views Asked by At

While using a Lambda function to update using the mutation in GraphQL, the data gets updated but on subscribing it the data shows up as NULL. This Issue happens only when i make a change in the schema by adding a new Field / Column. This issue does not happen when i don't make any changes in the existing schema.

Subscription error after adding new Field to an existing schema

Note: We are using amplify

when i make a change in the schema by adding a new Field / Column and I use a Lambda function to update data using the mutation in GraphQL, the data gets updated and on subscribing it the updated new data must show.

if we try adding a new field to the schema and try updating the new field using a Backend Lambda function using mutation. the new field gets updated. Now Try getting the updated data using Subscription / Query from any Frontend/ Amplify. I think there is a problem with the resolver which is sending the data as NULL.Schema where new field address added

1

There are 1 best solutions below

0
ymentha14 On

Same issue here: after digging a bit, turns out you need to query all the fields required by the subscription in the mutation that triggers the subscription. (in your case the mutation executed from the lambda function)

Ex: assuming you have a subscription with the following form:

subscription MySubscription {
  onSomethingDone {
   field1
   ..
   fieldN
  }
}

Then you would need to make sure that the mutation in your lambda function queries all fields from field1 to fieldN, i.e with the form :

mutation MyMutation {
  createSomething {
   field1
   ..
   fieldN
  }
}

Hope this helps