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

GraphQL Mutation how to make fields optional to update fields only by selection and generate schema #1013

Open
Kalanamith opened this issue Feb 1, 2023 · 1 comment

Comments

@Kalanamith
Copy link

I have a graphql mutation defined as follows

    updateParts(
      partId: String!
      parts: PartRequest!
    ): UpdatePartsResponse!

  input PartRequest {
    name: String!
    image: Strings!
    boltTypes: [Bolts]!
  }


  input Bolts {
    code: String!
    metadata: String!
  }

and the requirement was to update fields upon selection like

  • update all
mutation {
  updateParts(
    partId: "0x1223"
    parts: {
      name: "some"
      image: "dark.png"
      boltTypes: [
        { code: "A", metadata: "B" }
       
      ]
    }
  ) 
  }
}
  • Update by selection name only
mutation {
  updateParts(
    partId: "0x1223"
    parts: {
      name: "some"
     
    }
  ) 
  }
}

Update by selection , parts only

mutation {
  updateParts(
    partId: "0x1223"
    parts: {
       
      boltTypes: [
        { code: "A", metadata: "B" }
       
      ]
    }
  ) 
  }
}

How to construct a schema to achieve this ?

@Kalanamith Kalanamith changed the title GraphQL Mutation how to make fields optional to update required fields only by selection and generate schema GraphQL Mutation how to make fields optional to update fields only by selection and generate schema Feb 1, 2023
@benjie
Copy link
Member

benjie commented Feb 2, 2023

Make the fields on PartRequest nullable, this makes them optional. Optionality and nullability are effectively equivalent in GraphQL inputs currently (with the exception of where default values are present).

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

2 participants