Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Meta 'fields' not working #165

Open
JElgar opened this issue Jan 18, 2021 · 1 comment
Open

Meta 'fields' not working #165

JElgar opened this issue Jan 18, 2021 · 1 comment

Comments

@JElgar
Copy link

JElgar commented Jan 18, 2021

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
Copy link
Author

JElgar commented Jan 18, 2021

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?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant