Skip to content

Commit dfb55cd

Browse files
author
Pablo Chinea
committed
Adds test for nested node filtering.
1 parent b26f914 commit dfb55cd

File tree

1 file changed

+84
-0
lines changed

1 file changed

+84
-0
lines changed

graphene_django/tests/test_query.py

Lines changed: 84 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -281,3 +281,87 @@ def resolve_all_reporters(self, args, context, info):
281281
}]
282282
}
283283
}
284+
285+
def test_should_query_node_filtering():
286+
class ReporterType(DjangoObjectType):
287+
288+
class Meta:
289+
model = Reporter
290+
interfaces = (Node, )
291+
292+
class ArticleType(DjangoObjectType):
293+
294+
class Meta:
295+
model = Article
296+
interfaces = (Node, )
297+
filter_fields = ('lang', )
298+
299+
class Query(graphene.ObjectType):
300+
all_reporters = DjangoConnectionField(ReporterType)
301+
302+
r = Reporter.objects.create(
303+
first_name='John',
304+
last_name='Doe',
305+
email='johndoe@example.com',
306+
a_choice=1
307+
)
308+
Article.objects.create(
309+
headline='Article Node 1',
310+
pub_date=datetime.date.today(),
311+
reporter=r,
312+
editor=r,
313+
lang='es'
314+
)
315+
Article.objects.create(
316+
headline='Article Node 2',
317+
pub_date=datetime.date.today(),
318+
reporter=r,
319+
editor=r,
320+
lang='en'
321+
)
322+
323+
324+
schema = graphene.Schema(query=Query)
325+
query = '''
326+
query NodeFilteringQuery {
327+
allReporters {
328+
edges {
329+
node {
330+
id
331+
articles(lang: "es") {
332+
edges {
333+
node {
334+
id
335+
}
336+
}
337+
}
338+
}
339+
}
340+
}
341+
}
342+
'''
343+
344+
expected = {
345+
"allReporters": {
346+
"edges": [
347+
{
348+
"node": {
349+
"id": "UmVwb3J0ZXJUeXBlOjE=",
350+
"articles": {
351+
"edges": [
352+
{
353+
"node": {
354+
"id": "QXJ0aWNsZVR5cGU6MQ=="
355+
}
356+
}
357+
]
358+
}
359+
}
360+
}
361+
]
362+
}
363+
}
364+
365+
result = schema.execute(query)
366+
assert not result.errors
367+
assert result.data == expected

0 commit comments

Comments
 (0)