@@ -78,7 +78,7 @@ tests = testSpec "AST" $ do
78
78
output `shouldBe` " [1.5,1.5]"
79
79
parseOnly Parser. value output `shouldBe` Right input
80
80
describe " Parser" $ do
81
- it " parses anonymous query documents" $ do
81
+ it " parses shorthand syntax documents" $ do
82
82
let query = [r |{
83
83
dog {
84
84
name
@@ -96,6 +96,25 @@ tests = testSpec "AST" $ do
96
96
]
97
97
parsed `shouldBe` expected
98
98
99
+ it " parses anonymous query documents" $ do
100
+ let query = [r |query {
101
+ dog {
102
+ name
103
+ }
104
+ }|]
105
+ let Right parsed = parseOnly Parser. queryDocument query
106
+ let expected = AST. QueryDocument
107
+ [ AST. DefinitionOperation
108
+ (AST. Query
109
+ (AST. Node Nothing [] []
110
+ [ AST. SelectionField
111
+ (AST. Field Nothing dog [] []
112
+ [ AST. SelectionField (AST. Field Nothing someName [] [] [] )
113
+ ])
114
+ ]))
115
+ ]
116
+ parsed `shouldBe` expected
117
+
99
118
it " parses invalid documents" $ do
100
119
let query = [r |{
101
120
dog {
@@ -162,3 +181,33 @@ tests = testSpec "AST" $ do
162
181
]))
163
182
]
164
183
parsed `shouldBe` expected
184
+
185
+ it " parses anonymous query with variables" $ do
186
+ let query = [r |
187
+ query ($atOtherHomes: Boolean = true) {
188
+ dog {
189
+ isHousetrained(atOtherHomes: $atOtherHomes)
190
+ }
191
+ }
192
+ |]
193
+ let Right parsed = parseOnly Parser. queryDocument query
194
+ let expected = AST. QueryDocument
195
+ [ AST. DefinitionOperation
196
+ (AST. Query
197
+ (AST. Node Nothing
198
+ [ AST. VariableDefinition
199
+ (AST. Variable " atOtherHomes" )
200
+ (AST. TypeNamed (AST. NamedType " Boolean" ))
201
+ (Just (AST. ValueBoolean True ))
202
+ ] []
203
+ [ AST. SelectionField
204
+ (AST. Field Nothing dog [] []
205
+ [ AST. SelectionField
206
+ (AST. Field Nothing " isHousetrained"
207
+ [ AST. Argument " atOtherHomes"
208
+ (AST. ValueVariable (AST. Variable " atOtherHomes" ))
209
+ ] [] [] )
210
+ ])
211
+ ]))
212
+ ]
213
+ parsed `shouldBe` expected
0 commit comments