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

Codegen to support sparse updates #609

Open
ramapalani opened this issue Nov 1, 2023 · 1 comment
Open

Codegen to support sparse updates #609

ramapalani opened this issue Nov 1, 2023 · 1 comment

Comments

@ramapalani
Copy link

ramapalani commented Nov 1, 2023

GraphQL Mutation requires an input object. This input object has optional fields, and all those fields are not set in a mutation call, the default Deserialization by this codegen utility for all those missing fields are set to default value if specified in the schema or "null". This will result in DGS/subgraph overwriting those fields with default value/"null", which is not desirable.

Codegen deserialization should mark fields that are not provided, so that the DGS/subgraph implementation can handle sparse updates.

Example

Schema

mutation {
  patchProfile(input: ProfileInput!): Profile
}

input ProfileInput {
  id: ID!
  name: String
  address: String
}

type Profile {
  id: ID!
  name: String
  address: String
}

Mutation call

mutation patchProfile($input: ProfileInput!) {
  patchProfile(input: $input) {
    id
    name
    address
}

Calls

Call 1

Input

{
  "id": "1",
  "address": "new address"
}

DGS for the field name gets default value when specified by schema or "null", and will overwrite the value that was already there for the name field.
After fixing this issue, only address should be updated and remaining fields should not be altered.

Call 2

Input

{
  "id": "1",
  "name": "New name",
  "address": null
}

Deserialization works well for this now (DGS will set the address to null and name to "New name".
After fixing this issue, when the user explicitly sets a field to null, it should be honored.

@ramapalani
Copy link
Author

Example gitrepo to reproduce this issue: https://github.com/ramapalani/sparseupdate

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

No branches or pull requests

1 participant