Skip to content

Commit df6d2eb

Browse files
committed
Annotate selection
1 parent 610f303 commit df6d2eb

File tree

6 files changed

+53
-27
lines changed

6 files changed

+53
-27
lines changed

src/GraphQL/Internal/Syntax/AST.hs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -97,9 +97,9 @@ instance Arbitrary Variable where
9797

9898
type SelectionSet = [Selection]
9999

100-
data Selection = SelectionField Field
101-
| SelectionFragmentSpread FragmentSpread
102-
| SelectionInlineFragment InlineFragment
100+
data Selection = SelectionField Field PositionInfo
101+
| SelectionFragmentSpread FragmentSpread PositionInfo
102+
| SelectionInlineFragment InlineFragment PositionInfo
103103
deriving (Eq,Show)
104104

105105
data Field = Field (Maybe Alias) Name [Argument] [Directive] SelectionSet

src/GraphQL/Internal/Syntax/Encoder.hs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -61,9 +61,9 @@ selectionSet :: AST.SelectionSet -> Text
6161
selectionSet = bracesCommas selection
6262

6363
selection :: AST.Selection -> Text
64-
selection (AST.SelectionField x) = field x
65-
selection (AST.SelectionInlineFragment x) = inlineFragment x
66-
selection (AST.SelectionFragmentSpread x) = fragmentSpread x
64+
selection (AST.SelectionField x _) = field x
65+
selection (AST.SelectionInlineFragment x _) = inlineFragment x
66+
selection (AST.SelectionFragmentSpread x _) = fragmentSpread x
6767

6868
field :: AST.Field -> Text
6969
field (AST.Field alias name args ds ss) =

src/GraphQL/Internal/Syntax/Parser.hs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -92,11 +92,11 @@ selectionSet :: Parser AST.SelectionSet
9292
selectionSet = braces $ many1 selection
9393

9494
selection :: Parser AST.Selection
95-
selection = AST.SelectionField <$> field
95+
selection = positioned (AST.SelectionField <$> field
9696
-- Inline first to catch `on` case
9797
<|> AST.SelectionInlineFragment <$> inlineFragment
9898
<|> AST.SelectionFragmentSpread <$> fragmentSpread
99-
<?> "selection error!"
99+
<?> "selection error!")
100100

101101
field :: Parser AST.Field
102102
field = AST.Field <$> option empty (pure <$> alias)

