question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

GraphQL API Attribute not removed when providing null

See original GitHub issue

Describe the bug When doing an update mutation with a value of null (or undefined) for the key the attribute is not removed in DynamoDB.

To Reproduce Steps to reproduce the behavior: Create a model and push it and generate the graphql mutations

type Article @model 
{
  id: ID!
  title: String
  subtitle: String
}

Insert an article with a title and subtitle

Do an update mutation with a new title and set subtitle to null

graphqlOperation(mutations.updateArticle, {
   input: { title: 'new title', subtitle: null },
})

The title is changed in DynamoDB but the subtitle is still there untouched

Expected behavior What was expected is that the attribute subtitle should be removed from the DynamoDB table. This is mentioned/documented on the AppSync docs

If the attribute is set to null, it asks AWS AppSync and DynamoDB to remove that attribute from the post object

When executing the query in the AppSync console the attribute was removed (as expected)

mutation UpdateArticle {
  updateArticle(input: { id: "4f482b...", title: "new title", subtitle: null }) {
    id
  }
}

Also in the generated mutation resolver (generende with Amplify CLI) of the article there you see the line where it states when the value is null the key (attribute) should be removed

#if( $util.isNull($entry.value) )
    #set( $discard = $expRemove.add("#$entry.key") )
    $util.qr($expNames.put("#$entry.key", "$entry.key"))

Desktop:

  • OS: MacOS X
  • Browser Safari, Chrome, Firefox
  • Latest version

Additional context Updated all amplify packages to latest with no effect, also tried to do it with the Appsync SDK and Client but no change; also with a own typed gql no change.

dependencies": {
    "aws-amplify": "^1.1.18",
    "aws-amplify-react": "^2.2.5",
    "aws-appsync": "^1.7.0",
    "graphql-tag": "^2.10.0",
    "node-sass": "^4.11.0",
    "npm": "^6.5.0",
    "prop-types": "^15.6.2",
    "react": "^16.7.0",
    "react-dom": "^16.7.0",
    "react-scripts": "^2.1.3"
  }

Issue Analytics

  • State:closed
  • Created 5 years ago
  • Comments:6 (2 by maintainers)

github_iconTop GitHub Comments

1reaction
rohit3d2003commented, Mar 10, 2019

The same thing happens on iOS app as well

0reactions
github-actions[bot]commented, Jun 12, 2021

This issue has been automatically locked since there hasn’t been any recent activity after it was closed. Please open a new issue for related bugs.

Looking for a help forum? We recommend joining the Amplify Community Discord server *-help channels or Discussions for those types of questions.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Using nullability in GraphQL
For output fields, removing non-null from a field is a breaking change. The first case is easy to understand: If an API consumer...
Read more >
Nulls in GraphQL: Cheatsheet - Hasura
Nulls in the query. A GraphQL query can have fields and inputs, with or without variables. Fields are always optional, whether nullable or...
Read more >
Why does a GraphQL query return null? - Stack Overflow
There's two common reasons your field or fields are resolving to null: 1) returning data in the wrong shape inside your resolver; and...
Read more >
When To Use GraphQL Non-Null Fields | by Caleb Meredith
In the GraphQL type system all types are nullable by default. This means that a type like Int can take any integer (...
Read more >
GraphQL Best Practices
While there's nothing that prevents a GraphQL service from being versioned just like any other REST API, GraphQL takes a strong opinion on...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found