Skip to content

Commit 94602c7

Browse files
committed
add reverse relation one to one query test
1 parent ce6e6dd commit 94602c7

File tree

2 files changed

+57
-3
lines changed

2 files changed

+57
-3
lines changed

graphene_django/debug/tests/test_query.py

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -50,9 +50,7 @@ def resolve_reporter(self, info, **args):
5050
"""
5151
expected = {
5252
"reporter": {"lastName": "ABA"},
53-
"_debug": {
54-
"sql": [{"rawSql": str(Reporter.objects.order_by("pk")[:1].query)}]
55-
},
53+
"_debug": {"sql": [{"rawSql": str(Reporter.objects.order_by("pk")[:1].query)}]},
5654
}
5755
schema = graphene.Schema(query=Query)
5856
result = schema.execute(

graphene_django/tests/test_query.py

Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -226,6 +226,62 @@ def resolve_reporter(self, info):
226226
assert result.data == expected
227227

228228

229+
def test_should_query_onetoone_fields():
230+
film = Film(id=1)
231+
film_details = FilmDetails(id=1, film=film)
232+
233+
class FilmNode(DjangoObjectType):
234+
class Meta:
235+
model = Film
236+
interfaces = (Node,)
237+
238+
class FilmDetailsNode(DjangoObjectType):
239+
class Meta:
240+
model = FilmDetails
241+
interfaces = (Node,)
242+
243+
class Query(graphene.ObjectType):
244+
film = graphene.Field(FilmNode)
245+
film_details = graphene.Field(FilmDetailsNode)
246+
247+
def resolve_film(root, info):
248+
return film
249+
250+
def resolve_film_details(root, info):
251+
return film_details
252+
253+
query = """
254+
query FilmQuery {
255+
filmDetails {
256+
id
257+
film {
258+
id
259+
}
260+
}
261+
film {
262+
id
263+
details {
264+
id
265+
}
266+
}
267+
}
268+
"""
269+
expected = {
270+
"filmDetails": {
271+
"id": "RmlsbURldGFpbHNOb2RlOjE=",
272+
"film": {"id": "RmlsbU5vZGU6MQ=="},
273+
},
274+
"film": {
275+
"id": "RmlsbU5vZGU6MQ==",
276+
"details": {"id": "RmlsbURldGFpbHNOb2RlOjE="},
277+
},
278+
}
279+
schema = graphene.Schema(query=Query)
280+
result = schema.execute(query)
281+
assert not result.errors
282+
assert result.data == expected
283+
284+
229285
def test_should_query_connectionfields():
230286
class ReporterType(DjangoObjectType):
231287
class Meta:

0 commit comments

Comments
 (0)