Skip to content

GraphQL: null on GraphQL API layer should be converted to {__op: "Delete"} #7648

Closed

Description

@Moumouls

New Issue Checklist

Issue Description

Currently null values used during GraphQL mutation are not transformed by the GraphQL layer, so null is directly saved into the database. null in database could lead to unwanted behavior since query like exists: false will not resolve when the field has a null value.

Currently the GraphQL API has a lack of support to correctly unset fields. We should transform null to op Delete

Steps to reproduce

  • Create an object via graphql
  • Update a field to null
  • Query the field object with exists: false
  • Query will not resolve the object

Actual Outcome

null is saved into the DB

Expected Outcome

Null should transformed to undefined into the DB through the GraphQL API

Environment

alpha 5.0

Server

  • Parse Server version: alpha 5.0
  • Operating system: macOs
  • Local or remote host (AWS, Azure, Google Cloud, Heroku, Digital Ocean, etc): local

Database

  • System (MongoDB or Postgres): mongo
  • Database version: 4.4
  • Local or remote host (MongoDB Atlas, mLab, AWS, Azure, Google Cloud, etc): local

Activity

  1. parse-github-assistant commented on Oct 19, 2021

    @parse-github-assistant

    Thanks for opening this issue!

    • 🚀 You can help us to fix this issue faster by opening a pull request with a failing test. See our Contribution Guide for how to make a pull request, or read our New Contributor's Guide if this is your first time contributing.
  2. mtrezza commented on Oct 19, 2021

    @mtrezza
    Member

    null in database could lead to unwanted behavior since query like exists: false will not resolve when the field has a null value.

    This is expected and well-known behavior. A null value is not the same as undefined. A developer is expected to be aware of that, and there are use cases in which this differentiation is desired. The Parse SDKs account for that differentiation. For example, in the JS SDK there is a distinction between obj.set("key", null); and obj.unset("key");. See #7518 (comment).

  3. Moumouls commented on Oct 19, 2021

    @Moumouls
    MemberAuthor

    So here following the official spec of GraphQL null value in the input SHOULD delete the field in the database.

    Spec ref: https://spec.graphql.org/June2018/#sec-Null-Value

    a mutation representing deleting a field vs not altering a field, respectively

    and there are use cases in which this differentiation is desired

    Agree, but GraphQL API could not handle this diff, currently a developer with the GraphQL API can't know if the field is undefined or null, and graphql will never support this 2 values. Here the special case with the strict null check should be handled with the SDK or cloud code.

    But we need to let the developer unset the field via null value as expected by the official GraphQL Doc. And avoid a custom system with some unlink unset workarounds 🙂 (also hard to maintain)

    Later if a developer need to know if the field value is really "null" (non sense in a graphql use case since the response will not change), we could introduce a query {field: {isNull: false}} or something similar

  4. Moumouls commented on Oct 19, 2021

    @Moumouls
    MemberAuthor

    PR sent

  5. mtrezza commented on Oct 19, 2021

    @mtrezza
    Member

    Interesting, looking at the GraphQL spec it seems you are correct. Reclassified this as a bug since the current behavior seems to violate the GraphQL specs.

  6. added
    type:bugImpaired feature or lacking behavior that is likely assumed
    and removed on Oct 20, 2021
  7. parseplatformorg commented on Oct 27, 2021

    @parseplatformorg
    Contributor

    🎉 This change has been released in version 5.0.0-alpha.2

  8. parseplatformorg commented on Nov 1, 2021

    @parseplatformorg
    Contributor

    🎉 This change has been released in version 5.0.0-beta.1

  9. parseplatformorg commented on Mar 14, 2022

    @parseplatformorg
    Contributor

    🎉 This change has been released in version 5.0.0

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    state:releasedReleased as stable versionstate:released-alphaReleased as alpha versionstate:released-betaReleased as beta versiontype:bugImpaired feature or lacking behavior that is likely assumed

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions