Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 14 additions & 2 deletions src/GraphQLParser/AST/ASTNode.cs
Original file line number Diff line number Diff line change
@@ -1,11 +1,23 @@
namespace GraphQLParser.AST
namespace GraphQLParser.AST
{
/// <summary>
/// Represents a single node in the GraphQL document AST (Abstract Syntax Tree).
/// </summary>
public abstract class ASTNode
{
/// <summary>
/// Kind of this node.
/// </summary>
public abstract ASTNodeKind Kind { get; }

/// <summary>
/// Location of a node within a document's original text.
/// </summary>
public GraphQLLocation Location { get; set; }

/// <summary>
/// Comments for this node if any.
/// </summary>
public GraphQLComment? Comment { get; set; }
}
}
}
77 changes: 77 additions & 0 deletions src/GraphQLParser/AST/ASTNodeKind.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
namespace GraphQLParser.AST
{
/// <summary>
/// The kind of nodes in the GraphQL document AST (Abstract Syntax Tree).
/// </summary>
public enum ASTNodeKind
{
/// <summary>
/// Named thing inside GraphQL document: operations, fields, arguments, types, directives, fragments, and variables.
/// <br/>
/// All names must follow the same grammatical form: [_A-Za-z][_0-9A-Za-z]*
/// </summary>
Name,
Document,
OperationDefinition,
VariableDefinition,
Variable,
SelectionSet,
Field,
Argument,
FragmentSpread,
InlineFragment,
FragmentDefinition,

/// <summary>
/// An integer number is specified without a decimal point or exponent (ex. 1).
/// </summary>
IntValue,

/// <summary>
/// A Float number includes either a decimal point (ex. 1.0) or an exponent (ex. 1e50) or both (ex. 6.0221413e23).
/// </summary>
FloatValue,

/// <summary>
/// Strings are sequences of characters wrapped in double‐quotes ("). (ex. "Hello World").
/// White space and other otherwise‐ignored characters are significant within a string value.
/// </summary>
StringValue,

/// <summary>
/// Boolean value. The two keywords true and false represent the two boolean values.
/// </summary>
BooleanValue,
EnumValue,
ListValue,
ObjectValue,
ObjectField,
Directive,
NamedType,
ListType,
NonNullType,
NullValue,
SchemaDefinition,
OperationTypeDefinition,
ScalarTypeDefinition,
ObjectTypeDefinition,
FieldDefinition,
InputValueDefinition,
InterfaceTypeDefinition,
UnionTypeDefinition,
EnumTypeDefinition,
EnumValueDefinition,
InputObjectTypeDefinition,
TypeExtensionDefinition,
DirectiveDefinition,

/// <summary>
/// GraphQL source documents may contain single‐line comments, starting with the # marker.
/// A comment can contain any Unicode code point except LineTerminator so a comment always
/// consists of all code points starting with the # character up to but not including the line terminator.
/// Comments behave like white space and may appear after any token, or before a line terminator,
/// and have no significance to the semantic meaning of a GraphQL Document.
/// </summary>
Comment,
}
}
51 changes: 0 additions & 51 deletions src/GraphQLParser/AST/Enums.cs

This file was deleted.

5 changes: 3 additions & 2 deletions src/GraphQLParser/AST/GraphQLArgument.cs
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
namespace GraphQLParser.AST
namespace GraphQLParser.AST
{
public class GraphQLArgument : ASTNode, INamedNode
{
/// <inheritdoc/>
public override ASTNodeKind Kind => ASTNodeKind.Argument;

public GraphQLName? Name { get; set; }

public GraphQLValue? Value { get; set; }
}
}
}
13 changes: 13 additions & 0 deletions src/GraphQLParser/AST/GraphQLComment.cs
Original file line number Diff line number Diff line change
@@ -1,12 +1,20 @@
using System.Diagnostics;

namespace GraphQLParser.AST
{
/// <inheritdoc cref="ASTNodeKind.Comment"/>
[DebuggerDisplay("{TextString}")]
public class GraphQLComment : ASTNode
{
private ROM _text;
private string? _textString;

/// <inheritdoc/>
public override ASTNodeKind Kind => ASTNodeKind.Comment;

/// <summary>
/// Comment value represented as <see cref="ROM"/>.
/// </summary>
public ROM Text
{
get => _text;
Expand All @@ -17,6 +25,11 @@ public ROM Text
}
}

/// <summary>
/// Gets comment value represented as string. The value of this property is cached and in sync with <see cref="Text"/>.
/// The first time this property is accessed, memory in the managed heap will be allocated for it.
/// In scenarios where minimum memory consumption is required, use the <see cref="Text"/> property.
/// </summary>
public string TextString => _textString ??= (string)Text;
}
}
5 changes: 3 additions & 2 deletions src/GraphQLParser/AST/GraphQLDirective.cs
Original file line number Diff line number Diff line change
@@ -1,13 +1,14 @@
using System.Collections.Generic;
using System.Collections.Generic;

namespace GraphQLParser.AST
{
public class GraphQLDirective : ASTNode, INamedNode
{
public List<GraphQLArgument>? Arguments { get; set; }

/// <inheritdoc/>
public override ASTNodeKind Kind => ASTNodeKind.Directive;

public GraphQLName? Name { get; set; }
}
}
}
1 change: 1 addition & 0 deletions src/GraphQLParser/AST/GraphQLDirectiveDefinition.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ public class GraphQLDirectiveDefinition : GraphQLTypeDefinition

public List<GraphQLInputValueDefinition>? Definitions { get; set; }

/// <inheritdoc/>
public override ASTNodeKind Kind => ASTNodeKind.DirectiveDefinition;

