Subscription error for <Type>: GraphQLResponse.Error while Syncing Models from Datastore

746 Views Asked by At

I have several models defined in my schema.graphql file. One of which is:

type QuizCategory @model {
  id: ID!
  QuizCategoryName: String!
  QuizCategoryDescription: String!
  QuizCategoryThumbnailUrl: String!
  QuizCategoryReferenceCode: Int!
}

When I run amplify push, the schema.grahql in the build folder is updated to this:

 type QuizCategory {
   id: ID!
   QuizCategoryName: String!
   QuizCategoryDescription: String!
   QuizCategoryThumbnailUrl: String!
   QuizCategoryReferenceCode: Int!
   _version: Int!
   _deleted: Boolean
   _lastChangedAt: AWSTimestamp!
   createdAt: AWSDateTime!
   updatedAt: AWSDateTime!
 }

and an exact copy of this file is made in the schema tab in the appsync console as long with other autogenerated stuff.

Now, in the database that this datasource points to, I have added the columns and added values but when I run the app, I get this error messsage:

E/amplify:aws-datastore( 8287): GraphQLResponseException{message=Subscription error for QuizCategory: [GraphQLResponse.Error{message='Validation error of type FieldUndefined: Field '_deleted' in type 'QuizCategory' is undefined @ 'onUpdateQuizCategory/_deleted'', locations='null', path='null', extensions='null'}, GraphQLResponse.Error{message='Validation error of type FieldUndefined: Field '_lastChangedAt' in type 'QuizCategory' is undefined @ 'onUpdateQuizCategory/_lastChangedAt'', locations='null', path='null', extensions='null'}, GraphQLResponse.Error{message='Validation error of type FieldUndefined: Field '_version' in type 'QuizCategory' is undefined @ 'onUpdateQuizCategory/_version'', locations='null', path='null', extensions='null'}], errors=[GraphQLResponse.Error{message='Validation error of type FieldUndefined: Field '_deleted' in type 'QuizCategory' is undefined @ 'onUpdateQuizCategory/_deleted'', locations='null', path='null', extensions='null'}, GraphQLResponse.Error{message='Validation error of type FieldUndefined: Field '_lastChangedAt' in type 'QuizCategory' is undefined @ 'onUpdateQuizCategory/_lastChangedAt'', locations='null', path='null', extensions='null'}, GraphQLResponse.Error{message='Validation error of type FieldUndefined: Field '_version' in type 'QuizCategory' is undefined @ 'onUpdateQuizCategory/_version'', locations='null', path='null', extensions='null'}], recoverySuggestion=See attached list of GraphQLResponse.Error objects.}

I've tried adding the fields (_version, _deleted, _lastChangedAt, createdAt, updatedAt) to the table but that doesn't help.

In the AppSync guide, there is this line:

To use this metadata in client applications, include the _version, _lastChangedAt, and _deleted fields on your GraphQL types and in the selection set for mutations.

Which isn't very clear, and the documentation for Flutter is still very much under development that finding the cause of this is hard.

I've also gone through the following "related" github issues pages:

DataStore should automatically fill createdAt and updatedAt #6758 AWS Amplify GraphQL subscriptions fail with "Cannot return null for non-nullable type: 'AWSDateTime' within parent ... for createdAt/updatedAt" #5542

and most importantly this:

Couple of Bugs that are preventing AppSync from Synchronizing Local Datastore Changes Globally/Online #822

When I test the queries on the appsync console, everthing works just fine.

I'll update this question if anyone needs any clarification.

0

There are 0 best solutions below