Add required_output_field mutation option #134
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Adds a mutation option,
required_output_field
.For all relevant mutations, the
graphene.Field
for the mutation output is set withoutrequired=True
. This leads to the relevant GraphQL type beingFishNode
, and notFishNode!
for a mutation like this:This is not normally an issue. However, a type generator (like GraphQL-Codegen), will then naturally make the type of the mutation result
T | null
, which is annoying to work around.This PR solves the problem by introducing the
required_output_field
meta option for all mutations. IfTrue
, it setsrequired=True
for all output model fields.One question is whether this should be the default, since there are no scenarios (as far as I know) when the output field will actually be null if the above
createFish
is not null. This would technically be a breaking change, as it would alter the output schema of all apps using Graphene Django CUD, however I believe it would be extremely unlikely that it would actually break anything. It could perhaps also be a global configuration option.Another question is the naming.
required_output_field
is perhaps not the best name. But naming is hard.