Skip to content

Commit ad2688f

Browse files
committed
add test for when get_queryset is defined on DjangoObjectType
1 parent dd46f5f commit ad2688f

File tree

1 file changed

+44
-0
lines changed

1 file changed

+44
-0
lines changed

graphene_django/tests/test_query.py

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1007,3 +1007,47 @@ class Query(graphene.ObjectType):
10071007

10081008
result = schema.execute(query)
10091009
assert result.errors
1010+
1011+
1012+
def test_should_resolve_get_queryset_connectionfields():
1013+
reporter_1 = Reporter.objects.create(
1014+
first_name="John", last_name="Doe", email="johndoe@example.com", a_choice=1
1015+
)
1016+
reporter_2 = CNNReporter.objects.create(
1017+
first_name="Some",
1018+
last_name="Guy",
1019+
email="someguy@cnn.com",
1020+
a_choice=1,
1021+
reporter_type=2, # set this guy to be CNN
1022+
)
1023+
1024+
class ReporterType(DjangoObjectType):
1025+
class Meta:
1026+
model = Reporter
1027+
interfaces = (Node,)
1028+
1029+
@classmethod
1030+
def get_queryset(cls, queryset, info):
1031+
return queryset.filter(reporter_type=2)
1032+
1033+
class Query(graphene.ObjectType):
1034+
all_reporters = DjangoConnectionField(ReporterType)
1035+
1036+
schema = graphene.Schema(query=Query)
1037+
query = """
1038+
query ReporterPromiseConnectionQuery {
1039+
allReporters(first: 1) {
1040+
edges {
1041+
node {
1042+
id
1043+
}
1044+
}
1045+
}
1046+
}
1047+
"""
1048+
1049+
expected = {"allReporters": {"edges": [{"node": {"id": "UmVwb3J0ZXJUeXBlOjI="}}]}}
1050+
1051+
result = schema.execute(query)
1052+
assert not result.errors
1053+
assert result.data == expected

0 commit comments

Comments
 (0)