Adding support for disabling enum creation on SerializerMutation #851
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.
A workaround for #785 --
Appropriately,
DjangoObjectType
supports aconvert_choices_to_enum
which disables the creation of GraphQLEnum
types for everyChoiceField
on a model.However,
SerializerMutation
(similarly a subclass ofObjectType
and registered in the GQL schema) does not support such a flag, and forces creating anEnum
for everyChoiceField
. This behavior can be undesirable because it can trigger a duplicate type registration errorFound different types with the same name in the schema:
.For consistency's sake, a flag to disable the
Enum
creation should be added to theSerializerMutation
; this commit implements such changes.Sidenote --
In my sandbox, this error actually triggered even when the ChoiceField was only registered one single time, on one single Mutation, and not at all present in the
DjangoObjectType
, which leads me to believe that theSerializerMutation
'sEnum
definition is colliding with itself?There's actually 0% test coverage for the current existing behavior of creating
Enums
forSerializerMutation
because none of these tests actually implement anyModel
with aChoicesField
; the test coverage stops at ensuring the automatic type conversion returns a proper value (and I added a second test for my branching logic). I hesitate to suggest it, but it seems that in the current implementation ofEnums
inSerializerMutations
, simply adding a SerializerMutation with any ChoicesField to a schema might be enough to throw the error?I might have time to dig deeper into that, but for now, here's an effective and reasonable bandaid.