eamigo86 / graphene-django-extras

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

Meta 'fields' not working #165

Open JElgar opened 3 years ago

JElgar commented 3 years ago

When using DjangoObjectType from graphene_django it is possible to reduce the fields by setting the fields in the Meta class.

For example:

from graphene_django import DjangoObjectType

class PerformanceType(DjangoObjectType):
    class Meta:
        model = Performance
        filter_fields = {
            "id": ("exact",),
        }
        fields = (
            "id"
        )

As expected the output if I try and query something that is not the id:

{
  "errors": [
    {
      "message": "Cannot query field \"capacity\" on type \"PerformanceType\".",
      "locations": [
        {
          "line": 33,
          "column": 6
        }
      ]
    }
  ]
}

However when using graphene_django_extras this is not working:

When using the same snippet as above but with the import from graphene_django_extras import DjangoObjectType

The output when querying not the id is:

{
  "data": {
    "performances": [
      {
        "capacity": null
      }
    ]
  }
}

The expected would be the same as the original response (the error). Am I doing something wrong here?

JElgar commented 3 years ago

A workaround for this seems to be using only_fields instead of fields I couldn't spot this in the documentation but I may have missed it?

I found only_fields in the graphene_django source and it seems to be depreciated so I'm not sure if this is a long-term solution?