Skip to content

Commit

Permalink
Incorporated concepts from PR 70
Browse files Browse the repository at this point in the history
  • Loading branch information
Shane32 committed Jul 6, 2021
1 parent e84f98b commit 68344cb
Show file tree
Hide file tree
Showing 6 changed files with 73 additions and 25 deletions.
15 changes: 13 additions & 2 deletions src/GraphQLParser.ApiTests/GraphQL-Parser.approved.txt
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ namespace GraphQLParser.AST
TypeExtensionDefinition = 35,
DirectiveDefinition = 36,
Comment = 37,
Description = 38,
}
public class GraphQLArgument : GraphQLParser.AST.ASTNode, GraphQLParser.AST.INamedNode
{
Expand All @@ -62,6 +63,12 @@ namespace GraphQLParser.AST
public GraphQLParser.ROM Text { get; set; }
public override GraphQLParser.AST.GraphQLLocation Location { get; set; }
}
public class GraphQLDescription : GraphQLParser.AST.ASTNode
{
public GraphQLDescription() { }
public override GraphQLParser.AST.ASTNodeKind Kind { get; }
public GraphQLParser.ROM Value { get; set; }
}
public class GraphQLDirective : GraphQLParser.AST.ASTNode, GraphQLParser.AST.INamedNode
{
public GraphQLDirective() { }
Expand Down Expand Up @@ -280,10 +287,10 @@ namespace GraphQLParser.AST
protected GraphQLTypeDefinition() { }
public GraphQLParser.AST.GraphQLName? Name { get; set; }
}
public abstract class GraphQLTypeDefinitionWithDescription : GraphQLParser.AST.GraphQLTypeDefinition
public abstract class GraphQLTypeDefinitionWithDescription : GraphQLParser.AST.GraphQLTypeDefinition, GraphQLParser.AST.IHasDescription
{
protected GraphQLTypeDefinitionWithDescription() { }
public GraphQLParser.AST.GraphQLScalarValue? Description { get; set; }
public GraphQLParser.AST.GraphQLDescription? Description { get; set; }
}
public class GraphQLTypeExtensionDefinition : GraphQLParser.AST.GraphQLTypeDefinition
{
Expand Down Expand Up @@ -316,6 +323,10 @@ namespace GraphQLParser.AST
public GraphQLParser.AST.GraphQLType? Type { get; set; }
public GraphQLParser.AST.GraphQLVariable? Variable { get; set; }
}
public interface IHasDescription
{
GraphQLParser.AST.GraphQLDescription? Description { get; set; }
}
public interface IHasDirectivesNode
{
System.Collections.Generic.List<GraphQLParser.AST.GraphQLDirective>? Directives { get; set; }
Expand Down
5 changes: 5 additions & 0 deletions src/GraphQLParser/AST/ASTNodeKind.cs
Original file line number Diff line number Diff line change
Expand Up @@ -89,5 +89,10 @@ public enum ASTNodeKind
/// and have no significance to the semantic meaning of a GraphQL Document.
/// </summary>
Comment,

/// <summary>
/// Description of a type definition.
/// </summary>
Description,
}
}
9 changes: 9 additions & 0 deletions src/GraphQLParser/AST/GraphQLDescription.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
namespace GraphQLParser.AST
{
public class GraphQLDescription : ASTNode
{
public override ASTNodeKind Kind => ASTNodeKind.Description;

public ROM Value { get; set; }
}
}
6 changes: 3 additions & 3 deletions src/GraphQLParser/AST/GraphQLTypeDefinition.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,11 @@ public abstract class GraphQLTypeDefinition : ASTNode, INamedNode
public GraphQLName? Name { get; set; }
}