public List<GraphQLName>? Locations { get; set; }
Expand Down
4 changes: 4 additions & 0 deletions src/GraphQLParser/AST/GraphQLDocument.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,9 @@

namespace GraphQLParser.AST
{
/// <summary>
/// Represents the root of AST (Abstract Syntax Tree) for GraphQL document.
/// </summary>
public class GraphQLDocument : ASTNode, IDisposable
{
// In some cases, the parser is forced to change the text (escape symbols, comments),
Expand All @@ -15,6 +18,7 @@ public class GraphQLDocument : ASTNode, IDisposable

public List<GraphQLComment>? UnattachedComments { get; set; }

/// <inheritdoc/>
public override ASTNodeKind Kind => ASTNodeKind.Document;

protected virtual void Dispose(bool disposing)
Expand Down
5 changes: 3 additions & 2 deletions src/GraphQLParser/AST/GraphQLEnumTypeDefinition.cs
Original file line number Diff line number Diff line change
@@ -1,13 +1,14 @@
using System.Collections.Generic;
using System.Collections.Generic;

namespace GraphQLParser.AST
{
public class GraphQLEnumTypeDefinition : GraphQLTypeDefinition, IHasDirectivesNode
{
public List<GraphQLDirective>? Directives { get; set; }

/// <inheritdoc/>
public override ASTNodeKind Kind => ASTNodeKind.EnumTypeDefinition;

public List<GraphQLEnumValueDefinition>? Values { get; set; }
}
}
}
5 changes: 3 additions & 2 deletions src/GraphQLParser/AST/GraphQLEnumValueDefinition.cs
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
using System.Collections.Generic;
using System.Collections.Generic;

namespace GraphQLParser.AST
{
public class GraphQLEnumValueDefinition : GraphQLTypeDefinition, IHasDirectivesNode
{
public List<GraphQLDirective>? Directives { get; set; }

/// <inheritdoc/>
public override ASTNodeKind Kind => ASTNodeKind.EnumValueDefinition;
}
}
}
5 changes: 3 additions & 2 deletions src/GraphQLParser/AST/GraphQLFieldDefinition.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
using System.Collections.Generic;
using System.Collections.Generic;

namespace GraphQLParser.AST
{
Expand All @@ -8,8 +8,9 @@ public class GraphQLFieldDefinition : GraphQLTypeDefinition, IHasDirectivesNode

public List<GraphQLDirective>? Directives { get; set; }

/// <inheritdoc/>
public override ASTNodeKind Kind => ASTNodeKind.FieldDefinition;

public GraphQLType? Type { get; set; }
}
}
}
5 changes: 3 additions & 2 deletions src/GraphQLParser/AST/GraphQLFieldSelection.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
using System.Collections.Generic;
using System.Collections.Generic;

namespace GraphQLParser.AST
{
Expand All @@ -10,10 +10,11 @@ public class GraphQLFieldSelection : ASTNode, IHasDirectivesNode, INamedNode

public List<GraphQLDirective>? Directives { get; set; }

/// <inheritdoc/>
public override ASTNodeKind Kind => ASTNodeKind.Field;

public GraphQLName? Name { get; set; }

public GraphQLSelectionSet? SelectionSet { get; set; }
}
}
}
5 changes: 3 additions & 2 deletions src/GraphQLParser/AST/GraphQLFragmentDefinition.cs
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
namespace GraphQLParser.AST
namespace GraphQLParser.AST
{
public class GraphQLFragmentDefinition : GraphQLInlineFragment, INamedNode
{
/// <inheritdoc/>
public override ASTNodeKind Kind => ASTNodeKind.FragmentDefinition;

public GraphQLName? Name { get; set; }
}
}
}
5 changes: 3 additions & 2 deletions src/GraphQLParser/AST/GraphQLFragmentSpread.cs
Original file line number Diff line number Diff line change
@@ -1,13 +1,14 @@
using System.Collections.Generic;
using System.Collections.Generic;

namespace GraphQLParser.AST
{
public class GraphQLFragmentSpread : ASTNode, IHasDirectivesNode, INamedNode
{
public List<GraphQLDirective>? Directives { get; set; }

/// <inheritdoc/>
public override ASTNodeKind Kind => ASTNodeKind.FragmentSpread;

public GraphQLName? Name { get; set; }
}
}
}
1 change: 1 addition & 0 deletions src/GraphQLParser/AST/GraphQLInlineFragment.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ public class GraphQLInlineFragment : ASTNode, IHasDirectivesNode
{
public List<GraphQLDirective>? Directives { get; set; }

/// <inheritdoc/>
public override ASTNodeKind Kind => ASTNodeKind.InlineFragment;

public GraphQLSelectionSet? SelectionSet { get; set; }
Expand Down
1 change: 1 addition & 0 deletions src/GraphQLParser/AST/GraphQLInputObjectTypeDefinition.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ public class GraphQLInputObjectTypeDefinition : GraphQLTypeDefinition, IHasDirec

public List<GraphQLInputValueDefinition>? Fields { get; set; }

/// <inheritdoc/>
public override ASTNodeKind Kind => ASTNodeKind.InputObjectTypeDefinition;
}
}
5 changes: 3 additions & 2 deletions src/GraphQLParser/AST/GraphQLInputValueDefinition.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
using System.Collections.Generic;
using System.Collections.Generic;

namespace GraphQLParser.AST
{
Expand All @@ -8,8 +8,9 @@ public class GraphQLInputValueDefinition : GraphQLTypeDefinition, IHasDirectives

public List<GraphQLDirective>? Directives { get; set; }

/// <inheritdoc/>
public override ASTNodeKind Kind => ASTNodeKind.InputValueDefinition;

public GraphQLType? Type { get; set; }
}
}
}
Loading