mirror of
https://github.com/graphql-python/graphene-django.git
synced 2025-01-30 19:24:08 +03:00
Fix manager check in DjangoConnectionField (#693)
* Fix default manager check * Add test
This commit is contained in:
parent
54cc6a4b13
commit
40ae7e53ec
|
@ -101,7 +101,7 @@ class DjangoConnectionField(ConnectionField):
|
|||
iterable = default_manager
|
||||
iterable = maybe_queryset(iterable)
|
||||
if isinstance(iterable, QuerySet):
|
||||
if iterable is not default_manager:
|
||||
if iterable.model.objects is not default_manager:
|
||||
default_queryset = maybe_queryset(default_manager)
|
||||
iterable = cls.merge_querysets(default_queryset, iterable)
|
||||
_len = iterable.count()
|
||||
|
|
|
@ -1065,3 +1065,54 @@ def test_should_resolve_get_queryset_connectionfields():
|
|||
result = schema.execute(query)
|
||||
assert not result.errors
|
||||
assert result.data == expected
|
||||
|
||||
|
||||
def test_should_preserve_prefetch_related(django_assert_num_queries):
|
||||
class ReporterType(DjangoObjectType):
|
||||
class Meta:
|
||||
model = Reporter
|
||||
interfaces = (graphene.relay.Node,)
|
||||
|
||||
class FilmType(DjangoObjectType):
|
||||
reporters = DjangoConnectionField(ReporterType)
|
||||
|
||||
class Meta:
|
||||
model = Film
|
||||
interfaces = (graphene.relay.Node,)
|
||||
|
||||
class Query(graphene.ObjectType):
|
||||
films = DjangoConnectionField(FilmType)
|
||||
|
||||
def resolve_films(root, info):
|
||||
qs = Film.objects.prefetch_related("reporters")
|
||||
return qs
|
||||
|
||||
r1 = Reporter.objects.create(first_name="Dave", last_name="Smith")
|
||||
r2 = Reporter.objects.create(first_name="Jane", last_name="Doe")
|
||||
|
||||
f1 = Film.objects.create()
|
||||
f1.reporters.set([r1, r2])
|
||||
f2 = Film.objects.create()
|
||||
f2.reporters.set([r2])
|
||||
|
||||
query = """
|
||||
query {
|
||||
films {
|
||||
edges {
|
||||
node {
|
||||
reporters {
|
||||
edges {
|
||||
node {
|
||||
firstName
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
"""
|
||||
schema = graphene.Schema(query=Query)
|
||||
with django_assert_num_queries(3) as captured:
|
||||
result = schema.execute(query)
|
||||
assert not result.errors
|
||||
|
|
Loading…
Reference in New Issue
Block a user