public abstract class GraphQLTypeDefinitionWithDescription : GraphQLTypeDefinition
public abstract class GraphQLTypeDefinitionWithDescription : GraphQLTypeDefinition, IHasDescription
{
/// <summary>
/// Description of the node as represented by a nested node.
/// Description of the node
/// </summary>
public GraphQLScalarValue? Description { get; set; }
public GraphQLDescription? Description { get; set; }
}
}
7 changes: 7 additions & 0 deletions src/GraphQLParser/AST/IHasDescription.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
namespace GraphQLParser.AST
{
public interface IHasDescription
{
GraphQLDescription? Description { get; set; }
}
}
56 changes: 36 additions & 20 deletions src/GraphQLParser/ParserContext.Parse.cs
Original file line number Diff line number Diff line change
Expand Up @@ -233,10 +233,10 @@ private GraphQLDirective ParseDirective()
private GraphQLDirectiveDefinition ParseDirectiveDefinition()
{
int start = _currentToken.Start;
GraphQLScalarValue? description = null;
GraphQLDescription? description = null;
if (Peek(TokenKind.STRING))
{
description = ParseString();
description = ParseDescription();
ParseComment();
}
var comment = GetComment();
Expand Down Expand Up @@ -349,10 +349,10 @@ private GraphQLDocument ParseDocument()
private GraphQLEnumTypeDefinition ParseEnumTypeDefinition()
{
int start = _currentToken.Start;
GraphQLScalarValue? description = null;
GraphQLDescription? description = null;
if (Peek(TokenKind.STRING))
{
description = ParseString();
description = ParseDescription();
ParseComment();
}
var comment = GetComment();
Expand Down Expand Up @@ -395,10 +395,10 @@ private GraphQLValue ParseEnumValue(Token token)
private GraphQLEnumValueDefinition ParseEnumValueDefinition()
{
int start = _currentToken.Start;
GraphQLScalarValue? description = null;
GraphQLDescription? description = null;
if (Peek(TokenKind.STRING))
{
description = ParseString();
description = ParseDescription();
ParseComment();
}
var comment = GetComment();
Expand All @@ -423,10 +423,10 @@ private GraphQLEnumValueDefinition ParseEnumValueDefinition()
private GraphQLFieldDefinition ParseFieldDefinition()
{
int start = _currentToken.Start;
GraphQLScalarValue? description = null;
GraphQLDescription? description = null;
if (Peek(TokenKind.STRING))
{
description = ParseString();
description = ParseDescription();
ParseComment();
}

Expand Down Expand Up @@ -624,10 +624,10 @@ private void Throw_From_ParseFragmentName()
private GraphQLInputObjectTypeDefinition ParseInputObjectTypeDefinition()
{
int start = _currentToken.Start;
GraphQLScalarValue? description = null;
GraphQLDescription? description = null;
if (Peek(TokenKind.STRING))
{
description = ParseString();
description = ParseDescription();
ParseComment();
}
var comment = GetComment();
Expand Down Expand Up @@ -655,10 +655,10 @@ private GraphQLInputObjectTypeDefinition ParseInputObjectTypeDefinition()
private GraphQLInputValueDefinition ParseInputValueDef()
{
int start = _currentToken.Start;
GraphQLScalarValue? description = null;
GraphQLDescription? description = null;
if (Peek(TokenKind.STRING))
{
description = ParseString();
description = ParseDescription();
ParseComment();
}
var comment = GetComment();
Expand Down Expand Up @@ -706,10 +706,10 @@ private GraphQLValue ParseInt(/*bool isConstant*/)
private GraphQLInterfaceTypeDefinition ParseInterfaceTypeDefinition()
{
int start = _currentToken.Start;
GraphQLScalarValue? description = null;
GraphQLDescription? description = null;
if (Peek(TokenKind.STRING))
{
description = ParseString();
description = ParseDescription();
ParseComment();
}
var comment = GetComment();
Expand Down Expand Up @@ -964,10 +964,10 @@ private List<GraphQLObjectField> ParseObjectFields(bool isConstant)
private GraphQLObjectTypeDefinition ParseObjectTypeDefinition()
{
int start = _currentToken.Start;
GraphQLScalarValue? description = null;
GraphQLDescription? description = null;
if (Peek(TokenKind.STRING))
{
description = ParseString();
description = ParseDescription();
ParseComment();
}
var comment = GetComment();
Expand Down Expand Up @@ -1084,10 +1084,10 @@ private GraphQLOperationTypeDefinition ParseOperationTypeDefinition()
private GraphQLScalarTypeDefinition ParseScalarTypeDefinition()
{
int start = _currentToken.Start;
GraphQLScalarValue? description = null;
GraphQLDescription? description = null;
if (Peek(TokenKind.STRING))
{
description = ParseString();
description = ParseDescription();
ParseComment();
}
var comment = GetComment();
Expand Down Expand Up @@ -1173,6 +1173,22 @@ private GraphQLScalarValue ParseString(/*bool isConstant*/)
};
}

private GraphQLDescription ParseDescription()
{
var token = _currentToken;
Advance();
return _ignoreOptions == IgnoreOptions.IgnoreCommentsAndLocations
? new GraphQLDescription()
{
Value = token.Value,
}
: new GraphQLDescription()
{
Value = token.Value,
Location = GetLocation(token.Start)
};
}

private GraphQLType ParseType()
{
GraphQLType type;
Expand Down Expand Up @@ -1253,10 +1269,10 @@ private List<GraphQLNamedType> ParseUnionMembers()
private GraphQLUnionTypeDefinition ParseUnionTypeDefinition()
{
int start = _currentToken.Start;
GraphQLScalarValue? description = null;
GraphQLDescription? description = null;
if (Peek(TokenKind.STRING))
{
description = ParseString();
description = ParseDescription();
ParseComment();
}
var comment = GetComment();
Expand Down

0 comments on commit 68344cb

Please sign in to comment.