graphql-core
graphql-core copied to clipboard
Exclude unset fields
Original discussion: https://github.com/graphql-python/graphene-pydantic/pull/75
I use graphene and graphene-pydantic libraries.
Code example:
https://gist.github.com/dima-dmytruk23/aaeba0fbc7a539c1f8bf3d0914fce580
The client does not pass the name field, but it is still present in the
mutationasNone. Input query turns into aUserUpdateInput, which is when the default values are filled in to the dictionary. So then when your code passes the dictionary in to build theUserUpdate, it sets all the fields -- soexclude_unsetdoesn't exclude anything, since all the fields were in fact set.I am fairly sure it's not in
graphene-pydantic, though, since that is only responsible for converting to theGrapheneInputObjectType.
I propose to resolve this issue by adding the exclude unset flag to the GraphQLSchema class and use it in the coerce_input_value function.
Hi @dima-dmytruk23, and thanks for contributing.
Please understand that the scope of GraphQL-core is to be a straight-forward port of GraphQL.js, so I am very reluctant to add features that are not part of GraphQL.js or change the API. I'm not saying that we can never do this, and we in fact have serveral such extensions, but you really need to have convincing reasons why this is necessary. Any such extension makes maintaining GraphQL-core and keeping it in sync with GraphQL.js more difficult as they sum up.
Therefore, could you please first open an issue and explain what the feature tries to achieve, and how it could be useful and why it cannot be achieved in other ways, with example code, independent of Graphene or Graphene-Pydantic? We also require unit tests, and this will help to create them.