Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Closed
5 tasks done
arunks18 opened this issue Nov 15, 2022 · 6 comments
Assignees

Comments

@arunks18
Copy link

Before opening, please confirm:

  • I have installed the latest version of the Amplify CLI (see above), and confirmed that the issue still persists.
  • I have searched for duplicate or closed issues.
  • I have read the guide for submitting bug reports.
  • I have done my best to include a minimal, self-contained set of instructions for consistently reproducing the issue.
  • I have removed any sensitive information from my code snippets and submission.

How did you install the Amplify CLI?

npm

If applicable, what version of Node.js are you using?

16.17.1

Amplify CLI Version

10.2.1

What operating system are you using?

Mac

Did you make any manual changes to the cloud resources managed by Amplify? Please describe the changes made.

No manual changes made

Amplify Categories

api

Amplify Commands

Not applicable

Describe the bug

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. Note that i am using @searchable.

Expected behavior

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.

Reproduction steps

  1. Open your Current Schema
  2. Add a new Field in your schema
  3. Use a Lambda function to update the data using the GraphQL Mutation
  4. Now Subscribe the same data and view it.
  5. You will see NULL values as data.

GraphQL schema(s)

# Put schemas below this line

<img width="753" alt="Schema before change" src="https://user-images.githubusercontent.com/106301547/201969671-37b4a6fa-2048-41fc-9e22-6610345bb289.png">
<img width="753" alt="add new field address" src="https://user-images.githubusercontent.com/106301547/201969720-dbba3a7b-82ad-451d-9902-a3d5b1899366.png">

Project Identifier

No response

Log output

data after adding new field address in schema data return success

</details>


### Additional information

_No response_
@josefaidt josefaidt transferred this issue from aws-amplify/amplify-cli Nov 15, 2022
@josefaidt
Copy link
Contributor

Hey @arunks18 👋 thanks for raising this! From the issue's overview I see this is only happening after making changes. Is it possible that the index has yet to be backfilled when executing the query? Can you confirm whether this continues to occur after some time? How are you adding this new field to the schema?

@arunks18
Copy link
Author

arunks18 commented Nov 16, 2022

@josefaidt This issue is not related to indexing / Open search, even for those types which we have not included in @searchable / indexing it still shows the same error. For example, check the below type/schema, it also has the same issue.

type location
  @model
  @auth(
    rules: [
      { allow: public, operations: [read] }
      { allow: private, operations: [read, update, create] }
      {
        allow: groups
        groups: ["Admin"]
        operations: [create, update, read, delete]
      }
    ]
  ) {
  id: ID!
  name: String! #  name
  gender: String! # Gender type MALE / FEMALE
  city: String!
  state: String!
}

Kindly try adding a new field to the above 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.

@arunks18
Copy link
Author

@josefaidt any update regarding this issue ?

@arunks18
Copy link
Author

@josefaidt We are still waiting for the update, eagerly waiting for this !

@josefaidt josefaidt self-assigned this Nov 22, 2022
@josefaidt
Copy link
Contributor

Hey @arunks18 👋 apologies for the delay here! There was a recent update to the Amplify CLI that enables runtime filtering, can you try upgrading your CLI and recompiling the schema to test? Afterwards, if the issue still occurs please try removing the auth rules from the schema and push to test.

@arunks18
Copy link
Author

Updating the CLI did not work but we found the solution ourselves using the below link,
it took us a very long time.

https://blog.purple-technology.com/lessons-learned-aws-appsync-subscriptions/

  1. A subscription message contains only the fields which were requested by the mutation - other fields will be null

The point is that even though your lambda resolver is returning values for all the mutation fields, an AppSync subscription is only seeing the mutation fields which were selected in the mutation request. This is probably caused by the fact that resolver doesn't have to return values for fields which are not requested in the mutation request.

The issue is prevalent when schema's Fields are mandated to have some value and null not allowed. Once it is mandated the entire result set is returned as Null which should not be the case, it must be null only for the field which was not mentioned in the Mutation Query.

Thank you for your Help @josefaidt .

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants