Skip to content

Commit 68344cb

Browse files
committed
Incorporated concepts from PR 70
1 parent e84f98b commit 68344cb

File tree

6 files changed

+73
-25
lines changed

6 files changed

+73
-25
lines changed

src/GraphQLParser.ApiTests/GraphQL-Parser.approved.txt

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,7 @@ namespace GraphQLParser.AST
4747
TypeExtensionDefinition = 35,
4848
DirectiveDefinition = 36,
4949
Comment = 37,
50+
Description = 38,
5051
}
5152
public class GraphQLArgument : GraphQLParser.AST.ASTNode, GraphQLParser.AST.INamedNode
5253
{
@@ -62,6 +63,12 @@ namespace GraphQLParser.AST
6263
public GraphQLParser.ROM Text { get; set; }
6364
public override GraphQLParser.AST.GraphQLLocation Location { get; set; }
6465
}
66+
public class GraphQLDescription : GraphQLParser.AST.ASTNode
67+
{
68+
public GraphQLDescription() { }
69+
public override GraphQLParser.AST.ASTNodeKind Kind { get; }
70+
public GraphQLParser.ROM Value { get; set; }
71+
}
6572
public class GraphQLDirective : GraphQLParser.AST.ASTNode, GraphQLParser.AST.INamedNode
6673
{
6774
public GraphQLDirective() { }
@@ -280,10 +287,10 @@ namespace GraphQLParser.AST
280287
protected GraphQLTypeDefinition() { }
281288
public GraphQLParser.AST.GraphQLName? Name { get; set; }
282289
}
283-
public abstract class GraphQLTypeDefinitionWithDescription : GraphQLParser.AST.GraphQLTypeDefinition
290+
public abstract class GraphQLTypeDefinitionWithDescription : GraphQLParser.AST.GraphQLTypeDefinition, GraphQLParser.AST.IHasDescription
284291
{
285292
protected GraphQLTypeDefinitionWithDescription() { }
286-
public GraphQLParser.AST.GraphQLScalarValue? Description { get; set; }
293+
public GraphQLParser.AST.GraphQLDescription? Description { get; set; }
287294
}
288295
public class GraphQLTypeExtensionDefinition : GraphQLParser.AST.GraphQLTypeDefinition
289296
{
@@ -316,6 +323,10 @@ namespace GraphQLParser.AST
316323
public GraphQLParser.AST.GraphQLType? Type { get; set; }
317324
public GraphQLParser.AST.GraphQLVariable? Variable { get; set; }
318325
}
326+
public interface IHasDescription
327+
{
328+
GraphQLParser.AST.GraphQLDescription? Description { get; set; }
329+
}
319330
public interface IHasDirectivesNode
320331
{
321332
System.Collections.Generic.List<GraphQLParser.AST.GraphQLDirective>? Directives { get; set; }

src/GraphQLParser/AST/ASTNodeKind.cs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -89,5 +89,10 @@ public enum ASTNodeKind
8989
/// and have no significance to the semantic meaning of a GraphQL Document.
9090
/// </summary>
9191
Comment,
92+
93+
/// <summary>
94+
/// Description of a type definition.
95+
/// </summary>
96+
Description,
9297
}
9398
}
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
namespace GraphQLParser.AST
2+
{
3+
public class GraphQLDescription : ASTNode
4+
{
5+
public override ASTNodeKind Kind => ASTNodeKind.Description;
6+
7+
public ROM Value { get; set; }
8+
}
9+
}

src/GraphQLParser/AST/GraphQLTypeDefinition.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,11 +6,11 @@ public abstract class GraphQLTypeDefinition : ASTNode, INamedNode
66
public GraphQLName? Name { get; set; }
77
}
88

9-
public abstract class GraphQLTypeDefinitionWithDescription : GraphQLTypeDefinition
9+
public abstract class GraphQLTypeDefinitionWithDescription : GraphQLTypeDefinition, IHasDescription
1010
{
1111
/// <summary>
12-
/// Description of the node as represented by a nested node.
12+
/// Description of the node
1313
/// </summary>
14-
public GraphQLScalarValue? Description { get; set; }
14+
public GraphQLDescription? Description { get; set; }
1515
}
1616
}
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
namespace GraphQLParser.AST
2+
{
3+
public interface IHasDescription
4+
{
5+
GraphQLDescription? Description { get; set; }
6+
}
7+
}

src/GraphQLParser/ParserContext.Parse.cs

