Use DjangoObjectType (or something like it) as an Input class?
See original GitHub issueWe’re using Graphene with Relay for some boring CRUD style mutations. Now, since we have some rather large (i.e., many fields) models, it’s a bit tedious and also error-prone, to repeat typing in the model’s fields again for each mutation. Is it possible to use DjangoObjectType for this (from my 1st try it seems that, no)?
I’m mainly interested in the Meta class’ model
and only_fields
options.
And guys, thanks for the hard work on such a cool tool.
Issue Analytics
- State:
- Created 7 years ago
- Reactions:24
- Comments:13
Top Results From Across the Web
Is there a way to elegantly use a django model as an input ...
It would be nice if you could subclass something like "DjangoInputObjectType" and specify the model and fields you want in a Meta attribute....
Read more >Queries & ObjectTypes - Graphene-Python
A Resolver that maps to a defined DjangoObjectType should only use methods that return a queryset. Queryset methods like values will return dictionaries,...
Read more >Django + Graphene: From REST to GraphQL - FullStack Labs
Now, just like that, our app is available to respond to graphQL queries. Here we are using the logic directly, but you can...
Read more >graphene-django-extras - PyPI
This library add some extra funcionalities to graphene-django to facilitate ... definition to use as input on an Arguments class on traditional Mutations ......
Read more >How to add GraphQL to DjangoCMS | Articles | Bravelab.io
Create a file schema.py and import DjangoObjectType. Create a class Query that will hold all of ... Inside Meta class configure what django...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
I was able to dynamically generate an Input class from Model using a Django Rest Framework
serializer
and theconvert_serializer_to_input_type
tool ingraphene_django.rest_framework.serializer_converter
.Sample Code:
In the above code I [optionally] created a
PersonArgsInput
, which inherits from the generated Input class, so I can add additional fields. I can then use the the new class in my mutations however I want. like so:Here’s something I put together, which seem to work, but is certainly work in progress: