one to one ModelSerializer mutations #482
Closed
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.
Hey there,
First of all, this project is fantastic!
I've been attempting to slowly apply
graphene-django
to some of the models/endpoints we use at work, and struggled with writing mutations overModelSerializer
s.If you consider the Star Wars example, where every
Character
has aShip
, it would be pretty normal to write aCharacterSerializer
like this:This will include a field
ship
of classPrimaryKeyRelatedField
To use this serializer to power a GQL mutation, you'd like to write something really clean like this:
Currently, this mutation will run, but the response won't match the GQL we expect:
You could roll your own mutation like in the star wars example:
graphene-django/examples/starwars/schema.py
Line 41 in 52d14f3
but it would be great to support DRF
ModelSerializer
out of the box (we use DRF all over our codebase, often with complex validation)This is a first crack at solving this problem. More work would be needed to support M2M relationships, but I wanted to get this in front of y'all first and get some feedback first.
Let me know what you think!