Description
Currently it's possible to map Django models to ObjectType
s using DjangoNode
. I think it would be nice to have a similar feature that allows mapping forms to Mutation
with a DjangoMutation
class.
This would provide several great improvements:
- No need to duplicate form fields in
Input
classes anymore. - There would be a simple and obvious way to handle validation.
- The code could map
form.errors
toinfo.context.errors
(It took a while until I figured out how to do that) on it's own.
In the simple case you'd only have to define the outputs and a method that takes the validated data and returns an instance of the mutation class. I believe that even that would be unnecessary, if you're working with ModelForm
s. In that case a default method could just save the form and return the model instance wrapped in the corresponding DjangoNode
.
Code that gets us some of the way to such a class already appears to exist, which was written for the django-filter integration.
I'm not that familiar with the code base itself but I have read quite a bit of it and I' think it might be able to implement this. I'm interested to know what you think of it and whether this has a chance to be accepted.