Skip to content

Commit e0d26bf

Browse files
committed
add test for correct order
1 parent 0372bfb commit e0d26bf

File tree

1 file changed

+66
-0
lines changed

1 file changed

+66
-0
lines changed

src/test/groovy/graphql/analysis/QueryTraversalTest.groovy

Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,71 @@ class QueryTraversalTest extends Specification {
2727
return queryTraversal
2828
}
2929

30+
def "test preOrder order"() {
31+
given:
32+
def schema = TestUtil.schema("""
33+
type Query{
34+
foo: Foo
35+
bar: String
36+
}
37+
type Foo {
38+
subFoo: String
39+
}
40+
""")
41+
def visitor = Mock(QueryVisitor)
42+
def query = createQuery("""
43+
{foo { subFoo} bar }
44+
""")
45+
QueryTraversal queryTraversal = createQueryTraversal(query, schema, visitor)
46+
when:
47+
queryTraversal.visitPreOrder(visitor)
48+
49+
then:
50+
1 * visitor.visitField({ QueryVisitorEnvironment it -> it.field.name == "foo" && it.fieldDefinition.type.name == "Foo" && it.parent.name == "Query" })
51+
then:
52+
1 * visitor.visitField({ QueryVisitorEnvironment it ->
53+
it.field.name == "subFoo" && it.fieldDefinition.type.name == "String" &&
54+
it.parent.name == "Foo" &&
55+
it.path.field.name == "foo" && it.path.fieldDefinition.type.name == "Foo"
56+
})
57+
then:
58+
1 * visitor.visitField({ QueryVisitorEnvironment it -> it.field.name == "bar" && it.fieldDefinition.type.name == "String" && it.parent.name == "Query" })
59+
60+
}
61+
62+
def "test postOrder order"() {
63+
given:
64+
def schema = TestUtil.schema("""
65+
type Query{
66+
foo: Foo
67+
bar: String
68+
}
69+
type Foo {
70+
subFoo: String
71+
}
72+
""")
73+
def visitor = Mock(QueryVisitor)
74+
def query = createQuery("""
75+
{foo { subFoo} bar }
76+
""")
77+
QueryTraversal queryTraversal = createQueryTraversal(query, schema, visitor)
78+
when:
79+
queryTraversal.visitPostOrder(visitor)
80+
81+
then:
82+
1 * visitor.visitField({ QueryVisitorEnvironment it ->
83+
it.field.name == "subFoo" && it.fieldDefinition.type.name == "String" &&
84+
it.parent.name == "Foo" &&
85+
it.path.field.name == "foo" && it.path.fieldDefinition.type.name == "Foo"
86+
})
87+
then:
88+
1 * visitor.visitField({ QueryVisitorEnvironment it -> it.field.name == "foo" && it.fieldDefinition.type.name == "Foo" && it.parent.name == "Query" })
89+
then:
90+
1 * visitor.visitField({ QueryVisitorEnvironment it -> it.field.name == "bar" && it.fieldDefinition.type.name == "String" && it.parent.name == "Query" })
91+
92+
}
93+
94+
3095
@Unroll
3196
def "simple query: (#order)"() {
3297
given:
@@ -333,6 +398,7 @@ class QueryTraversalTest extends Specification {
333398
334399
}
335400
401+
336402
def "simple reduce"() {
337403
given:
338404
def schema = TestUtil.schema("""

0 commit comments

Comments
 (0)