Skip to content

Commit

Permalink
Adds test for nested node filtering.
Browse files Browse the repository at this point in the history
  • Loading branch information
Pablo Chinea committed Dec 30, 2016
1 parent b26f914 commit dfb55cd
Showing 1 changed file with 84 additions and 0 deletions.
84 changes: 84 additions & 0 deletions graphene_django/tests/test_query.py
Original file line number Diff line number Diff line change
Expand Up @@ -281,3 +281,87 @@ def resolve_all_reporters(self, args, context, info):
}]
}
}

def test_should_query_node_filtering():
class ReporterType(DjangoObjectType):

class Meta:
model = Reporter
interfaces = (Node, )

class ArticleType(DjangoObjectType):

class Meta:
model = Article
interfaces = (Node, )
filter_fields = ('lang', )

class Query(graphene.ObjectType):
all_reporters = DjangoConnectionField(ReporterType)

r = Reporter.objects.create(
first_name='John',
last_name='Doe',
email='johndoe@example.com',
a_choice=1
)
Article.objects.create(
headline='Article Node 1',
pub_date=datetime.date.today(),
reporter=r,
editor=r,
lang='es'
)
Article.objects.create(
headline='Article Node 2',
pub_date=datetime.date.today(),
reporter=r,
editor=r,
lang='en'
)


schema = graphene.Schema(query=Query)
query = '''
query NodeFilteringQuery {
allReporters {
edges {
node {
id
articles(lang: "es") {
edges {
node {
id
}
}
}
}
}
}
}
'''

expected = {
"allReporters": {
"edges": [
{
"node": {
"id": "UmVwb3J0ZXJUeXBlOjE=",
"articles": {
"edges": [
{
"node": {
"id": "QXJ0aWNsZVR5cGU6MQ=="
}
}
]
}
}
}
]
}
}

result = schema.execute(query)
assert not result.errors
assert result.data == expected

0 comments on commit dfb55cd

Please sign in to comment.