graphql-python / graphql-python/graphene-django

Default QuerySet for DjangoObjectType has no effect with graphene.List

Open
#925 13 comments 3 reactions 0 assignees View on GitHub
Docs enhancement
Dominant language
Python
Stars
4.4k
Forks
760
PR merge metrics
No merged PRs in 30d

Description

The documentation describes the use of a [default QuerySet on ObjectType level](https://docs.graphene-python.org/projects/django/en/latest/queries/#default-queryset).

The [unit test for this functionality](https://github.com/graphql-python/graphene-django/blob/master/graphene_django/tests/test_query.py#L1030) makes use of DjangoConnectionField.

Using `graphene.List` instead ignores the existence of the default QuerySet.

```
class CurrencyType(DjangoObjectType):
class Meta:
model = Currency

@classmethod
def get_queryset(cls, queryset, info):
print(cls)
print(queryset)
return queryset.filter(symbol__isnull=False)
```

```
all_currencies = graphene.List(CurrencyType)

def resolve_all_currencies(self, info):
return Currency.objects.all()
```

The `get_queryset` method is never called, and the filter is not applied.

Please refer to graphql-python/graphene#698 for some history on this.

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.