src/GraphQL/Internal/Validation.hs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -497,14 +497,14 @@ traverseFragmentSpreads f selection =
497497
validateSelection :: Schema -> AST.Selection -> Validation (Selection' UnresolvedFragmentSpread AST.Value)
498498
validateSelection schema selection =
499499
case selection of
500-
AST.SelectionField (AST.Field alias name args directives ss) ->
500+
AST.SelectionField (AST.Field alias name args directives ss) _ ->
501501
SelectionField <$> (Field' alias name
502502
<$> validateArguments args
503503
<*> validateDirectives directives
504504
<*> childSegments ss)
505-
AST.SelectionFragmentSpread (AST.FragmentSpread name directives) ->
505+
AST.SelectionFragmentSpread (AST.FragmentSpread name directives) _ ->
506506
SelectionFragmentSpread <$> (UnresolvedFragmentSpread name <$> validateDirectives directives)
507-
AST.SelectionInlineFragment (AST.InlineFragment typeCond directives ss) ->
507+
AST.SelectionInlineFragment (AST.InlineFragment typeCond directives ss) _ ->
508508
SelectionInlineFragment <$> (InlineFragment
509509
<$> traverse (validateTypeCondition schema) typeCond
510510
<*> validateDirectives directives

tests/ASTTests.hs

Lines changed: 20 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -90,8 +90,9 @@ tests = testSpec "AST" $ do
9090
(AST.AnonymousQuery
9191
[ AST.SelectionField
9292
(AST.Field Nothing dog [] []
93-
[ AST.SelectionField (AST.Field Nothing someName [] [] [])
93+
[ AST.SelectionField (AST.Field Nothing someName [] [] []) (Just (56,84))
9494
])
95+
(Just (25,107))
9596
] $ Just (0, 108)
9697
) $ Just (0, 108)
9798
] (Just (0, 108))
@@ -110,8 +111,9 @@ tests = testSpec "AST" $ do
110111
(AST.Node Nothing [] []
111112
[ AST.SelectionField
112113
(AST.Field Nothing dog [] []
113-
[ AST.SelectionField (AST.Field Nothing someName [] [] [])
114+
[ AST.SelectionField (AST.Field Nothing someName [] [] []) (Just (62,90))
114115
])
116+
(Just (31,113))
115117
] $ Just (6, 114)) $ Just (0, 114)
116118
) $ Just (0, 114)
117119
] (Just (0, 114))
@@ -147,8 +149,9 @@ tests = testSpec "AST" $ do
147149
(AST.AnonymousQuery
148150
[ AST.SelectionField
149151
(AST.Field Nothing dog [] []
150-
[ AST.SelectionField (AST.Field Nothing someName [] [] [])
152+
[ AST.SelectionField (AST.Field Nothing someName [] [] []) (Just (56,84))
151153
])
154+
(Just (25,107))
152155
] $ Just (0,131)
153156
) $ Just (0,131)
154157
, AST.DefinitionOperation
@@ -158,9 +161,11 @@ tests = testSpec "AST" $ do
158161
(AST.Field Nothing dog [] []
159162
[ AST.SelectionField
160163
(AST.Field Nothing "owner" [] []
161-
[ AST.SelectionField (AST.Field Nothing someName [] [] [])
164+
[ AST.SelectionField (AST.Field Nothing someName [] [] []) (Just (236,266))
162165
])
166+
(Just (201,291))
163167
])
168+
(Just (170,314))
164169
] $ Just (137,315)) $ Just (131,315)
165170
) $ Just (131,315)
166171
] (Just (0, 315))
@@ -192,7 +197,9 @@ tests = testSpec "AST" $ do
192197
[ AST.Argument "atOtherHomes"
193198
(AST.ValueVariable (AST.Variable "atOtherHomes"))
194199
] [] [])
200+
(Just (130,196))
195201
])
202+
(Just (100,218))
196203
] $ Just (27, 240)
197204
) $ Just (21, 240)
198205
) $ Just (21, 240)
@@ -225,7 +232,9 @@ tests = testSpec "AST" $ do
225232
[ AST.Argument "atOtherHomes"
226233
(AST.ValueVariable (AST.Variable "atOtherHomes"))
227234
] [] [])
235+
(Just (113,179))
228236
])
237+
(Just (83,201))
229238
] $ Just (27, 223)
230239
) $ Just (21, 223)
231240
) $ Just (21, 223)
@@ -263,7 +272,9 @@ tests = testSpec "AST" $ do
263272
[ AST.Argument "atOtherHomes"
264273
(AST.ValueVariable (AST.Variable "atOtherHomes"))
265274
] [] [])
275+
(Just (106,172))
266276
])
277+
(Just (76,194))
267278
] $ Just (27, 216)
268279
) $ Just (21, 216)
269280
) $ Just (21, 216)
@@ -296,7 +307,9 @@ tests = testSpec "AST" $ do
296307
])
297308
]))
298309
] [] [])
310+
(Just (81,172))
299311
])
312+
(Just (51,194))
300313
] $ Just (27, 216)
301314
) $ Just (21, 216)
302315
) $ Just (21,216)
@@ -318,16 +331,17 @@ tests = testSpec "AST" $ do
318331
let expected = AST.QueryDocument
319332
[AST.DefinitionFragment (AST.FragmentDefinition "dogTest"
320333
(AST.NamedType "Dog") [] [
321-
AST.SelectionField (AST.Field Nothing "name" [] [] [])
334+
AST.SelectionField (AST.Field Nothing "name" [] [] []) (Just (69,94))
322335
]) $ Just (21, 116),
323336
AST.DefinitionOperation
324337
(AST.Query
325338
(AST.Node Nothing
326339
[] []
327340
[AST.SelectionField
328341
(AST.Field Nothing dog [] []
329-
[AST.SelectionFragmentSpread (AST.FragmentSpread "dogTest" [])
342+
[AST.SelectionFragmentSpread (AST.FragmentSpread "dogTest" []) (Just (176,209))
330343
])
344+
(Just (146,231))
331345
] $ Just (122, 253)
332346
) $ Just (116, 253)
333347
) $ Just (116, 253)

tests/ValidationTests.hs

Lines changed: 22 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ tests = testSpec "Validation" $ do
4444
[ AST.DefinitionOperation
4545
( AST.Query
4646
( AST.Node me [] []
47-
[ AST.SelectionField (AST.Field Nothing someName [] [] [])
47+
[ AST.SelectionField (AST.Field Nothing someName [] [] []) Nothing
4848
] Nothing
4949
) Nothing
5050
) Nothing
@@ -58,8 +58,9 @@ tests = testSpec "Validation" $ do
5858
(AST.Node Nothing [] []
5959
[ AST.SelectionField
6060
(AST.Field Nothing dog [] []
61-
[ AST.SelectionField (AST.Field Nothing someName [] [] [])
61+
[ AST.SelectionField (AST.Field Nothing someName [] [] []) Nothing
6262
])
63+
Nothing
6364
] Nothing) Nothing
6465
) Nothing
6566
] Nothing
@@ -83,7 +84,9 @@ tests = testSpec "Validation" $ do
8384
[ AST.Argument "atOtherHomes"
8485
(AST.ValueVariable (AST.Variable "atOtherHomes"))
8586
] [] [])
87+
Nothing
8688
])
89+
Nothing
8790
] Nothing) Nothing
8891
) Nothing
8992
] Nothing
@@ -108,7 +111,9 @@ tests = testSpec "Validation" $ do
108111
[ AST.Argument "atOtherHomes"
109112
(AST.ValueVariable (AST.Variable "atOtherHomes"))
110113
] [] [])
114+
Nothing
111115
])
116+
Nothing
112117
] Nothing) Nothing
113118
) Nothing
114119
] Nothing
@@ -119,14 +124,14 @@ tests = testSpec "Validation" $ do
119124
[ AST.DefinitionOperation
120125
( AST.Query
121126
( AST.Node me [] []
122-
[ AST.SelectionField (AST.Field Nothing someName [] [] [])
127+
[ AST.SelectionField (AST.Field Nothing someName [] [] []) Nothing
123128
] Nothing
124129
) Nothing
125130
) Nothing
126131
, AST.DefinitionOperation
127132
( AST.Query
128133
( AST.Node me [] []
129-
[ AST.SelectionField (AST.Field Nothing someName [] [] [])
134+
[ AST.SelectionField (AST.Field Nothing someName [] [] []) Nothing
130135
] Nothing
131136
) Nothing
132137
) Nothing
@@ -137,12 +142,12 @@ tests = testSpec "Validation" $ do
137142
let doc = AST.QueryDocument
138143
[ AST.DefinitionOperation
139144
( AST.AnonymousQuery
140-
[ AST.SelectionField (AST.Field Nothing someName [] [] [])
145+
[ AST.SelectionField (AST.Field Nothing someName [] [] []) Nothing
141146
] Nothing
142147
) Nothing
143148
, AST.DefinitionOperation
144149
( AST.AnonymousQuery
145-
[ AST.SelectionField (AST.Field Nothing someName [] [] [])
150+
[ AST.SelectionField (AST.Field Nothing someName [] [] []) Nothing
146151
] Nothing
147152
) Nothing
148153
] Nothing
@@ -154,12 +159,12 @@ tests = testSpec "Validation" $ do
154159
let doc = AST.QueryDocument
155160
[ AST.DefinitionOperation
156161
( AST.AnonymousQuery
157-
[ AST.SelectionField (AST.Field Nothing someName [] [] [])
162+
[ AST.SelectionField (AST.Field Nothing someName [] [] []) Nothing
158163
] Nothing
159164
) Nothing
160165
, AST.DefinitionOperation
161166
( AST.Query (AST.Node (pure "houseTrainedQuery") [] []
162-
[ AST.SelectionField (AST.Field Nothing someName [] [] [])
167+
[ AST.SelectionField (AST.Field Nothing someName [] [] []) Nothing
163168
] Nothing
164169
) Nothing
165170
) Nothing
@@ -186,7 +191,9 @@ tests = testSpec "Validation" $ do
186191
[ AST.Argument "atOtherHomes"
187192
(AST.ValueVariable (AST.Variable "atOtherHomes"))
188193
] [] [])
194+
Nothing
189195
])
196+
Nothing
190197
] Nothing) Nothing
191198
) Nothing
192199
] Nothing
@@ -208,7 +215,9 @@ tests = testSpec "Validation" $ do
208215
[ AST.SelectionField
209216
(AST.Field Nothing "isHousetrained"
210217
[] [] [])
218+
Nothing
211219
])
220+
Nothing
212221
] Nothing) Nothing
213222
) Nothing
214223
] Nothing
@@ -232,7 +241,9 @@ tests = testSpec "Validation" $ do
232241
])
233242
]))
234243
] [] [])
244+
Nothing
235245
])
246+
Nothing
236247
] Nothing) Nothing
237248
) Nothing
238249
] Nothing
@@ -241,16 +252,17 @@ tests = testSpec "Validation" $ do
241252
let doc = AST.QueryDocument
242253
[AST.DefinitionFragment (AST.FragmentDefinition "dogTest"
243254
(AST.NamedType "Dog") [] [
244-
AST.SelectionField (AST.Field Nothing "name" [] [] [])
255+
AST.SelectionField (AST.Field Nothing "name" [] [] []) Nothing
245256
]) Nothing,
246257
AST.DefinitionOperation
247258
(AST.Query
248259
(AST.Node Nothing
249260
[] []
250261
[AST.SelectionField
251262
(AST.Field Nothing dog [] []
252-
[AST.SelectionFragmentSpread (AST.FragmentSpread "dogTest" [])
263+
[AST.SelectionFragmentSpread (AST.FragmentSpread "dogTest" []) Nothing
253264
])
265+
Nothing
254266
] Nothing) Nothing
255267
) Nothing
256268
] Nothing

0 commit comments

Comments
 (0)