Cannot return null for non-nullable field FooType.barType [Enum]
See original GitHub issueThe error occurs with graphene-django==2.0.0 with a field with choices, for example:
class Foo(models.Model):
ONE = 1
TWO = 2
BAR_TYPES = (
(ONE, _('one'),
(TWO, _('two'),
)
bar_type = models.PositiveIntegerField(_('type'), choices=BAR_TYPES)
class FooType(DjangoObjectType):
class Meta:
model = Foo
This error can be resolved with an explicit graphene.Field declaration:
class FooEnum(graphene.Enum):
ONE = 1
TWO = 2
class FooType(DjangoObjectType):
bar_type = graphene.Field(FooEnum)
class Meta:
model = Foo
Is it really necessary to duplicate the choices, though?
Issue Analytics
- State:
- Created 5 years ago
- Reactions:3
- Comments:6
Top Results From Across the Web
Return ENUM - Cannot return null for non-nullable field
SOLVED: The issue was that I was using Prisma as ORM. When I was getting a new book, I was writing the code:...
Read more >Cannot return null for non-nullable field FooType.barType [Enum]
Cannot return null for non -nullable field FooType.barType [Enum] ... The error occurs with graphene-django==2.0.0 with a field with choices, for example:
Read more >Cannot return null for non-nullable type graphql - Fauna Forums
I get the following error when i query allTodos index through graphql "errors": [ { "message": "Cannot return null for non-nullable type ...
Read more >Extend the Kubernetes API with CustomResourceDefinitions
This page shows how to install a custom resource into the Kubernetes API by creating a CustomResourceDefinition. Before you begin You need ...
Read more >"Cannot return null for non-nullable field" error - GraphQL API
I have an Item custom class, and I use a custom graphql mutation to update an item via a resolver in Cloud code...
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 had the same issue until I applied the following:
this fixed an issues for me.
I’ve got the recipe from here: http://anthonyfox.io/2017/02/choices-for-choices-in-django-charfields/
Also there are useful comments under this article: https://hackernoon.com/using-enum-as-model-field-choice-in-django-92d8b97aaa63
This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.