-
Notifications
You must be signed in to change notification settings - Fork 7
/
Copy pathtest_inline_fragment.py
59 lines (52 loc) · 1.35 KB
/
test_inline_fragment.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
from typing import Union, List
from graphql_query import Field, GraphQLQueryBaseModel, InlineFragment
def test_inline_fragments():
class Droid(GraphQLQueryBaseModel):
primaryFunction: str
class Human(GraphQLQueryBaseModel):
height: float
class Hero(GraphQLQueryBaseModel):
name: str
type: Union[Human, Droid]
types: List[Union[Human, Droid]]
correct = [
Field(name="name", fields=[]),
Field(
name="type",
fields=[
InlineFragment(type="Human", fields=[Field(name="height", fields=[])]),
InlineFragment(type="Droid", fields=[Field(name="primaryFunction", fields=[])]),
],
),
Field(
name="types",
fields=[
InlineFragment(type="Human", fields=[Field(name="height", fields=[])]),
InlineFragment(type="Droid", fields=[Field(name="primaryFunction", fields=[])]),
],
),
]
generated = Hero.graphql_fields()
assert generated == correct
assert (
Field(name="hero", fields=generated).render()
== """hero {
name
type {
... on Human {
height
}
... on Droid {
primaryFunction
}
}
types {
... on Human {
height
}
... on Droid {
primaryFunction
}
}
}"""
)