Lines changed: 36 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -233,10 +233,10 @@ private GraphQLDirective ParseDirective()
233233
private GraphQLDirectiveDefinition ParseDirectiveDefinition()
234234
{
235235
int start = _currentToken.Start;
236-
GraphQLScalarValue? description = null;
236+
GraphQLDescription? description = null;
237237
if (Peek(TokenKind.STRING))
238238
{
239-
description = ParseString();
239+
description = ParseDescription();
240240
ParseComment();
241241
}
242242
var comment = GetComment();
@@ -349,10 +349,10 @@ private GraphQLDocument ParseDocument()
349349
private GraphQLEnumTypeDefinition ParseEnumTypeDefinition()
350350
{
351351
int start = _currentToken.Start;
352-
GraphQLScalarValue? description = null;
352+
GraphQLDescription? description = null;
353353
if (Peek(TokenKind.STRING))
354354
{
355-
description = ParseString();
355+
description = ParseDescription();
356356
ParseComment();
357357
}
358358
var comment = GetComment();
@@ -395,10 +395,10 @@ private GraphQLValue ParseEnumValue(Token token)
395395
private GraphQLEnumValueDefinition ParseEnumValueDefinition()
396396
{
397397
int start = _currentToken.Start;
398-
GraphQLScalarValue? description = null;
398+
GraphQLDescription? description = null;
399399
if (Peek(TokenKind.STRING))
400400
{
401-
description = ParseString();
401+
description = ParseDescription();
402402
ParseComment();
403403
}
404404
var comment = GetComment();
@@ -423,10 +423,10 @@ private GraphQLEnumValueDefinition ParseEnumValueDefinition()
423423
private GraphQLFieldDefinition ParseFieldDefinition()
424424
{
425425
int start = _currentToken.Start;
426-
GraphQLScalarValue? description = null;
426+
GraphQLDescription? description = null;
427427
if (Peek(TokenKind.STRING))
428428
{
429-
description = ParseString();
429+
description = ParseDescription();
430430
ParseComment();
431431
}
432432

@@ -624,10 +624,10 @@ private void Throw_From_ParseFragmentName()
624624
private GraphQLInputObjectTypeDefinition ParseInputObjectTypeDefinition()
625625
{
626626
int start = _currentToken.Start;
627-
GraphQLScalarValue? description = null;
627+
GraphQLDescription? description = null;
628628
if (Peek(TokenKind.STRING))
629629
{
630-
description = ParseString();
630+
description = ParseDescription();
631631
ParseComment();
632632
}
633633
var comment = GetComment();
@@ -655,10 +655,10 @@ private GraphQLInputObjectTypeDefinition ParseInputObjectTypeDefinition()
655655
private GraphQLInputValueDefinition ParseInputValueDef()
656656
{
657657
int start = _currentToken.Start;
658-
GraphQLScalarValue? description = null;
658+
GraphQLDescription? description = null;
659659
if (Peek(TokenKind.STRING))
660660
{
661-
description = ParseString();
661+
description = ParseDescription();
662662
ParseComment();
663663
}
664664
var comment = GetComment();
@@ -706,10 +706,10 @@ private GraphQLValue ParseInt(/*bool isConstant*/)
706706
private GraphQLInterfaceTypeDefinition ParseInterfaceTypeDefinition()
707707
{
708708
int start = _currentToken.Start;
709-
GraphQLScalarValue? description = null;
709+
GraphQLDescription? description = null;
710710
if (Peek(TokenKind.STRING))
711711
{
712-
description = ParseString();
712+
description = ParseDescription();
713713
ParseComment();
714714
}
715715
var comment = GetComment();
@@ -964,10 +964,10 @@ private List<GraphQLObjectField> ParseObjectFields(bool isConstant)
964964
private GraphQLObjectTypeDefinition ParseObjectTypeDefinition()
965965
{
966966
int start = _currentToken.Start;
967-
GraphQLScalarValue? description = null;
967+
GraphQLDescription? description = null;
968968
if (Peek(TokenKind.STRING))
969969
{
970-
description = ParseString();
970+
description = ParseDescription();
971971
ParseComment();
972972
}
973973
var comment = GetComment();
@@ -1084,10 +1084,10 @@ private GraphQLOperationTypeDefinition ParseOperationTypeDefinition()
10841084
private GraphQLScalarTypeDefinition ParseScalarTypeDefinition()
10851085
{
10861086
int start = _currentToken.Start;
1087-
GraphQLScalarValue? description = null;
1087+
GraphQLDescription? description = null;
10881088
if (Peek(TokenKind.STRING))
10891089
{
1090-
description = ParseString();
1090+
description = ParseDescription();
10911091
ParseComment();
10921092
}
10931093
var comment = GetComment();
@@ -1173,6 +1173,22 @@ private GraphQLScalarValue ParseString(/*bool isConstant*/)
11731173
};
11741174
}
11751175

1176+
private GraphQLDescription ParseDescription()
1177+
{
1178+
var token = _currentToken;
1179+
Advance();
1180+
return _ignoreOptions == IgnoreOptions.IgnoreCommentsAndLocations
1181+
? new GraphQLDescription()
1182+
{
1183+
Value = token.Value,
1184+
}
1185+
: new GraphQLDescription()
1186+
{
1187+
Value = token.Value,
1188+
Location = GetLocation(token.Start)
1189+
};
1190+
}
1191+
11761192
private GraphQLType ParseType()
11771193
{
11781194
GraphQLType type;
@@ -1253,10 +1269,10 @@ private List<GraphQLNamedType> ParseUnionMembers()
12531269
private GraphQLUnionTypeDefinition ParseUnionTypeDefinition()
12541270
{
12551271
int start = _currentToken.Start;
1256-
GraphQLScalarValue? description = null;
1272+
GraphQLDescription? description = null;
12571273
if (Peek(TokenKind.STRING))
12581274
{
1259-
description = ParseString();
1275+
description = ParseDescription();
12601276
ParseComment();
12611277
}
12621278
var comment = GetComment();

0 commit comments

Comments
 (0)