graphene-django-extras icon indicating copy to clipboard operation
graphene-django-extras copied to clipboard

Meta 'fields' not working

Open JElgar opened this issue 3 years ago • 1 comments

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 avatar Jan 18 '21 23:01 JElgar

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?

JElgar avatar Jan 18 '21 23:01 JElgar