-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtest_query_plan.py
60 lines (56 loc) · 1.47 KB
/
test_query_plan.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
60
# test_query_plan.py
import unittest
from query_plan import QueryPlan, Fetch, Field, Sequence
class TestQueryPlan(unittest.TestCase):
def test_query_plan_document(self):
# Example of a test for the QueryPlan
query_plan = QueryPlan([
Sequence([
Fetch("SubgraphA", [
Field("updateFooInA", alias="updateInAOne", subfields=[
Field("id"),
Field("bar")
])
]),
Fetch("SubgraphB", [
Field("updateFooInB", alias="updateInBOne", subfields=[
Field("id"),
Field("baz")
])
])
]),
Fetch("SubgraphA", [
Field("updateFooInA", alias="updateInATwo", subfields=[
Field("id"),
Field("bar")
])
])
])
expected_output = """{
QueryPlan {
Sequence {
Fetch(service: "SubgraphA") {
updateInAOne: updateFooInA {
id
bar
}
}
Fetch(service: "SubgraphB") {
updateInBOne: updateFooInB {
id
baz
}
}
}
Fetch(service: "SubgraphA") {
updateInATwo: updateFooInA {
id
bar
}
}
}
}
"""
self.assertEqual(query_plan.to_document(), expected_output)
if __name__ == "__main__":
unittest.main()