diff --git a/src/GraphQLParser/AST/ASTNode.cs b/src/GraphQLParser/AST/ASTNode.cs
index 47ad9999..aea2916c 100644
--- a/src/GraphQLParser/AST/ASTNode.cs
+++ b/src/GraphQLParser/AST/ASTNode.cs
@@ -1,11 +1,23 @@
-namespace GraphQLParser.AST
+namespace GraphQLParser.AST
{
+ ///
+ /// Represents a single node in the GraphQL document AST (Abstract Syntax Tree).
+ ///
public abstract class ASTNode
{
+ ///
+ /// Kind of this node.
+ ///
public abstract ASTNodeKind Kind { get; }
+ ///
+ /// Location of a node within a document's original text.
+ ///
public GraphQLLocation Location { get; set; }
+ ///
+ /// Comments for this node if any.
+ ///
public GraphQLComment? Comment { get; set; }
}
-}
\ No newline at end of file
+}
diff --git a/src/GraphQLParser/AST/ASTNodeKind.cs b/src/GraphQLParser/AST/ASTNodeKind.cs
new file mode 100644
index 00000000..6629312f
--- /dev/null
+++ b/src/GraphQLParser/AST/ASTNodeKind.cs
@@ -0,0 +1,77 @@
+namespace GraphQLParser.AST
+{
+ ///
+ /// The kind of nodes in the GraphQL document AST (Abstract Syntax Tree).
+ ///
+ public enum ASTNodeKind
+ {
+ ///
+ /// Named thing inside GraphQL document: operations, fields, arguments, types, directives, fragments, and variables.
+ ///
+ /// All names must follow the same grammatical form: [_A-Za-z][_0-9A-Za-z]*
+ ///
+ Name,
+ Document,
+ OperationDefinition,
+ VariableDefinition,
+ Variable,
+ SelectionSet,
+ Field,
+ Argument,
+ FragmentSpread,
+ InlineFragment,
+ FragmentDefinition,
+
+ ///
+ /// An integer number is specified without a decimal point or exponent (ex. 1).
+ ///
+ IntValue,
+
+ ///
+ /// A Float number includes either a decimal point (ex. 1.0) or an exponent (ex. 1e50) or both (ex. 6.0221413e23).
+ ///
+ FloatValue,
+
+ ///
+ /// 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.
+ ///
+ StringValue,
+
+ ///
+ /// Boolean value. The two keywords true and false represent the two boolean values.
+ ///
+ BooleanValue,
+ EnumValue,
+ ListValue,
+ ObjectValue,
+ ObjectField,
+ Directive,
+ NamedType,
+ ListType,
+ NonNullType,
+ NullValue,
+ SchemaDefinition,
+ OperationTypeDefinition,
+ ScalarTypeDefinition,
+ ObjectTypeDefinition,
+ FieldDefinition,
+ InputValueDefinition,
+ InterfaceTypeDefinition,
+ UnionTypeDefinition,
+ EnumTypeDefinition,
+ EnumValueDefinition,
+ InputObjectTypeDefinition,
+ TypeExtensionDefinition,
+ DirectiveDefinition,
+
+ ///
+ /// 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.
+ ///
+ Comment,
+ }
+}
diff --git a/src/GraphQLParser/AST/Enums.cs b/src/GraphQLParser/AST/Enums.cs
deleted file mode 100644
index 55e56f9d..00000000
--- a/src/GraphQLParser/AST/Enums.cs
+++ /dev/null
@@ -1,51 +0,0 @@
-namespace GraphQLParser.AST
-{
- public enum ASTNodeKind
- {
- Name,
- Document,
- OperationDefinition,
- VariableDefinition,
- Variable,
- SelectionSet,
- Field,
- Argument,
- FragmentSpread,
- InlineFragment,
- FragmentDefinition,
- IntValue,
- FloatValue,
- StringValue,
- BooleanValue,
- EnumValue,
- ListValue,
- ObjectValue,
- ObjectField,
- Directive,
- NamedType,
- ListType,
- NonNullType,
- NullValue,
- SchemaDefinition,
- OperationTypeDefinition,
- ScalarTypeDefinition,
- ObjectTypeDefinition,
- FieldDefinition,
- InputValueDefinition,
- InterfaceTypeDefinition,
- UnionTypeDefinition,
- EnumTypeDefinition,
- EnumValueDefinition,
- InputObjectTypeDefinition,
- TypeExtensionDefinition,
- DirectiveDefinition,
- Comment,
- }
-
- public enum OperationType
- {
- Query,
- Mutation,
- Subscription
- }
-}
\ No newline at end of file
diff --git a/src/GraphQLParser/AST/GraphQLArgument.cs b/src/GraphQLParser/AST/GraphQLArgument.cs
index 5687ab40..8a83ebd0 100644
--- a/src/GraphQLParser/AST/GraphQLArgument.cs
+++ b/src/GraphQLParser/AST/GraphQLArgument.cs
@@ -1,11 +1,12 @@
-namespace GraphQLParser.AST
+namespace GraphQLParser.AST
{
public class GraphQLArgument : ASTNode, INamedNode
{
+ ///
public override ASTNodeKind Kind => ASTNodeKind.Argument;
public GraphQLName? Name { get; set; }
public GraphQLValue? Value { get; set; }
}
-}
\ No newline at end of file
+}
diff --git a/src/GraphQLParser/AST/GraphQLComment.cs b/src/GraphQLParser/AST/GraphQLComment.cs
index debadbb5..b6402a59 100644
--- a/src/GraphQLParser/AST/GraphQLComment.cs
+++ b/src/GraphQLParser/AST/GraphQLComment.cs
@@ -1,12 +1,20 @@
+using System.Diagnostics;
+
namespace GraphQLParser.AST
{
+ ///
+ [DebuggerDisplay("{TextString}")]
public class GraphQLComment : ASTNode
{
private ROM _text;
private string? _textString;
+ ///
public override ASTNodeKind Kind => ASTNodeKind.Comment;
+ ///
+ /// Comment value represented as .
+ ///
public ROM Text
{
get => _text;
@@ -17,6 +25,11 @@ public ROM Text
}
}
+ ///
+ /// Gets comment value represented as string. The value of this property is cached and in sync with .
+ /// 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 property.
+ ///
public string TextString => _textString ??= (string)Text;
}
}
diff --git a/src/GraphQLParser/AST/GraphQLDirective.cs b/src/GraphQLParser/AST/GraphQLDirective.cs
index 62381fe5..5a5d388c 100644
--- a/src/GraphQLParser/AST/GraphQLDirective.cs
+++ b/src/GraphQLParser/AST/GraphQLDirective.cs
@@ -1,4 +1,4 @@
-using System.Collections.Generic;
+using System.Collections.Generic;
namespace GraphQLParser.AST
{
@@ -6,8 +6,9 @@ public class GraphQLDirective : ASTNode, INamedNode
{
public List? Arguments { get; set; }
+ ///
public override ASTNodeKind Kind => ASTNodeKind.Directive;
public GraphQLName? Name { get; set; }
}
-}
\ No newline at end of file
+}
diff --git a/src/GraphQLParser/AST/GraphQLDirectiveDefinition.cs b/src/GraphQLParser/AST/GraphQLDirectiveDefinition.cs
index 732651fb..0163d1ad 100644
--- a/src/GraphQLParser/AST/GraphQLDirectiveDefinition.cs
+++ b/src/GraphQLParser/AST/GraphQLDirectiveDefinition.cs
@@ -8,6 +8,7 @@ public class GraphQLDirectiveDefinition : GraphQLTypeDefinition
public List? Definitions { get; set; }
+ ///
public override ASTNodeKind Kind => ASTNodeKind.DirectiveDefinition;
public List? Locations { get; set; }
diff --git a/src/GraphQLParser/AST/GraphQLDocument.cs b/src/GraphQLParser/AST/GraphQLDocument.cs
index 67b14429..e6caca1d 100644
--- a/src/GraphQLParser/AST/GraphQLDocument.cs
+++ b/src/GraphQLParser/AST/GraphQLDocument.cs
@@ -4,6 +4,9 @@
namespace GraphQLParser.AST
{
+ ///
+ /// Represents the root of AST (Abstract Syntax Tree) for GraphQL document.
+ ///
public class GraphQLDocument : ASTNode, IDisposable
{
// In some cases, the parser is forced to change the text (escape symbols, comments),
@@ -15,6 +18,7 @@ public class GraphQLDocument : ASTNode, IDisposable
public List? UnattachedComments { get; set; }
+ ///
public override ASTNodeKind Kind => ASTNodeKind.Document;
protected virtual void Dispose(bool disposing)
diff --git a/src/GraphQLParser/AST/GraphQLEnumTypeDefinition.cs b/src/GraphQLParser/AST/GraphQLEnumTypeDefinition.cs
index 7d32245a..181bf2b5 100644
--- a/src/GraphQLParser/AST/GraphQLEnumTypeDefinition.cs
+++ b/src/GraphQLParser/AST/GraphQLEnumTypeDefinition.cs
@@ -1,4 +1,4 @@
-using System.Collections.Generic;
+using System.Collections.Generic;
namespace GraphQLParser.AST
{
@@ -6,8 +6,9 @@ public class GraphQLEnumTypeDefinition : GraphQLTypeDefinition, IHasDirectivesNo
{
public List? Directives { get; set; }
+ ///
public override ASTNodeKind Kind => ASTNodeKind.EnumTypeDefinition;
public List? Values { get; set; }
}
-}
\ No newline at end of file
+}
diff --git a/src/GraphQLParser/AST/GraphQLEnumValueDefinition.cs b/src/GraphQLParser/AST/GraphQLEnumValueDefinition.cs
index 7d3a143b..48f96cd4 100644
--- a/src/GraphQLParser/AST/GraphQLEnumValueDefinition.cs
+++ b/src/GraphQLParser/AST/GraphQLEnumValueDefinition.cs
@@ -1,4 +1,4 @@
-using System.Collections.Generic;
+using System.Collections.Generic;
namespace GraphQLParser.AST
{
@@ -6,6 +6,7 @@ public class GraphQLEnumValueDefinition : GraphQLTypeDefinition, IHasDirectivesN
{
public List? Directives { get; set; }
+ ///
public override ASTNodeKind Kind => ASTNodeKind.EnumValueDefinition;
}
-}
\ No newline at end of file
+}
diff --git a/src/GraphQLParser/AST/GraphQLFieldDefinition.cs b/src/GraphQLParser/AST/GraphQLFieldDefinition.cs
index 81c48602..bcfc46eb 100644
--- a/src/GraphQLParser/AST/GraphQLFieldDefinition.cs
+++ b/src/GraphQLParser/AST/GraphQLFieldDefinition.cs
@@ -1,4 +1,4 @@
-using System.Collections.Generic;
+using System.Collections.Generic;
namespace GraphQLParser.AST
{
@@ -8,8 +8,9 @@ public class GraphQLFieldDefinition : GraphQLTypeDefinition, IHasDirectivesNode
public List? Directives { get; set; }
+ ///
public override ASTNodeKind Kind => ASTNodeKind.FieldDefinition;
public GraphQLType? Type { get; set; }
}
-}
\ No newline at end of file
+}
diff --git a/src/GraphQLParser/AST/GraphQLFieldSelection.cs b/src/GraphQLParser/AST/GraphQLFieldSelection.cs
index 7fa8b4c5..7092762a 100644
--- a/src/GraphQLParser/AST/GraphQLFieldSelection.cs
+++ b/src/GraphQLParser/AST/GraphQLFieldSelection.cs
@@ -1,4 +1,4 @@
-using System.Collections.Generic;
+using System.Collections.Generic;
namespace GraphQLParser.AST
{
@@ -10,10 +10,11 @@ public class GraphQLFieldSelection : ASTNode, IHasDirectivesNode, INamedNode
public List? Directives { get; set; }
+ ///
public override ASTNodeKind Kind => ASTNodeKind.Field;
public GraphQLName? Name { get; set; }
public GraphQLSelectionSet? SelectionSet { get; set; }
}
-}
\ No newline at end of file
+}
diff --git a/src/GraphQLParser/AST/GraphQLFragmentDefinition.cs b/src/GraphQLParser/AST/GraphQLFragmentDefinition.cs
index 7fbe2fa3..0a551600 100644
--- a/src/GraphQLParser/AST/GraphQLFragmentDefinition.cs
+++ b/src/GraphQLParser/AST/GraphQLFragmentDefinition.cs
@@ -1,9 +1,10 @@
-namespace GraphQLParser.AST
+namespace GraphQLParser.AST
{
public class GraphQLFragmentDefinition : GraphQLInlineFragment, INamedNode
{
+ ///
public override ASTNodeKind Kind => ASTNodeKind.FragmentDefinition;
public GraphQLName? Name { get; set; }
}
-}
\ No newline at end of file
+}
diff --git a/src/GraphQLParser/AST/GraphQLFragmentSpread.cs b/src/GraphQLParser/AST/GraphQLFragmentSpread.cs
index b3d1a543..1c70ed68 100644
--- a/src/GraphQLParser/AST/GraphQLFragmentSpread.cs
+++ b/src/GraphQLParser/AST/GraphQLFragmentSpread.cs
@@ -1,4 +1,4 @@
-using System.Collections.Generic;
+using System.Collections.Generic;
namespace GraphQLParser.AST
{
@@ -6,8 +6,9 @@ public class GraphQLFragmentSpread : ASTNode, IHasDirectivesNode, INamedNode
{
public List? Directives { get; set; }
+ ///
public override ASTNodeKind Kind => ASTNodeKind.FragmentSpread;
public GraphQLName? Name { get; set; }
}
-}
\ No newline at end of file
+}
diff --git a/src/GraphQLParser/AST/GraphQLInlineFragment.cs b/src/GraphQLParser/AST/GraphQLInlineFragment.cs
index 1755ac0e..6086ebd1 100644
--- a/src/GraphQLParser/AST/GraphQLInlineFragment.cs
+++ b/src/GraphQLParser/AST/GraphQLInlineFragment.cs
@@ -6,6 +6,7 @@ public class GraphQLInlineFragment : ASTNode, IHasDirectivesNode
{
public List? Directives { get; set; }
+ ///
public override ASTNodeKind Kind => ASTNodeKind.InlineFragment;
public GraphQLSelectionSet? SelectionSet { get; set; }
diff --git a/src/GraphQLParser/AST/GraphQLInputObjectTypeDefinition.cs b/src/GraphQLParser/AST/GraphQLInputObjectTypeDefinition.cs
index 7cf7cc9a..37f9117e 100644
--- a/src/GraphQLParser/AST/GraphQLInputObjectTypeDefinition.cs
+++ b/src/GraphQLParser/AST/GraphQLInputObjectTypeDefinition.cs
@@ -8,6 +8,7 @@ public class GraphQLInputObjectTypeDefinition : GraphQLTypeDefinition, IHasDirec
public List? Fields { get; set; }
+ ///
public override ASTNodeKind Kind => ASTNodeKind.InputObjectTypeDefinition;
}
}
diff --git a/src/GraphQLParser/AST/GraphQLInputValueDefinition.cs b/src/GraphQLParser/AST/GraphQLInputValueDefinition.cs
index ed6098ed..d2cf3f7e 100644
--- a/src/GraphQLParser/AST/GraphQLInputValueDefinition.cs
+++ b/src/GraphQLParser/AST/GraphQLInputValueDefinition.cs
@@ -1,4 +1,4 @@
-using System.Collections.Generic;
+using System.Collections.Generic;
namespace GraphQLParser.AST
{
@@ -8,8 +8,9 @@ public class GraphQLInputValueDefinition : GraphQLTypeDefinition, IHasDirectives
public List? Directives { get; set; }
+ ///
public override ASTNodeKind Kind => ASTNodeKind.InputValueDefinition;
public GraphQLType? Type { get; set; }
}
-}
\ No newline at end of file
+}
diff --git a/src/GraphQLParser/AST/GraphQLInterfaceTypeDefinition.cs b/src/GraphQLParser/AST/GraphQLInterfaceTypeDefinition.cs
index deb3feaf..db4cb9a4 100644
--- a/src/GraphQLParser/AST/GraphQLInterfaceTypeDefinition.cs
+++ b/src/GraphQLParser/AST/GraphQLInterfaceTypeDefinition.cs
@@ -1,4 +1,4 @@
-using System.Collections.Generic;
+using System.Collections.Generic;
namespace GraphQLParser.AST
{
@@ -8,6 +8,7 @@ public class GraphQLInterfaceTypeDefinition : GraphQLTypeDefinition, IHasDirecti
public List? Fields { get; set; }
+ ///
public override ASTNodeKind Kind => ASTNodeKind.InterfaceTypeDefinition;
}
-}
\ No newline at end of file
+}
diff --git a/src/GraphQLParser/AST/GraphQLListType.cs b/src/GraphQLParser/AST/GraphQLListType.cs
index bca90daa..fcb9687b 100644
--- a/src/GraphQLParser/AST/GraphQLListType.cs
+++ b/src/GraphQLParser/AST/GraphQLListType.cs
@@ -2,6 +2,7 @@ namespace GraphQLParser.AST
{
public class GraphQLListType : GraphQLType
{
+ ///
public override ASTNodeKind Kind => ASTNodeKind.ListType;
public GraphQLType? Type { get; set; }
diff --git a/src/GraphQLParser/AST/GraphQLListValue.cs b/src/GraphQLParser/AST/GraphQLListValue.cs
index b4b95d5c..8e6e7b2f 100644
--- a/src/GraphQLParser/AST/GraphQLListValue.cs
+++ b/src/GraphQLParser/AST/GraphQLListValue.cs
@@ -13,6 +13,7 @@ public GraphQLListValue(ASTNodeKind kind)
public ROM AstValue { get; set; }
+ ///
public override ASTNodeKind Kind => _kind;
public List? Values { get; set; }
diff --git a/src/GraphQLParser/AST/GraphQLLocation.cs b/src/GraphQLParser/AST/GraphQLLocation.cs
index 03aa0f1d..d4c6b4c6 100644
--- a/src/GraphQLParser/AST/GraphQLLocation.cs
+++ b/src/GraphQLParser/AST/GraphQLLocation.cs
@@ -4,7 +4,7 @@
namespace GraphQLParser.AST
{
///
- /// Provides information regarding the location of a node within a document's original query text.
+ /// Provides information regarding the location of a node within a document's original text.
///
[DebuggerDisplay("(Start={Start}, End={End})")]
public readonly struct GraphQLLocation : IEquatable
diff --git a/src/GraphQLParser/AST/GraphQLName.cs b/src/GraphQLParser/AST/GraphQLName.cs
index 35f87691..31463dad 100644
--- a/src/GraphQLParser/AST/GraphQLName.cs
+++ b/src/GraphQLParser/AST/GraphQLName.cs
@@ -2,14 +2,19 @@
namespace GraphQLParser.AST
{
- [DebuggerDisplay("{Value}")]
+ ///
+ [DebuggerDisplay("{ValueString}")]
public class GraphQLName : ASTNode
{
private ROM _value;
private string? _valueString;
+ ///
public override ASTNodeKind Kind => ASTNodeKind.Name;
+ ///
+ /// Name value represented as .
+ ///
public ROM Value
{
get => _value;
@@ -20,6 +25,11 @@ public ROM Value
}
}
+ ///
+ /// Gets name value represented as string. The value of this property is cached and in sync with .
+ /// 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 property.
+ ///
public string ValueString => _valueString ??= (string)Value;
}
}
diff --git a/src/GraphQLParser/AST/GraphQLNamedType.cs b/src/GraphQLParser/AST/GraphQLNamedType.cs
index a2377885..ed3543f4 100644
--- a/src/GraphQLParser/AST/GraphQLNamedType.cs
+++ b/src/GraphQLParser/AST/GraphQLNamedType.cs
@@ -2,6 +2,7 @@ namespace GraphQLParser.AST
{
public class GraphQLNamedType : GraphQLType, INamedNode
{
+ ///
public override ASTNodeKind Kind => ASTNodeKind.NamedType;
public GraphQLName? Name { get; set; }
diff --git a/src/GraphQLParser/AST/GraphQLNonNullType.cs b/src/GraphQLParser/AST/GraphQLNonNullType.cs
index 10f42615..450040f0 100644
--- a/src/GraphQLParser/AST/GraphQLNonNullType.cs
+++ b/src/GraphQLParser/AST/GraphQLNonNullType.cs
@@ -2,6 +2,7 @@ namespace GraphQLParser.AST
{
public class GraphQLNonNullType : GraphQLType
{
+ ///
public override ASTNodeKind Kind => ASTNodeKind.NonNullType;
public GraphQLType? Type { get; set; }
diff --git a/src/GraphQLParser/AST/GraphQLObjectField.cs b/src/GraphQLParser/AST/GraphQLObjectField.cs
index 7d6f5c4b..0ffd2662 100644
--- a/src/GraphQLParser/AST/GraphQLObjectField.cs
+++ b/src/GraphQLParser/AST/GraphQLObjectField.cs
@@ -1,11 +1,12 @@
-namespace GraphQLParser.AST
+namespace GraphQLParser.AST
{
public class GraphQLObjectField : ASTNode, INamedNode
{
+ ///
public override ASTNodeKind Kind => ASTNodeKind.ObjectField;
public GraphQLName? Name { get; set; }
public GraphQLValue? Value { get; set; }
}
-}
\ No newline at end of file
+}
diff --git a/src/GraphQLParser/AST/GraphQLObjectTypeDefinition.cs b/src/GraphQLParser/AST/GraphQLObjectTypeDefinition.cs
index 243c798a..15c497ea 100644
--- a/src/GraphQLParser/AST/GraphQLObjectTypeDefinition.cs
+++ b/src/GraphQLParser/AST/GraphQLObjectTypeDefinition.cs
@@ -1,4 +1,4 @@
-using System.Collections.Generic;
+using System.Collections.Generic;
namespace GraphQLParser.AST
{
@@ -10,6 +10,7 @@ public class GraphQLObjectTypeDefinition : GraphQLTypeDefinition, IHasDirectives
public List? Interfaces { get; set; }
+ ///
public override ASTNodeKind Kind => ASTNodeKind.ObjectTypeDefinition;
}
-}
\ No newline at end of file
+}
diff --git a/src/GraphQLParser/AST/GraphQLObjectValue.cs b/src/GraphQLParser/AST/GraphQLObjectValue.cs
index cc555802..08d09f92 100644
--- a/src/GraphQLParser/AST/GraphQLObjectValue.cs
+++ b/src/GraphQLParser/AST/GraphQLObjectValue.cs
@@ -1,4 +1,4 @@
-using System.Collections.Generic;
+using System.Collections.Generic;
namespace GraphQLParser.AST
{
@@ -6,6 +6,7 @@ public class GraphQLObjectValue : GraphQLValue
{
public List? Fields { get; set; }
+ ///
public override ASTNodeKind Kind => ASTNodeKind.ObjectValue;
}
-}
\ No newline at end of file
+}
diff --git a/src/GraphQLParser/AST/GraphQLOperationDefinition.cs b/src/GraphQLParser/AST/GraphQLOperationDefinition.cs
index 799fbd40..7f3f9009 100644
--- a/src/GraphQLParser/AST/GraphQLOperationDefinition.cs
+++ b/src/GraphQLParser/AST/GraphQLOperationDefinition.cs
@@ -1,4 +1,4 @@
-using System.Collections.Generic;
+using System.Collections.Generic;
namespace GraphQLParser.AST
{
@@ -6,6 +6,7 @@ public class GraphQLOperationDefinition : ASTNode, IHasDirectivesNode, INamedNod
{
public List? Directives { get; set; }
+ ///
public override ASTNodeKind Kind => ASTNodeKind.OperationDefinition;
public GraphQLName? Name { get; set; }
@@ -16,4 +17,4 @@ public class GraphQLOperationDefinition : ASTNode, IHasDirectivesNode, INamedNod
public List? VariableDefinitions { get; set; }
}
-}
\ No newline at end of file
+}
diff --git a/src/GraphQLParser/AST/GraphQLOperationTypeDefinition.cs b/src/GraphQLParser/AST/GraphQLOperationTypeDefinition.cs
index d11fbd04..569dd2aa 100644
--- a/src/GraphQLParser/AST/GraphQLOperationTypeDefinition.cs
+++ b/src/GraphQLParser/AST/GraphQLOperationTypeDefinition.cs
@@ -1,11 +1,12 @@
-namespace GraphQLParser.AST
+namespace GraphQLParser.AST
{
public class GraphQLOperationTypeDefinition : ASTNode
{
+ ///
public override ASTNodeKind Kind => ASTNodeKind.OperationTypeDefinition;
public OperationType Operation { get; set; }
public GraphQLNamedType? Type { get; set; }
}
-}
\ No newline at end of file
+}
diff --git a/src/GraphQLParser/AST/GraphQLScalarTypeDefinition.cs b/src/GraphQLParser/AST/GraphQLScalarTypeDefinition.cs
index ae882b53..707978f7 100644
--- a/src/GraphQLParser/AST/GraphQLScalarTypeDefinition.cs
+++ b/src/GraphQLParser/AST/GraphQLScalarTypeDefinition.cs
@@ -1,4 +1,4 @@
-using System.Collections.Generic;
+using System.Collections.Generic;
namespace GraphQLParser.AST
{
@@ -6,6 +6,7 @@ public class GraphQLScalarTypeDefinition : GraphQLTypeDefinition, IHasDirectives
{
public List? Directives { get; set; }
+ ///
public override ASTNodeKind Kind => ASTNodeKind.ScalarTypeDefinition;
}
-}
\ No newline at end of file
+}
diff --git a/src/GraphQLParser/AST/GraphQLScalarValue.cs b/src/GraphQLParser/AST/GraphQLScalarValue.cs
index eb9b6d06..87844aad 100644
--- a/src/GraphQLParser/AST/GraphQLScalarValue.cs
+++ b/src/GraphQLParser/AST/GraphQLScalarValue.cs
@@ -1,18 +1,46 @@
+using System.Diagnostics;
+
namespace GraphQLParser.AST
{
+ ///
+ /// Scalar nodes represent primitive leaf values in a GraphQL document.
+ ///
+ /// There are 6 kinds of scalar nodes:
+ ///
+ /// String
+ ///
+ /// Boolean
+ ///
+ /// Int
+ ///
+ /// Float
+ ///
+ /// Enumeration
+ ///
+ /// Null
+ ///
+ [DebuggerDisplay("{ValueString}")]
public class GraphQLScalarValue : GraphQLValue
{
private readonly ASTNodeKind _kind;
private ROM _value;
private string? _valueString;
+ ///
+ /// Creates scalar node with the specified kind.
+ ///
+ /// One of six kinds of scalar nodes.
public GraphQLScalarValue(ASTNodeKind kind)
{
_kind = kind;
}
+ ///
public override ASTNodeKind Kind => _kind;
+ ///
+ /// Scalar value represented as .
+ ///
public ROM Value
{
get => _value;
@@ -23,8 +51,14 @@ public ROM Value
}
}
+ ///
+ /// Gets scalar value represented as string. The value of this property is cached and in sync with .
+ /// 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 property.
+ ///
public string ValueString => _valueString ??= (string)Value;
+ ///
public override string? ToString() => Kind == ASTNodeKind.StringValue ? $"\"{Value}\"" : Value.ToString();
}
}
diff --git a/src/GraphQLParser/AST/GraphQLSchemaDefinition.cs b/src/GraphQLParser/AST/GraphQLSchemaDefinition.cs
index fbdd42e2..e723d0c7 100644
--- a/src/GraphQLParser/AST/GraphQLSchemaDefinition.cs
+++ b/src/GraphQLParser/AST/GraphQLSchemaDefinition.cs
@@ -1,4 +1,4 @@
-using System.Collections.Generic;
+using System.Collections.Generic;
namespace GraphQLParser.AST
{
@@ -6,8 +6,9 @@ public class GraphQLSchemaDefinition : ASTNode, IHasDirectivesNode
{
public List? Directives { get; set; }
+ ///
public override ASTNodeKind Kind => ASTNodeKind.SchemaDefinition;
public List? OperationTypes { get; set; }
}
-}
\ No newline at end of file
+}
diff --git a/src/GraphQLParser/AST/GraphQLSelectionSet.cs b/src/GraphQLParser/AST/GraphQLSelectionSet.cs
index 8dfe77a1..bb90bbd9 100644
--- a/src/GraphQLParser/AST/GraphQLSelectionSet.cs
+++ b/src/GraphQLParser/AST/GraphQLSelectionSet.cs
@@ -1,11 +1,12 @@
-using System.Collections.Generic;
+using System.Collections.Generic;
namespace GraphQLParser.AST
{
public class GraphQLSelectionSet : ASTNode
{
+ ///
public override ASTNodeKind Kind => ASTNodeKind.SelectionSet;
public List? Selections { get; set; }
}
-}
\ No newline at end of file
+}
diff --git a/src/GraphQLParser/AST/GraphQLTypeExtensionDefinition.cs b/src/GraphQLParser/AST/GraphQLTypeExtensionDefinition.cs
index 6aa07e30..63cccd4f 100644
--- a/src/GraphQLParser/AST/GraphQLTypeExtensionDefinition.cs
+++ b/src/GraphQLParser/AST/GraphQLTypeExtensionDefinition.cs
@@ -1,9 +1,10 @@
-namespace GraphQLParser.AST
+namespace GraphQLParser.AST
{
public class GraphQLTypeExtensionDefinition : GraphQLTypeDefinition
{
public GraphQLObjectTypeDefinition? Definition { get; set; }
+ ///
public override ASTNodeKind Kind => ASTNodeKind.TypeExtensionDefinition;
}
-}
\ No newline at end of file
+}
diff --git a/src/GraphQLParser/AST/GraphQLUnionTypeDefinition.cs b/src/GraphQLParser/AST/GraphQLUnionTypeDefinition.cs
index 152c3555..3325f6d8 100644
--- a/src/GraphQLParser/AST/GraphQLUnionTypeDefinition.cs
+++ b/src/GraphQLParser/AST/GraphQLUnionTypeDefinition.cs
@@ -1,4 +1,4 @@
-using System.Collections.Generic;
+using System.Collections.Generic;
namespace GraphQLParser.AST
{
@@ -6,8 +6,9 @@ public class GraphQLUnionTypeDefinition : GraphQLTypeDefinition, IHasDirectivesN
{
public List? Directives { get; set; }
+ ///
public override ASTNodeKind Kind => ASTNodeKind.UnionTypeDefinition;
public List? Types { get; set; }
}
-}
\ No newline at end of file
+}
diff --git a/src/GraphQLParser/AST/GraphQLVariable.cs b/src/GraphQLParser/AST/GraphQLVariable.cs
index 39e53d7d..01259bed 100644
--- a/src/GraphQLParser/AST/GraphQLVariable.cs
+++ b/src/GraphQLParser/AST/GraphQLVariable.cs
@@ -1,9 +1,10 @@
-namespace GraphQLParser.AST
+namespace GraphQLParser.AST
{
public class GraphQLVariable : GraphQLValue, INamedNode
{
+ ///
public override ASTNodeKind Kind => ASTNodeKind.Variable;
public GraphQLName? Name { get; set; }
}
-}
\ No newline at end of file
+}
diff --git a/src/GraphQLParser/AST/GraphQLVariableDefinition.cs b/src/GraphQLParser/AST/GraphQLVariableDefinition.cs
index ded9321a..3a489465 100644
--- a/src/GraphQLParser/AST/GraphQLVariableDefinition.cs
+++ b/src/GraphQLParser/AST/GraphQLVariableDefinition.cs
@@ -1,13 +1,14 @@
-namespace GraphQLParser.AST
+namespace GraphQLParser.AST
{
public class GraphQLVariableDefinition : ASTNode
{
public object? DefaultValue { get; set; }
+ ///
public override ASTNodeKind Kind => ASTNodeKind.VariableDefinition;
public GraphQLType? Type { get; set; }
public GraphQLVariable? Variable { get; set; }
}
-}
\ No newline at end of file
+}
diff --git a/src/GraphQLParser/AST/OperationType.cs b/src/GraphQLParser/AST/OperationType.cs
new file mode 100644
index 00000000..dbd48623
--- /dev/null
+++ b/src/GraphQLParser/AST/OperationType.cs
@@ -0,0 +1,23 @@
+namespace GraphQLParser.AST
+{
+ ///
+ /// An enumeration of the GraphQL operation types.
+ ///
+ public enum OperationType
+ {
+ ///
+ /// A query operation.
+ ///
+ Query,
+
+ ///
+ /// A mutation operation.
+ ///
+ Mutation,
+
+ ///
+ /// A subscription operation.
+ ///
+ Subscription
+ }
+}
diff --git a/src/GraphQLParser/Exceptions/GraphQLSyntaxErrorException.cs b/src/GraphQLParser/Exceptions/GraphQLSyntaxErrorException.cs
index 9c63ccfe..8066a779 100644
--- a/src/GraphQLParser/Exceptions/GraphQLSyntaxErrorException.cs
+++ b/src/GraphQLParser/Exceptions/GraphQLSyntaxErrorException.cs
@@ -4,14 +4,29 @@
namespace GraphQLParser.Exceptions
{
+ ///
+ /// An exception representing a GraphQL document syntax error.
+ ///
public class GraphQLSyntaxErrorException : Exception
{
+ ///
+ /// Error description.
+ ///
public string Description { get; private set; }
+ ///
+ /// The line number on which the symbol that caused the error is located.
+ ///
public int Line { get; private set; }
+ ///
+ /// The column number on which the symbol that caused the error is located.
+ ///
public int Column { get; private set; }
+ ///
+ /// Initializes a new instance with the specified parameters.
+ ///
public GraphQLSyntaxErrorException(string description, ROM source, int location)
: this(description, source, new Location(source, location))
{
diff --git a/src/GraphQLParser/Lexer.cs b/src/GraphQLParser/Lexer.cs
index 199db7d2..78b3fc79 100644
--- a/src/GraphQLParser/Lexer.cs
+++ b/src/GraphQLParser/Lexer.cs
@@ -1,7 +1,16 @@
namespace GraphQLParser
{
+ ///
+ /// Lexer for GraphQL syntax.
+ ///
public static class Lexer
{
+ ///
+ /// Generates token based on input text.
+ ///
+ /// Input data as a sequence of characters.
+ /// The index in the source at which to start searching the token.
+ /// Found token.
public static Token Lex(ROM source, int start = 0) => new LexerContext(source, start).GetToken();
}
}
diff --git a/src/GraphQLParser/Location.cs b/src/GraphQLParser/Location.cs
index 27a4dfb5..c504553d 100644
--- a/src/GraphQLParser/Location.cs
+++ b/src/GraphQLParser/Location.cs
@@ -2,10 +2,18 @@
namespace GraphQLParser
{
+ ///
+ /// Provides the ability to decode a linear character position into a line and column number.
+ ///
public readonly struct Location
{
private static readonly Regex _lineRegex = new Regex("\r\n|[\n\r]", RegexOptions.ECMAScript);
+ ///
+ /// Creates location from a given sequence of characters and a linear character position.
+ ///
+ /// Input data as a sequence of characters.
+ /// Linear character position in the .
public Location(ROM source, int position)
{
Line = 1;
@@ -25,8 +33,14 @@ public Location(ROM source, int position)
}
}
+ ///
+ /// The column number on which the character is located.
+ ///
public int Column { get; }
+ ///
+ /// The line number on which the character is located.
+ ///
public int Line { get; }
}
}
diff --git a/src/GraphQLParser/Parser.cs b/src/GraphQLParser/Parser.cs
index fc139ebc..b81a061d 100644
--- a/src/GraphQLParser/Parser.cs
+++ b/src/GraphQLParser/Parser.cs
@@ -2,8 +2,17 @@
namespace GraphQLParser
{
+ ///
+ /// Parser for GraphQL syntax.
+ ///
public static class Parser
{
+ ///
+ /// Generates AST based on input text.
+ ///
+ /// Input data as a sequence of characters.
+ /// Specifies whether to ignore comments when parsing GraphQL document. By default, all comments are ignored.
+ /// AST (Abstract Syntax Tree) for GraphQL document.
public static GraphQLDocument Parse(ROM source, bool ignoreComments = true) => new ParserContext(source, ignoreComments).Parse();
}
}
diff --git a/src/GraphQLParser/ROM.cs b/src/GraphQLParser/ROM.cs
index 78a167ce..b79b67a8 100644
--- a/src/GraphQLParser/ROM.cs
+++ b/src/GraphQLParser/ROM.cs
@@ -47,7 +47,7 @@ public bool Equals(ROM other)
}
///
- public override int GetHashCode()
+ public override int GetHashCode() //TODO: find a better implementation
{
if (_memory.Length == 0)
return 0;
@@ -77,30 +77,69 @@ public override int GetHashCode()
///
public override string ToString() => _memory.ToString();
+ ///
+ /// Implicitly casts ReadOnlyMemory<char> to .
+ ///
public static implicit operator ROM(ReadOnlyMemory memory) => new ROM(memory);
+ ///
+ /// Implicitly casts to ReadOnlyMemory<char>.
+ ///
public static implicit operator ReadOnlyMemory(ROM rom) => rom._memory;
+ ///
+ /// Implicitly casts to ReadOnlySpan<char>.
+ ///
public static implicit operator ReadOnlySpan(ROM rom) => rom._memory.Span;
+ ///
+ /// Implicitly casts Memory<char> to .
+ ///
public static implicit operator ROM(Memory memory) => new ROM(memory);
+ ///
+ /// Implicitly casts string to .
+ ///
public static implicit operator ROM(string s) => s.AsMemory();
+ ///
+ /// Explicitly casts to string.
+ ///
public static explicit operator string(ROM rom) => rom.ToString();
+ ///
+ /// Implicitly casts array of chars to .
+ ///
public static implicit operator ROM(char[] array) => new ReadOnlyMemory(array);
+ ///
+ /// Checks two ROMs for equality. The check is based on the actual contents of the two chunks of memory.
+ ///
+ public static bool operator ==(ROM rom1, ROM rom2) => rom1.Equals(rom2);
+
+ ///
+ /// Checks two ROMs for inequality. The check is based on the actual contents of the two chunks of memory.
+ ///
+ public static bool operator !=(ROM rom1, ROM rom2) => !rom1.Equals(rom2);
+
+ ///
+ /// Checks ROM and string for equality. The check is based on the actual contents of the two chunks of memory.
+ ///
public static bool operator ==(ROM rom, string s) => rom._memory.Span.SequenceEqual(s.AsSpan());
+ ///
+ /// Checks ROM and string for inequality. The check is based on the actual contents of the two chunks of memory.
+ ///
public static bool operator !=(ROM rom, string s) => !rom._memory.Span.SequenceEqual(s.AsSpan());
+ ///
+ /// Checks string and ROM and for equality. The check is based on the actual contents of the two chunks of memory.
+ ///
public static bool operator ==(string s, ROM rom) => rom == s;
+ ///
+ /// Checks string and ROM and for inequality. The check is based on the actual contents of the two chunks of memory.
+ ///
public static bool operator !=(string s, ROM rom) => rom != s;
-
- public static bool operator ==(ROM rom1, ROM rom2) => rom1.Equals(rom2);
-
- public static bool operator !=(ROM rom1, ROM rom2) => !rom1.Equals(rom2);
}
}
diff --git a/src/GraphQLParser/Token.cs b/src/GraphQLParser/Token.cs
index 896e8f54..8283b8f1 100644
--- a/src/GraphQLParser/Token.cs
+++ b/src/GraphQLParser/Token.cs
@@ -22,12 +22,26 @@ public Token(TokenKind kind, ROM value, int start, int end)
public TokenKind Kind { get; }
///
- /// Starting position of the token in the document.
+ /// The index for the start of the token in the source (i.e. it's inclusive).
+ ///
+ /// For example:
+ ///
+ /// { field { subfield } }
+ ///
+ /// --^ Start = 2
+ ///
///
public int Start { get; }
///
- /// Ending position of the token in the document.
+ /// The index for the character immediately after the token in the source (i.e. it's exclusive).
+ ///
+ /// For example:
+ ///
+ /// { field { subfield } }
+ ///
+ /// --------------------^ End = 20
+ ///
///
public int End { get; }