@@ -12,6 +12,81 @@ public class ParserTests
12
12
{
13
13
private static readonly string NL = Environment . NewLine ;
14
14
15
+ [ Fact ]
16
+ public void Comments_on_FragmentSpread_Should_Read_Correclty ( )
17
+ {
18
+ const string query = @"
19
+ query _ {
20
+ person {
21
+ #comment
22
+ ...human
23
+ }
24
+ }
25
+
26
+ fragment human on person {
27
+ name
28
+ }" ;
29
+
30
+ var parser = new Parser ( new Lexer ( ) ) ;
31
+ var document = parser . Parse ( new Source ( query ) ) ;
32
+ document . Definitions . Count ( ) . ShouldBe ( 2 ) ;
33
+ var def = document . Definitions . First ( ) as GraphQLOperationDefinition ;
34
+ def . SelectionSet . Selections . Count ( ) . ShouldBe ( 1 ) ;
35
+ var field = def . SelectionSet . Selections . First ( ) as GraphQLFieldSelection ;
36
+ field . SelectionSet . Selections . Count ( ) . ShouldBe ( 1 ) ;
37
+ var fragment = field . SelectionSet . Selections . First ( ) as GraphQLFragmentSpread ;
38
+ fragment . Comment . Text . ShouldBe ( "comment" ) ;
39
+ }
40
+
41
+ [ Fact ]
42
+ public void Comments_on_FragmentInline_Should_Read_Correclty ( )
43
+ {
44
+ const string query = @"
45
+ query _ {
46
+ person {
47
+ #comment
48
+ ... on human {
49
+ name
50
+ }
51
+ }
52
+ }" ;
53
+
54
+ var parser = new Parser ( new Lexer ( ) ) ;
55
+ var document = parser . Parse ( new Source ( query ) ) ;
56
+ document . Definitions . Count ( ) . ShouldBe ( 1 ) ;
57
+ var def = document . Definitions . First ( ) as GraphQLOperationDefinition ;
58
+ def . SelectionSet . Selections . Count ( ) . ShouldBe ( 1 ) ;
59
+ var field = def . SelectionSet . Selections . First ( ) as GraphQLFieldSelection ;
60
+ field . SelectionSet . Selections . Count ( ) . ShouldBe ( 1 ) ;
61
+ var fragment = field . SelectionSet . Selections . First ( ) as GraphQLInlineFragment ;
62
+ fragment . Comment . Text . ShouldBe ( "comment" ) ;
63
+ }
64
+
65
+ [ Fact ]
66
+ public void Comments_on_Variable_Should_Read_Correclty ( )
67
+ {
68
+ const string query = @"
69
+ query _(
70
+ #comment1
71
+ $id: ID,
72
+ $id2: String!,
73
+ #comment3
74
+ $id3: String) {
75
+ person {
76
+ name
77
+ }
78
+ }" ;
79
+
80
+ var parser = new Parser ( new Lexer ( ) ) ;
81
+ var document = parser . Parse ( new Source ( query ) ) ;
82
+ document . Definitions . Count ( ) . ShouldBe ( 1 ) ;
83
+ var def = document . Definitions . First ( ) as GraphQLOperationDefinition ;
84
+ def . VariableDefinitions . Count ( ) . ShouldBe ( 3 ) ;
85
+ def . VariableDefinitions . First ( ) . Comment . Text . ShouldBe ( "comment1" ) ;
86
+ def . VariableDefinitions . Skip ( 1 ) . First ( ) . Comment . ShouldBeNull ( ) ;
87
+ def . VariableDefinitions . Skip ( 2 ) . First ( ) . Comment . Text . ShouldBe ( "comment3" ) ;
88
+ }
89
+
15
90
[ Fact ]
16
91
public void Comments_On_SelectionSet_Should_Read_Correctly ( )
17
92
{
@@ -456,4 +531,4 @@ public void Should_Parse_Unions(string text)
456
531
new Parser ( new Lexer ( ) ) . Parse ( new Source ( text ) ) . ShouldNotBeNull ( ) ;
457
532
}
458
533
}
459
- }
534
+ }
0 commit comments