@@ -78,7 +78,7 @@ tests = testSpec "AST" $ do
7878 output `shouldBe` " [1.5,1.5]"
7979 parseOnly Parser. value output `shouldBe` Right input
8080 describe " Parser" $ do
81- it " parses anonymous query documents" $ do
81+ it " parses shorthand syntax documents" $ do
8282 let query = [r |{
8383 dog {
8484 name
@@ -96,6 +96,25 @@ tests = testSpec "AST" $ do
9696 ]
9797 parsed `shouldBe` expected
9898
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+
99118 it " parses invalid documents" $ do
100119 let query = [r |{
101120 dog {
@@ -162,3 +181,33 @@ tests = testSpec "AST" $ do
162181 ]))
163182 ]
164183 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