eamigo86 / graphene-django-extras

Extras functionalities for Graphene-Django
MIT License
417 stars 108 forks source link

DjangoObjectType incorrectly produces nullable fields #115

Open iynaix opened 5 years ago

iynaix commented 5 years ago

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:

UserType UserTypeGDE

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.

tpict commented 5 years ago

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

tnagorra commented 4 years ago

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.

Tom-Greenwood commented 3 years ago

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.

tnagorra commented 3 years ago

@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.

Tom-Greenwood commented 3 years ago

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.