graphene-django-extras
graphene-django-extras copied to clipboard
DjangoObjectType incorrectly produces nullable fields
Using the following simple schema and the default User
model.
import graphene
from graphene_django import DjangoObjectType
from graphene_django_extras import DjangoObjectType as DjangoObjectTypeGDE
from django.contrib.auth.models import User
class UserType(DjangoObjectType):
class Meta:
model = User
class UserTypeGDE(DjangoObjectTypeGDE):
class Meta:
model = User
class Query(graphene.ObjectType):
all_users = graphene.List(UserType)
all_users_gde = graphene.List(UserTypeGDE)
schema = graphene.Schema(query=Query)
Produces the following graphql types:
In the schema generated by graphene-django-extras, every field (except for id) is marked as nullable. However, all the fields except lastLogin are marked as not null in the database and will always return a value.
It appears that is_required
isn't checking whether or not fields are nullable: https://github.com/eamigo86/graphene-django-extras/blame/master/graphene_django_extras/utils.py#L206
Looks like the problem is at https://github.com/eamigo86/graphene-django-extras/blob/abb5a333ef74a3c0aa0ce50ee896ae1c3c3b3c32/graphene_django_extras/converter.py#L199
A string field can only be required if input_flag
is 'create'
.
Similar logic also applies to other type of fields.
is input_flag
something users can set?
If not, any workarounds? I am using typescript on the frontend and having everything as optionally null when it's really not is quite painful.
@Tom-Greenwood We didn't find a workaround for this. We were only using this library for a small functionality so we just stopped using this library. We are also using typescript and codegen to generate all the typings and we didn't want to lose that.
Thanks @tnagorra I am exactly the same situation. Similarly, I found that I could build the same filtering functionality with just plain django and graphene after all.