diff --git a/src/GraphQLParser.ApiTests/GraphQLParser.approved.txt b/src/GraphQLParser.ApiTests/GraphQLParser.approved.txt index 1ab610ae..2f450a14 100644 --- a/src/GraphQLParser.ApiTests/GraphQLParser.approved.txt +++ b/src/GraphQLParser.ApiTests/GraphQLParser.approved.txt @@ -138,6 +138,12 @@ namespace GraphQLParser.AST public GraphQLArgumentsDefinition() { } public override GraphQLParser.AST.ASTNodeKind Kind { get; } } + public class GraphQLBooleanValue : GraphQLParser.AST.GraphQLValue + { + public GraphQLBooleanValue() { } + public override GraphQLParser.AST.ASTNodeKind Kind { get; } + public GraphQLParser.ROM Value { get; set; } + } public class GraphQLComment : GraphQLParser.AST.ASTNode { public GraphQLComment() { } @@ -199,10 +205,17 @@ namespace GraphQLParser.AST public override GraphQLParser.AST.ASTNodeKind Kind { get; } public GraphQLParser.AST.GraphQLEnumValuesDefinition? Values { get; set; } } + public class GraphQLEnumValue : GraphQLParser.AST.GraphQLValue, GraphQLParser.AST.INamedNode + { + public GraphQLEnumValue() { } + public override GraphQLParser.AST.ASTNodeKind Kind { get; } + public GraphQLParser.AST.GraphQLName Name { get; set; } + } public class GraphQLEnumValueDefinition : GraphQLParser.AST.GraphQLTypeDefinition, GraphQLParser.AST.IHasDirectivesNode { public GraphQLEnumValueDefinition() { } public GraphQLParser.AST.GraphQLDirectives? Directives { get; set; } + public GraphQLParser.AST.GraphQLEnumValue EnumValue { get; set; } public override GraphQLParser.AST.ASTNodeKind Kind { get; } } public class GraphQLEnumValuesDefinition : GraphQLParser.AST.ASTListNode @@ -239,6 +252,12 @@ namespace GraphQLParser.AST public GraphQLFieldsDefinition() { } public override GraphQLParser.AST.ASTNodeKind Kind { get; } } + public class GraphQLFloatValue : GraphQLParser.AST.GraphQLValue + { + public GraphQLFloatValue() { } + public override GraphQLParser.AST.ASTNodeKind Kind { get; } + public GraphQLParser.ROM Value { get; set; } + } public class GraphQLFragmentDefinition : GraphQLParser.AST.GraphQLExecutableDefinition, GraphQLParser.AST.INamedNode { public GraphQLFragmentDefinition() { } @@ -293,6 +312,12 @@ namespace GraphQLParser.AST public override GraphQLParser.AST.ASTNodeKind Kind { get; } public GraphQLParser.AST.GraphQLType Type { get; set; } } + public class GraphQLIntValue : GraphQLParser.AST.GraphQLValue + { + public GraphQLIntValue() { } + public override GraphQLParser.AST.ASTNodeKind Kind { get; } + public GraphQLParser.ROM Value { get; set; } + } public class GraphQLInterfaceTypeDefinition : GraphQLParser.AST.GraphQLTypeDefinition, GraphQLParser.AST.IHasDirectivesNode, GraphQLParser.AST.IHasFieldsDefinitionNode, GraphQLParser.AST.IHasInterfacesNode { public GraphQLInterfaceTypeDefinition() { } @@ -356,12 +381,18 @@ namespace GraphQLParser.AST public GraphQLParser.AST.GraphQLType Type { get; set; } public override string ToString() { } } + public class GraphQLNullValue : GraphQLParser.AST.GraphQLValue + { + public GraphQLNullValue() { } + public override GraphQLParser.AST.ASTNodeKind Kind { get; } + public GraphQLParser.ROM Value { get; set; } + } public class GraphQLObjectField : GraphQLParser.AST.ASTNode, GraphQLParser.AST.INamedNode { public GraphQLObjectField() { } public override GraphQLParser.AST.ASTNodeKind Kind { get; } public GraphQLParser.AST.GraphQLName Name { get; set; } - public GraphQLParser.AST.GraphQLValue? Value { get; set; } + public GraphQLParser.AST.GraphQLValue Value { get; set; } } public class GraphQLObjectTypeDefinition : GraphQLParser.AST.GraphQLTypeDefinition, GraphQLParser.AST.IHasDirectivesNode, GraphQLParser.AST.IHasFieldsDefinitionNode, GraphQLParser.AST.IHasInterfacesNode { @@ -412,13 +443,6 @@ namespace GraphQLParser.AST public GraphQLParser.AST.GraphQLDirectives? Directives { get; set; } public override GraphQLParser.AST.ASTNodeKind Kind { get; } } - public class GraphQLScalarValue : GraphQLParser.AST.GraphQLValue - { - public GraphQLScalarValue(GraphQLParser.AST.ASTNodeKind kind) { } - public override GraphQLParser.AST.ASTNodeKind Kind { get; } - public GraphQLParser.ROM Value { get; set; } - public override string? ToString() { } - } public class GraphQLSchemaDefinition : GraphQLParser.AST.ASTNode, GraphQLParser.AST.IHasDescriptionNode, GraphQLParser.AST.IHasDirectivesNode { public GraphQLSchemaDefinition() { } @@ -433,6 +457,12 @@ namespace GraphQLParser.AST public override GraphQLParser.AST.ASTNodeKind Kind { get; } public System.Collections.Generic.List? Selections { get; set; } } + public class GraphQLStringValue : GraphQLParser.AST.GraphQLValue + { + public GraphQLStringValue() { } + public override GraphQLParser.AST.ASTNodeKind Kind { get; } + public GraphQLParser.ROM Value { get; set; } + } public abstract class GraphQLType : GraphQLParser.AST.ASTNode { protected GraphQLType() { } @@ -681,7 +711,7 @@ namespace GraphQLParser.Visitors public virtual System.Threading.Tasks.ValueTask VisitArgument(GraphQLParser.AST.GraphQLArgument argument, TContext context) { } public virtual System.Threading.Tasks.ValueTask VisitArguments(GraphQLParser.AST.GraphQLArguments arguments, TContext context) { } public virtual System.Threading.Tasks.ValueTask VisitArgumentsDefinition(GraphQLParser.AST.GraphQLArgumentsDefinition argumentsDefinition, TContext context) { } - public virtual System.Threading.Tasks.ValueTask VisitBooleanValue(GraphQLParser.AST.GraphQLScalarValue booleanValue, TContext context) { } + public virtual System.Threading.Tasks.ValueTask VisitBooleanValue(GraphQLParser.AST.GraphQLBooleanValue booleanValue, TContext context) { } public virtual System.Threading.Tasks.ValueTask VisitComment(GraphQLParser.AST.GraphQLComment comment, TContext context) { } public virtual System.Threading.Tasks.ValueTask VisitDescription(GraphQLParser.AST.GraphQLDescription description, TContext context) { } public virtual System.Threading.Tasks.ValueTask VisitDirective(GraphQLParser.AST.GraphQLDirective directive, TContext context) { } @@ -691,13 +721,13 @@ namespace GraphQLParser.Visitors public virtual System.Threading.Tasks.ValueTask VisitDocument(GraphQLParser.AST.GraphQLDocument document, TContext context) { } public virtual System.Threading.Tasks.ValueTask VisitEnumTypeDefinition(GraphQLParser.AST.GraphQLEnumTypeDefinition enumTypeDefinition, TContext context) { } public virtual System.Threading.Tasks.ValueTask VisitEnumTypeExtension(GraphQLParser.AST.GraphQLEnumTypeExtension enumTypeExtension, TContext context) { } - public virtual System.Threading.Tasks.ValueTask VisitEnumValue(GraphQLParser.AST.GraphQLScalarValue enumValue, TContext context) { } + public virtual System.Threading.Tasks.ValueTask VisitEnumValue(GraphQLParser.AST.GraphQLEnumValue enumValue, TContext context) { } public virtual System.Threading.Tasks.ValueTask VisitEnumValueDefinition(GraphQLParser.AST.GraphQLEnumValueDefinition enumValueDefinition, TContext context) { } public virtual System.Threading.Tasks.ValueTask VisitEnumValuesDefinition(GraphQLParser.AST.GraphQLEnumValuesDefinition enumValuesDefinition, TContext context) { } public virtual System.Threading.Tasks.ValueTask VisitField(GraphQLParser.AST.GraphQLField field, TContext context) { } public virtual System.Threading.Tasks.ValueTask VisitFieldDefinition(GraphQLParser.AST.GraphQLFieldDefinition fieldDefinition, TContext context) { } public virtual System.Threading.Tasks.ValueTask VisitFieldsDefinition(GraphQLParser.AST.GraphQLFieldsDefinition fieldsDefinition, TContext context) { } - public virtual System.Threading.Tasks.ValueTask VisitFloatValue(GraphQLParser.AST.GraphQLScalarValue floatValue, TContext context) { } + public virtual System.Threading.Tasks.ValueTask VisitFloatValue(GraphQLParser.AST.GraphQLFloatValue floatValue, TContext context) { } public virtual System.Threading.Tasks.ValueTask VisitFragmentDefinition(GraphQLParser.AST.GraphQLFragmentDefinition fragmentDefinition, TContext context) { } public virtual System.Threading.Tasks.ValueTask VisitFragmentSpread(GraphQLParser.AST.GraphQLFragmentSpread fragmentSpread, TContext context) { } public virtual System.Threading.Tasks.ValueTask VisitImplementsInterfaces(GraphQLParser.AST.GraphQLImplementsInterfaces implementsInterfaces, TContext context) { } @@ -706,7 +736,7 @@ namespace GraphQLParser.Visitors public virtual System.Threading.Tasks.ValueTask VisitInputObjectTypeDefinition(GraphQLParser.AST.GraphQLInputObjectTypeDefinition inputObjectTypeDefinition, TContext context) { } public virtual System.Threading.Tasks.ValueTask VisitInputObjectTypeExtension(GraphQLParser.AST.GraphQLInputObjectTypeExtension inputObjectTypeExtension, TContext context) { } public virtual System.Threading.Tasks.ValueTask VisitInputValueDefinition(GraphQLParser.AST.GraphQLInputValueDefinition inputValueDefinition, TContext context) { } - public virtual System.Threading.Tasks.ValueTask VisitIntValue(GraphQLParser.AST.GraphQLScalarValue intValue, TContext context) { } + public virtual System.Threading.Tasks.ValueTask VisitIntValue(GraphQLParser.AST.GraphQLIntValue intValue, TContext context) { } public virtual System.Threading.Tasks.ValueTask VisitInterfaceTypeDefinition(GraphQLParser.AST.GraphQLInterfaceTypeDefinition interfaceTypeDefinition, TContext context) { } public virtual System.Threading.Tasks.ValueTask VisitInterfaceTypeExtension(GraphQLParser.AST.GraphQLInterfaceTypeExtension interfaceTypeExtension, TContext context) { } public virtual System.Threading.Tasks.ValueTask VisitListType(GraphQLParser.AST.GraphQLListType listType, TContext context) { } @@ -714,7 +744,7 @@ namespace GraphQLParser.Visitors public virtual System.Threading.Tasks.ValueTask VisitName(GraphQLParser.AST.GraphQLName name, TContext context) { } public virtual System.Threading.Tasks.ValueTask VisitNamedType(GraphQLParser.AST.GraphQLNamedType namedType, TContext context) { } public virtual System.Threading.Tasks.ValueTask VisitNonNullType(GraphQLParser.AST.GraphQLNonNullType nonNullType, TContext context) { } - public virtual System.Threading.Tasks.ValueTask VisitNullValue(GraphQLParser.AST.GraphQLScalarValue nullValue, TContext context) { } + public virtual System.Threading.Tasks.ValueTask VisitNullValue(GraphQLParser.AST.GraphQLNullValue nullValue, TContext context) { } public virtual System.Threading.Tasks.ValueTask VisitObjectField(GraphQLParser.AST.GraphQLObjectField objectField, TContext context) { } public virtual System.Threading.Tasks.ValueTask VisitObjectTypeDefinition(GraphQLParser.AST.GraphQLObjectTypeDefinition objectTypeDefinition, TContext context) { } public virtual System.Threading.Tasks.ValueTask VisitObjectTypeExtension(GraphQLParser.AST.GraphQLObjectTypeExtension objectTypeExtension, TContext context) { } @@ -725,7 +755,7 @@ namespace GraphQLParser.Visitors public virtual System.Threading.Tasks.ValueTask VisitScalarTypeExtension(GraphQLParser.AST.GraphQLScalarTypeExtension scalarTypeExtension, TContext context) { } public virtual System.Threading.Tasks.ValueTask VisitSchemaDefinition(GraphQLParser.AST.GraphQLSchemaDefinition schemaDefinition, TContext context) { } public virtual System.Threading.Tasks.ValueTask VisitSelectionSet(GraphQLParser.AST.GraphQLSelectionSet selectionSet, TContext context) { } - public virtual System.Threading.Tasks.ValueTask VisitStringValue(GraphQLParser.AST.GraphQLScalarValue stringValue, TContext context) { } + public virtual System.Threading.Tasks.ValueTask VisitStringValue(GraphQLParser.AST.GraphQLStringValue stringValue, TContext context) { } public virtual System.Threading.Tasks.ValueTask VisitTypeCondition(GraphQLParser.AST.GraphQLTypeCondition typeCondition, TContext context) { } public virtual System.Threading.Tasks.ValueTask VisitUnionMemberTypes(GraphQLParser.AST.GraphQLUnionMemberTypes unionMemberTypes, TContext context) { } public virtual System.Threading.Tasks.ValueTask VisitUnionTypeDefinition(GraphQLParser.AST.GraphQLUnionTypeDefinition unionTypeDefinition, TContext context) { } @@ -755,7 +785,7 @@ namespace GraphQLParser.Visitors System.Threading.Tasks.ValueTask VisitArgument(GraphQLParser.AST.GraphQLArgument argument, TContext context); System.Threading.Tasks.ValueTask VisitArguments(GraphQLParser.AST.GraphQLArguments arguments, TContext context); System.Threading.Tasks.ValueTask VisitArgumentsDefinition(GraphQLParser.AST.GraphQLArgumentsDefinition argumentsDefinition, TContext context); - System.Threading.Tasks.ValueTask VisitBooleanValue(GraphQLParser.AST.GraphQLScalarValue booleanValue, TContext context); + System.Threading.Tasks.ValueTask VisitBooleanValue(GraphQLParser.AST.GraphQLBooleanValue booleanValue, TContext context); System.Threading.Tasks.ValueTask VisitComment(GraphQLParser.AST.GraphQLComment comment, TContext context); System.Threading.Tasks.ValueTask VisitDescription(GraphQLParser.AST.GraphQLDescription description, TContext context); System.Threading.Tasks.ValueTask VisitDirective(GraphQLParser.AST.GraphQLDirective directive, TContext context); @@ -765,13 +795,13 @@ namespace GraphQLParser.Visitors System.Threading.Tasks.ValueTask VisitDocument(GraphQLParser.AST.GraphQLDocument document, TContext context); System.Threading.Tasks.ValueTask VisitEnumTypeDefinition(GraphQLParser.AST.GraphQLEnumTypeDefinition enumTypeDefinition, TContext context); System.Threading.Tasks.ValueTask VisitEnumTypeExtension(GraphQLParser.AST.GraphQLEnumTypeExtension enumTypeExtension, TContext context); - System.Threading.Tasks.ValueTask VisitEnumValue(GraphQLParser.AST.GraphQLScalarValue enumValue, TContext context); + System.Threading.Tasks.ValueTask VisitEnumValue(GraphQLParser.AST.GraphQLEnumValue enumValue, TContext context); System.Threading.Tasks.ValueTask VisitEnumValueDefinition(GraphQLParser.AST.GraphQLEnumValueDefinition enumValueDefinition, TContext context); System.Threading.Tasks.ValueTask VisitEnumValuesDefinition(GraphQLParser.AST.GraphQLEnumValuesDefinition enumValuesDefinition, TContext context); System.Threading.Tasks.ValueTask VisitField(GraphQLParser.AST.GraphQLField field, TContext context); System.Threading.Tasks.ValueTask VisitFieldDefinition(GraphQLParser.AST.GraphQLFieldDefinition fieldDefinition, TContext context); System.Threading.Tasks.ValueTask VisitFieldsDefinition(GraphQLParser.AST.GraphQLFieldsDefinition fieldsDefinition, TContext context); - System.Threading.Tasks.ValueTask VisitFloatValue(GraphQLParser.AST.GraphQLScalarValue floatValue, TContext context); + System.Threading.Tasks.ValueTask VisitFloatValue(GraphQLParser.AST.GraphQLFloatValue floatValue, TContext context); System.Threading.Tasks.ValueTask VisitFragmentDefinition(GraphQLParser.AST.GraphQLFragmentDefinition fragmentDefinition, TContext context); System.Threading.Tasks.ValueTask VisitFragmentSpread(GraphQLParser.AST.GraphQLFragmentSpread fragmentSpread, TContext context); System.Threading.Tasks.ValueTask VisitImplementsInterfaces(GraphQLParser.AST.GraphQLImplementsInterfaces implementsInterfaces, TContext context); @@ -780,7 +810,7 @@ namespace GraphQLParser.Visitors System.Threading.Tasks.ValueTask VisitInputObjectTypeDefinition(GraphQLParser.AST.GraphQLInputObjectTypeDefinition inputObjectTypeDefinition, TContext context); System.Threading.Tasks.ValueTask VisitInputObjectTypeExtension(GraphQLParser.AST.GraphQLInputObjectTypeExtension inputObjectTypeExtension, TContext context); System.Threading.Tasks.ValueTask VisitInputValueDefinition(GraphQLParser.AST.GraphQLInputValueDefinition inputValueDefinition, TContext context); - System.Threading.Tasks.ValueTask VisitIntValue(GraphQLParser.AST.GraphQLScalarValue intValue, TContext context); + System.Threading.Tasks.ValueTask VisitIntValue(GraphQLParser.AST.GraphQLIntValue intValue, TContext context); System.Threading.Tasks.ValueTask VisitInterfaceTypeDefinition(GraphQLParser.AST.GraphQLInterfaceTypeDefinition interfaceTypeDefinition, TContext context); System.Threading.Tasks.ValueTask VisitInterfaceTypeExtension(GraphQLParser.AST.GraphQLInterfaceTypeExtension interfaceTypeExtension, TContext context); System.Threading.Tasks.ValueTask VisitListType(GraphQLParser.AST.GraphQLListType listType, TContext context); @@ -788,7 +818,7 @@ namespace GraphQLParser.Visitors System.Threading.Tasks.ValueTask VisitName(GraphQLParser.AST.GraphQLName name, TContext context); System.Threading.Tasks.ValueTask VisitNamedType(GraphQLParser.AST.GraphQLNamedType namedType, TContext context); System.Threading.Tasks.ValueTask VisitNonNullType(GraphQLParser.AST.GraphQLNonNullType nonNullType, TContext context); - System.Threading.Tasks.ValueTask VisitNullValue(GraphQLParser.AST.GraphQLScalarValue nullValue, TContext context); + System.Threading.Tasks.ValueTask VisitNullValue(GraphQLParser.AST.GraphQLNullValue nullValue, TContext context); System.Threading.Tasks.ValueTask VisitObjectField(GraphQLParser.AST.GraphQLObjectField objectField, TContext context); System.Threading.Tasks.ValueTask VisitObjectTypeDefinition(GraphQLParser.AST.GraphQLObjectTypeDefinition objectTypeDefinition, TContext context); System.Threading.Tasks.ValueTask VisitObjectTypeExtension(GraphQLParser.AST.GraphQLObjectTypeExtension objectTypeExtension, TContext context); @@ -799,7 +829,7 @@ namespace GraphQLParser.Visitors System.Threading.Tasks.ValueTask VisitScalarTypeExtension(GraphQLParser.AST.GraphQLScalarTypeExtension scalarTypeExtension, TContext context); System.Threading.Tasks.ValueTask VisitSchemaDefinition(GraphQLParser.AST.GraphQLSchemaDefinition schemaDefinition, TContext context); System.Threading.Tasks.ValueTask VisitSelectionSet(GraphQLParser.AST.GraphQLSelectionSet selectionSet, TContext context); - System.Threading.Tasks.ValueTask VisitStringValue(GraphQLParser.AST.GraphQLScalarValue stringValue, TContext context); + System.Threading.Tasks.ValueTask VisitStringValue(GraphQLParser.AST.GraphQLStringValue stringValue, TContext context); System.Threading.Tasks.ValueTask VisitTypeCondition(GraphQLParser.AST.GraphQLTypeCondition typeCondition, TContext context); System.Threading.Tasks.ValueTask VisitUnionMemberTypes(GraphQLParser.AST.GraphQLUnionMemberTypes unionMemberTypes, TContext context); System.Threading.Tasks.ValueTask VisitUnionTypeDefinition(GraphQLParser.AST.GraphQLUnionTypeDefinition unionTypeDefinition, TContext context); @@ -828,7 +858,7 @@ namespace GraphQLParser.Visitors public override System.Threading.Tasks.ValueTask VisitArgument(GraphQLParser.AST.GraphQLArgument argument, TContext context) { } public override System.Threading.Tasks.ValueTask VisitArguments(GraphQLParser.AST.GraphQLArguments arguments, TContext context) { } public override System.Threading.Tasks.ValueTask VisitArgumentsDefinition(GraphQLParser.AST.GraphQLArgumentsDefinition argumentsDefinition, TContext context) { } - public override System.Threading.Tasks.ValueTask VisitBooleanValue(GraphQLParser.AST.GraphQLScalarValue booleanValue, TContext context) { } + public override System.Threading.Tasks.ValueTask VisitBooleanValue(GraphQLParser.AST.GraphQLBooleanValue booleanValue, TContext context) { } public override System.Threading.Tasks.ValueTask VisitComment(GraphQLParser.AST.GraphQLComment comment, TContext context) { } public override System.Threading.Tasks.ValueTask VisitDescription(GraphQLParser.AST.GraphQLDescription description, TContext context) { } public override System.Threading.Tasks.ValueTask VisitDirective(GraphQLParser.AST.GraphQLDirective directive, TContext context) { } @@ -838,13 +868,13 @@ namespace GraphQLParser.Visitors public override System.Threading.Tasks.ValueTask VisitDocument(GraphQLParser.AST.GraphQLDocument document, TContext context) { } public override System.Threading.Tasks.ValueTask VisitEnumTypeDefinition(GraphQLParser.AST.GraphQLEnumTypeDefinition enumTypeDefinition, TContext context) { } public override System.Threading.Tasks.ValueTask VisitEnumTypeExtension(GraphQLParser.AST.GraphQLEnumTypeExtension enumTypeExtension, TContext context) { } - public override System.Threading.Tasks.ValueTask VisitEnumValue(GraphQLParser.AST.GraphQLScalarValue enumValue, TContext context) { } + public override System.Threading.Tasks.ValueTask VisitEnumValue(GraphQLParser.AST.GraphQLEnumValue enumValue, TContext context) { } public override System.Threading.Tasks.ValueTask VisitEnumValueDefinition(GraphQLParser.AST.GraphQLEnumValueDefinition enumValueDefinition, TContext context) { } public override System.Threading.Tasks.ValueTask VisitEnumValuesDefinition(GraphQLParser.AST.GraphQLEnumValuesDefinition enumValuesDefinition, TContext context) { } public override System.Threading.Tasks.ValueTask VisitField(GraphQLParser.AST.GraphQLField field, TContext context) { } public override System.Threading.Tasks.ValueTask VisitFieldDefinition(GraphQLParser.AST.GraphQLFieldDefinition fieldDefinition, TContext context) { } public override System.Threading.Tasks.ValueTask VisitFieldsDefinition(GraphQLParser.AST.GraphQLFieldsDefinition fieldsDefinition, TContext context) { } - public override System.Threading.Tasks.ValueTask VisitFloatValue(GraphQLParser.AST.GraphQLScalarValue floatValue, TContext context) { } + public override System.Threading.Tasks.ValueTask VisitFloatValue(GraphQLParser.AST.GraphQLFloatValue floatValue, TContext context) { } public override System.Threading.Tasks.ValueTask VisitFragmentDefinition(GraphQLParser.AST.GraphQLFragmentDefinition fragmentDefinition, TContext context) { } public override System.Threading.Tasks.ValueTask VisitFragmentSpread(GraphQLParser.AST.GraphQLFragmentSpread fragmentSpread, TContext context) { } public override System.Threading.Tasks.ValueTask VisitImplementsInterfaces(GraphQLParser.AST.GraphQLImplementsInterfaces implementsInterfaces, TContext context) { } @@ -853,7 +883,7 @@ namespace GraphQLParser.Visitors public override System.Threading.Tasks.ValueTask VisitInputObjectTypeDefinition(GraphQLParser.AST.GraphQLInputObjectTypeDefinition inputObjectTypeDefinition, TContext context) { } public override System.Threading.Tasks.ValueTask VisitInputObjectTypeExtension(GraphQLParser.AST.GraphQLInputObjectTypeExtension inputObjectTypeExtension, TContext context) { } public override System.Threading.Tasks.ValueTask VisitInputValueDefinition(GraphQLParser.AST.GraphQLInputValueDefinition inputValueDefinition, TContext context) { } - public override System.Threading.Tasks.ValueTask VisitIntValue(GraphQLParser.AST.GraphQLScalarValue intValue, TContext context) { } + public override System.Threading.Tasks.ValueTask VisitIntValue(GraphQLParser.AST.GraphQLIntValue intValue, TContext context) { } public override System.Threading.Tasks.ValueTask VisitInterfaceTypeDefinition(GraphQLParser.AST.GraphQLInterfaceTypeDefinition interfaceTypeDefinition, TContext context) { } public override System.Threading.Tasks.ValueTask VisitInterfaceTypeExtension(GraphQLParser.AST.GraphQLInterfaceTypeExtension interfaceTypeExtension, TContext context) { } public override System.Threading.Tasks.ValueTask VisitListType(GraphQLParser.AST.GraphQLListType listType, TContext context) { } @@ -861,7 +891,7 @@ namespace GraphQLParser.Visitors public override System.Threading.Tasks.ValueTask VisitName(GraphQLParser.AST.GraphQLName name, TContext context) { } public override System.Threading.Tasks.ValueTask VisitNamedType(GraphQLParser.AST.GraphQLNamedType namedType, TContext context) { } public override System.Threading.Tasks.ValueTask VisitNonNullType(GraphQLParser.AST.GraphQLNonNullType nonNullType, TContext context) { } - public override System.Threading.Tasks.ValueTask VisitNullValue(GraphQLParser.AST.GraphQLScalarValue nullValue, TContext context) { } + public override System.Threading.Tasks.ValueTask VisitNullValue(GraphQLParser.AST.GraphQLNullValue nullValue, TContext context) { } public override System.Threading.Tasks.ValueTask VisitObjectField(GraphQLParser.AST.GraphQLObjectField objectField, TContext context) { } public override System.Threading.Tasks.ValueTask VisitObjectTypeDefinition(GraphQLParser.AST.GraphQLObjectTypeDefinition objectTypeDefinition, TContext context) { } public override System.Threading.Tasks.ValueTask VisitObjectTypeExtension(GraphQLParser.AST.GraphQLObjectTypeExtension objectTypeExtension, TContext context) { } @@ -872,7 +902,7 @@ namespace GraphQLParser.Visitors public override System.Threading.Tasks.ValueTask VisitScalarTypeExtension(GraphQLParser.AST.GraphQLScalarTypeExtension scalarTypeExtension, TContext context) { } public override System.Threading.Tasks.ValueTask VisitSchemaDefinition(GraphQLParser.AST.GraphQLSchemaDefinition schemaDefinition, TContext context) { } public override System.Threading.Tasks.ValueTask VisitSelectionSet(GraphQLParser.AST.GraphQLSelectionSet selectionSet, TContext context) { } - public override System.Threading.Tasks.ValueTask VisitStringValue(GraphQLParser.AST.GraphQLScalarValue stringValue, TContext context) { } + public override System.Threading.Tasks.ValueTask VisitStringValue(GraphQLParser.AST.GraphQLStringValue stringValue, TContext context) { } public override System.Threading.Tasks.ValueTask VisitTypeCondition(GraphQLParser.AST.GraphQLTypeCondition typeCondition, TContext context) { } public override System.Threading.Tasks.ValueTask VisitUnionMemberTypes(GraphQLParser.AST.GraphQLUnionMemberTypes unionMemberTypes, TContext context) { } public override System.Threading.Tasks.ValueTask VisitUnionTypeDefinition(GraphQLParser.AST.GraphQLUnionTypeDefinition unionTypeDefinition, TContext context) { } diff --git a/src/GraphQLParser.Tests/Issue82.cs b/src/GraphQLParser.Tests/Issue82.cs index 220161e3..47663b93 100644 --- a/src/GraphQLParser.Tests/Issue82.cs +++ b/src/GraphQLParser.Tests/Issue82.cs @@ -30,7 +30,7 @@ public void Parse_Named_And_Literal_Variables(IgnoreOptions options) var selection = def.SelectionSet.Selections[0].ShouldBeAssignableTo(); selection.Arguments.Count.ShouldBe(2); selection.Arguments[0].Value.ShouldBeAssignableTo().Name.Value.ShouldBe("username"); - selection.Arguments[1].Value.ShouldBeAssignableTo().Value.ShouldBe("Pete"); + selection.Arguments[1].Value.ShouldBeAssignableTo().Value.ShouldBe("Pete"); } } } diff --git a/src/GraphQLParser.Tests/ParserTests.cs b/src/GraphQLParser.Tests/ParserTests.cs index 44de7c36..472690ec 100644 --- a/src/GraphQLParser.Tests/ParserTests.cs +++ b/src/GraphQLParser.Tests/ParserTests.cs @@ -208,13 +208,13 @@ public void Comments_on_Values_Should_Read_Correctly(IgnoreOptions options) field.SelectionSet.Selections.Count.ShouldBe(1); field.Arguments.Count.ShouldBe(9); - var boolValue = field.Arguments[0].Value.ShouldBeAssignableTo(); + var boolValue = field.Arguments[0].Value.ShouldBeAssignableTo(); boolValue.Comment.ShouldNotBeNull().Text.ShouldBe("comment for bool"); - var nullValue = field.Arguments[1].Value.ShouldBeAssignableTo(); + var nullValue = field.Arguments[1].Value.ShouldBeAssignableTo(); nullValue.Comment.ShouldNotBeNull().Text.ShouldBe("comment for null"); - var enumValue = field.Arguments[2].Value.ShouldBeAssignableTo(); + var enumValue = field.Arguments[2].Value.ShouldBeAssignableTo(); enumValue.Comment.ShouldNotBeNull().Text.ShouldBe("comment for enum"); var listValue = field.Arguments[3].Value.ShouldBeAssignableTo(); @@ -223,13 +223,13 @@ public void Comments_on_Values_Should_Read_Correctly(IgnoreOptions options) var objValue = field.Arguments[4].Value.ShouldBeAssignableTo(); objValue.Comment.ShouldNotBeNull().Text.ShouldBe("comment for object"); - var intValue = field.Arguments[5].Value.ShouldBeAssignableTo(); + var intValue = field.Arguments[5].Value.ShouldBeAssignableTo(); intValue.Comment.ShouldNotBeNull().Text.ShouldBe("comment for int"); - var floatValue = field.Arguments[6].Value.ShouldBeAssignableTo(); + var floatValue = field.Arguments[6].Value.ShouldBeAssignableTo(); floatValue.Comment.ShouldNotBeNull().Text.ShouldBe("comment for float"); - var stringValue = field.Arguments[7].Value.ShouldBeAssignableTo(); + var stringValue = field.Arguments[7].Value.ShouldBeAssignableTo(); stringValue.Comment.ShouldNotBeNull().Text.ShouldBe("comment for string"); var varValue = field.Arguments[8].Value.ShouldBeAssignableTo(); @@ -527,6 +527,18 @@ public void Should_Throw_On_Unknown_OperationType() ex.Column.ShouldBe(1); } + [Theory] + [InlineData("enum E { true A }", "Unexpected Name \"true\"; enum values are represented as unquoted names but not 'true' or 'false' or 'null'.", 1, 10)] + [InlineData("enum E { B false }", "Unexpected Name \"false\"; enum values are represented as unquoted names but not 'true' or 'false' or 'null'.", 1, 12)] + [InlineData("enum E { A null B }", "Unexpected Name \"null\"; enum values are represented as unquoted names but not 'true' or 'false' or 'null'.", 1, 12)] + public void Should_Throw_On_Invalid_EnumValue(string query, string description, int line, int column) + { + var ex = Should.Throw(() => query.Parse()); + ex.Description.ShouldBe(description); + ex.Line.ShouldBe(line); + ex.Column.ShouldBe(column); + } + [Theory] [InlineData(IgnoreOptions.None)] [InlineData(IgnoreOptions.Comments)] @@ -825,7 +837,7 @@ public void Should_Parse_SpecifiedBy() def.Directives[0].Name.Value.ShouldBe("specifiedBy"); def.Directives[0].Arguments.Count.ShouldBe(1); def.Directives[0].Arguments[0].Name.Value.ShouldBe("url"); - var value = def.Directives[0].Arguments[0].Value.ShouldBeAssignableTo(); + var value = def.Directives[0].Arguments[0].Value.ShouldBeAssignableTo(); value.Value.ShouldBe("https://tools.ietf.org/html/rfc4122"); } @@ -936,23 +948,23 @@ public void Should_Parse_Extensions(string text, ASTNodeKind kind) } [Theory] - [InlineData("extend", "Unexpected EOF")] - [InlineData("extend scalar", "Expected Name, found EOF")] - [InlineData("extend scalar A", "Unexpected EOF")] - [InlineData("extend scalar A B", "Unexpected Name \"B\"")] - [InlineData("extend type", "Expected Name, found EOF")] - [InlineData("extend type A", "Unexpected EOF")] - [InlineData("extend type A B", "Unexpected Name \"B\"")] - [InlineData("extend interface", "Expected Name, found EOF")] - [InlineData("extend interface A", "Unexpected EOF")] - [InlineData("extend interface A B", "Unexpected Name \"B\"")] - [InlineData("extend union", "Expected Name, found EOF")] - [InlineData("extend union A", "Unexpected EOF")] - [InlineData("extend enum", "Expected Name, found EOF")] - [InlineData("extend enum A", "Unexpected EOF")] - [InlineData("extend input", "Expected Name, found EOF")] - [InlineData("extend input A", "Unexpected EOF")] - [InlineData("extend variable", "Unexpected Name \"variable\"")] + [InlineData("extend", "Unexpected EOF; for more information see http://spec.graphql.org/October2021/#TypeExtension")] + [InlineData("extend scalar", "Expected Name, found EOF; for more information see http://spec.graphql.org/October2021/#ScalarTypeExtension")] + [InlineData("extend scalar A", "Unexpected EOF; for more information see http://spec.graphql.org/October2021/#ScalarTypeExtension")] + [InlineData("extend scalar A B", "Unexpected Name \"B\"; for more information see http://spec.graphql.org/October2021/#ScalarTypeExtension")] + [InlineData("extend type", "Expected Name, found EOF; for more information see http://spec.graphql.org/October2021/#ObjectTypeExtension")] + [InlineData("extend type A", "Unexpected EOF; for more information see http://spec.graphql.org/October2021/#ObjectTypeExtension")] + [InlineData("extend type A B", "Unexpected Name \"B\"; for more information see http://spec.graphql.org/October2021/#ObjectTypeExtension")] + [InlineData("extend interface", "Expected Name, found EOF; for more information see http://spec.graphql.org/October2021/#InterfaceTypeExtension")] + [InlineData("extend interface A", "Unexpected EOF; for more information see http://spec.graphql.org/October2021/#InterfaceTypeExtension")] + [InlineData("extend interface A B", "Unexpected Name \"B\"; for more information see http://spec.graphql.org/October2021/#InterfaceTypeExtension")] + [InlineData("extend union", "Expected Name, found EOF; for more information see http://spec.graphql.org/October2021/#UnionTypeExtension")] + [InlineData("extend union A", "Unexpected EOF; for more information see http://spec.graphql.org/October2021/#UnionTypeExtension")] + [InlineData("extend enum", "Expected Name, found EOF; for more information see http://spec.graphql.org/October2021/#EnumTypeExtension")] + [InlineData("extend enum A", "Unexpected EOF; for more information see http://spec.graphql.org/October2021/#EnumTypeExtension")] + [InlineData("extend input", "Expected Name, found EOF; for more information see http://spec.graphql.org/October2021/#InputObjectTypeExtension")] + [InlineData("extend input A", "Unexpected EOF; for more information see http://spec.graphql.org/October2021/#InputObjectTypeExtension")] + [InlineData("extend variable", "Unexpected Name \"variable\"; for more information see http://spec.graphql.org/October2021/#TypeExtension")] public void Should_Throw_Extensions(string text, string description) { var ex = Should.Throw(() => text.Parse()); diff --git a/src/GraphQLParser.Tests/Validation/ParserValidationTests.cs b/src/GraphQLParser.Tests/Validation/ParserValidationTests.cs index ac1e78a0..cf45eabe 100644 --- a/src/GraphQLParser.Tests/Validation/ParserValidationTests.cs +++ b/src/GraphQLParser.Tests/Validation/ParserValidationTests.cs @@ -16,10 +16,10 @@ public void Parse_FragmentInvalidOnName_ThrowsExceptionWithCorrectMessage(Ignore var exception = Should.Throw(() => "fragment on on on { on }".Parse(new ParserOptions { Ignore = options })); exception.Message.ShouldBe( - "Syntax Error GraphQL (1:10) Unexpected Name \"on\"\n" + + "Syntax Error GraphQL (1:10) Unexpected Name \"on\"; fragment name can not be 'on'.\n" + "1: fragment on on on { on }\n" + " ^\n"); - exception.Description.ShouldBe("Unexpected Name " + "\"on\""); + exception.Description.ShouldBe("Unexpected Name " + "\"on\"; fragment name can not be 'on'."); exception.Line.ShouldBe(1); exception.Column.ShouldBe(10); } @@ -52,10 +52,10 @@ public void Parse_InvalidFragmentNameInSpread_ThrowsExceptionWithCorrectMessage( var exception = Should.Throw(() => "{ ...on }".Parse(new ParserOptions { Ignore = options })); exception.Message.ShouldBe( - "Syntax Error GraphQL (1:9) Expected Name, found }\n" + + "Syntax Error GraphQL (1:9) Expected Name, found }; for more information see http://spec.graphql.org/October2021/#NamedType\n" + "1: { ...on }\n" + " ^\n"); - exception.Description.ShouldBe("Expected Name, found }"); + exception.Description.ShouldBe("Expected Name, found }; for more information see http://spec.graphql.org/October2021/#NamedType"); exception.Line.ShouldBe(1); exception.Column.ShouldBe(9); } @@ -88,10 +88,10 @@ public void Parse_MissingEndingBrace_ThrowsExceptionWithCorrectMessage(IgnoreOpt var exception = Should.Throw(() => "{".Parse(new ParserOptions { Ignore = options })); exception.Message.ShouldBe( - "Syntax Error GraphQL (1:2) Expected Name, found EOF\n" + + "Syntax Error GraphQL (1:2) Expected Name, found EOF; for more information see http://spec.graphql.org/October2021/#Field\n" + "1: {\n" + " ^\n"); - exception.Description.ShouldBe("Expected Name, found EOF"); + exception.Description.ShouldBe("Expected Name, found EOF; for more information see http://spec.graphql.org/October2021/#Field"); exception.Line.ShouldBe(1); exception.Column.ShouldBe(2); } @@ -106,10 +106,10 @@ public void Parse_MissingFieldNameWhenAliasing_ThrowsExceptionWithCorrectMessage var exception = Should.Throw(() => "{ field: {} }".Parse(new ParserOptions { Ignore = options })); exception.Message.ShouldBe( - "Syntax Error GraphQL (1:10) Expected Name, found {\n" + + "Syntax Error GraphQL (1:10) Expected Name, found {; for more information see http://spec.graphql.org/October2021/#Field\n" + "1: { field: {} }\n" + " ^\n"); - exception.Description.ShouldBe("Expected Name, found {"); + exception.Description.ShouldBe("Expected Name, found {; for more information see http://spec.graphql.org/October2021/#Field"); exception.Line.ShouldBe(1); exception.Column.ShouldBe(10); } diff --git a/src/GraphQLParser.Tests/Visitors/GraphQLAstVisitorTests.cs b/src/GraphQLParser.Tests/Visitors/GraphQLAstVisitorTests.cs index cdaa2586..545667bd 100644 --- a/src/GraphQLParser.Tests/Visitors/GraphQLAstVisitorTests.cs +++ b/src/GraphQLParser.Tests/Visitors/GraphQLAstVisitorTests.cs @@ -13,13 +13,13 @@ public class GraphQLAstVisitorTests { public class CountVisitor : DefaultNodeVisitor { - public override async ValueTask VisitBooleanValue(GraphQLScalarValue booleanValue, CountContext context) + public override async ValueTask VisitBooleanValue(GraphQLBooleanValue booleanValue, CountContext context) { context.VisitedBooleanValues.Add(booleanValue); await base.VisitBooleanValue(booleanValue, context); } - public override async ValueTask VisitIntValue(GraphQLScalarValue intValue, CountContext context) + public override async ValueTask VisitIntValue(GraphQLIntValue intValue, CountContext context) { context.VisitedIntValues.Add(intValue); await base.VisitIntValue(intValue, context); @@ -55,13 +55,13 @@ public override async ValueTask VisitDirective(GraphQLDirective directive, Count await base.VisitDirective(directive, context); } - public override async ValueTask VisitEnumValue(GraphQLScalarValue enumValue, CountContext context) + public override async ValueTask VisitEnumValue(GraphQLEnumValue enumValue, CountContext context) { context.VisitedEnumValues.Add(enumValue); await base.VisitEnumValue(enumValue, context); } - public override async ValueTask VisitStringValue(GraphQLScalarValue stringValue, CountContext context) + public override async ValueTask VisitStringValue(GraphQLStringValue stringValue, CountContext context) { context.VisitedStringValues.Add(stringValue); await base.VisitStringValue(stringValue, context); @@ -81,7 +81,7 @@ public override async ValueTask VisitField(GraphQLField field, CountContext cont await base.VisitField(field, context); } - public override async ValueTask VisitFloatValue(GraphQLScalarValue floatValue, CountContext context) + public override async ValueTask VisitFloatValue(GraphQLFloatValue floatValue, CountContext context) { context.VisitedFloatValues.Add(floatValue); await base.VisitFloatValue(floatValue, context); @@ -192,19 +192,19 @@ public class CountContext : INodeVisitorContext public List VisitedArguments = new(); public List VisitedDefinitions = new(); public List VisitedDirectives = new(); - public List VisitedEnumValues = new(); + public List VisitedEnumValues = new(); public List VisitedFields = new(); - public List VisitedFloatValues = new(); + public List VisitedFloatValues = new(); public List VisitedFragmentDefinitions = new(); public List VisitedFragmentSpreads = new(); public List VisitedFragmentTypeConditions = new(); public List VisitedInlineFragments = new(); - public List VisitedIntValues = new(); + public List VisitedIntValues = new(); public List VisitedNames = new(); public List VisitedSelectionSets = new(); - public List VisitedStringValues = new(); + public List VisitedStringValues = new(); public List VisitedVariables = new(); - public List VisitedBooleanValues = new(); + public List VisitedBooleanValues = new(); public CancellationToken CancellationToken { get; set; } } diff --git a/src/GraphQLParser/AST/GraphQLBooleanValue.cs b/src/GraphQLParser/AST/GraphQLBooleanValue.cs new file mode 100644 index 00000000..1a00ff7a --- /dev/null +++ b/src/GraphQLParser/AST/GraphQLBooleanValue.cs @@ -0,0 +1,56 @@ +namespace GraphQLParser.AST +{ + /// + /// AST node for . + /// + public class GraphQLBooleanValue : GraphQLValue + { + /// + public override ASTNodeKind Kind => ASTNodeKind.BooleanValue; + + /// + /// Value represented as . + /// + public ROM Value { get; set; } + } + + internal sealed class GraphQLBooleanValueWithLocation : GraphQLBooleanValue + { + private GraphQLLocation _location; + + public override GraphQLLocation Location + { + get => _location; + set => _location = value; + } + } + + internal sealed class GraphQLBooleanValueWithComment : GraphQLBooleanValue + { + private GraphQLComment? _comment; + + public override GraphQLComment? Comment + { + get => _comment; + set => _comment = value; + } + } + + internal sealed class GraphQLBooleanValueFull : GraphQLBooleanValue + { + private GraphQLLocation _location; + private GraphQLComment? _comment; + + public override GraphQLLocation Location + { + get => _location; + set => _location = value; + } + + public override GraphQLComment? Comment + { + get => _comment; + set => _comment = value; + } + } +} diff --git a/src/GraphQLParser/AST/GraphQLEnumValue.cs b/src/GraphQLParser/AST/GraphQLEnumValue.cs new file mode 100644 index 00000000..a9681888 --- /dev/null +++ b/src/GraphQLParser/AST/GraphQLEnumValue.cs @@ -0,0 +1,54 @@ +namespace GraphQLParser.AST +{ + /// + /// AST node for . + /// + public class GraphQLEnumValue : GraphQLValue, INamedNode + { + /// + public override ASTNodeKind Kind => ASTNodeKind.EnumValue; + + /// + public GraphQLName Name { get; set; } = null!; + } + + internal sealed class GraphQLEnumValueWithLocation : GraphQLEnumValue + { + private GraphQLLocation _location; + + public override GraphQLLocation Location + { + get => _location; + set => _location = value; + } + } + + internal sealed class GraphQLEnumValueWithComment : GraphQLEnumValue + { + private GraphQLComment? _comment; + + public override GraphQLComment? Comment + { + get => _comment; + set => _comment = value; + } + } + + internal sealed class GraphQLEnumValueFull : GraphQLEnumValue + { + private GraphQLLocation _location; + private GraphQLComment? _comment; + + public override GraphQLLocation Location + { + get => _location; + set => _location = value; + } + + public override GraphQLComment? Comment + { + get => _comment; + set => _comment = value; + } + } +} diff --git a/src/GraphQLParser/AST/GraphQLEnumValueDefinition.cs b/src/GraphQLParser/AST/GraphQLEnumValueDefinition.cs index 778dc6de..c328ec08 100644 --- a/src/GraphQLParser/AST/GraphQLEnumValueDefinition.cs +++ b/src/GraphQLParser/AST/GraphQLEnumValueDefinition.cs @@ -8,6 +8,13 @@ public class GraphQLEnumValueDefinition : GraphQLTypeDefinition, IHasDirectivesN /// public override ASTNodeKind Kind => ASTNodeKind.EnumValueDefinition; + /// + /// Enum value represented as a nested AST node. Alas, inherited + /// property holds almost + /// the same data and should be set as well. + /// + public GraphQLEnumValue EnumValue { get; set; } = null!; + /// public GraphQLDirectives? Directives { get; set; } } diff --git a/src/GraphQLParser/AST/GraphQLExecutableDefinition.cs b/src/GraphQLParser/AST/GraphQLExecutableDefinition.cs index 29135e46..d5a8077f 100644 --- a/src/GraphQLParser/AST/GraphQLExecutableDefinition.cs +++ b/src/GraphQLParser/AST/GraphQLExecutableDefinition.cs @@ -2,6 +2,7 @@ namespace GraphQLParser.AST { /// /// Base AST node for and . + ///
/// http://spec.graphql.org/October2021/#ExecutableDefinition ///
public abstract class GraphQLExecutableDefinition : ASTNode, IHasDirectivesNode diff --git a/src/GraphQLParser/AST/GraphQLFloatValue.cs b/src/GraphQLParser/AST/GraphQLFloatValue.cs new file mode 100644 index 00000000..629ad9e4 --- /dev/null +++ b/src/GraphQLParser/AST/GraphQLFloatValue.cs @@ -0,0 +1,56 @@ +namespace GraphQLParser.AST +{ + /// + /// AST node for . + /// + public class GraphQLFloatValue : GraphQLValue + { + /// + public override ASTNodeKind Kind => ASTNodeKind.BooleanValue; + + /// + /// Value represented as . + /// + public ROM Value { get; set; } + } + + internal sealed class GraphQLFloatValueWithLocation : GraphQLFloatValue + { + private GraphQLLocation _location; + + public override GraphQLLocation Location + { + get => _location; + set => _location = value; + } + } + + internal sealed class GraphQLFloatValueWithComment : GraphQLFloatValue + { + private GraphQLComment? _comment; + + public override GraphQLComment? Comment + { + get => _comment; + set => _comment = value; + } + } + + internal sealed class GraphQLFloatValueFull : GraphQLFloatValue + { + private GraphQLLocation _location; + private GraphQLComment? _comment; + + public override GraphQLLocation Location + { + get => _location; + set => _location = value; + } + + public override GraphQLComment? Comment + { + get => _comment; + set => _comment = value; + } + } +} diff --git a/src/GraphQLParser/AST/GraphQLIntValue.cs b/src/GraphQLParser/AST/GraphQLIntValue.cs new file mode 100644 index 00000000..ba200d85 --- /dev/null +++ b/src/GraphQLParser/AST/GraphQLIntValue.cs @@ -0,0 +1,56 @@ +namespace GraphQLParser.AST +{ + /// + /// AST node for . + /// + public class GraphQLIntValue : GraphQLValue + { + /// + public override ASTNodeKind Kind => ASTNodeKind.IntValue; + + /// + /// Value represented as . + /// + public ROM Value { get; set; } + } + + internal sealed class GraphQLIntValueWithLocation : GraphQLIntValue + { + private GraphQLLocation _location; + + public override GraphQLLocation Location + { + get => _location; + set => _location = value; + } + } + + internal sealed class GraphQLIntValueWithComment : GraphQLIntValue + { + private GraphQLComment? _comment; + + public override GraphQLComment? Comment + { + get => _comment; + set => _comment = value; + } + } + + internal sealed class GraphQLIntValueFull : GraphQLIntValue + { + private GraphQLLocation _location; + private GraphQLComment? _comment; + + public override GraphQLLocation Location + { + get => _location; + set => _location = value; + } + + public override GraphQLComment? Comment + { + get => _comment; + set => _comment = value; + } + } +} diff --git a/src/GraphQLParser/AST/GraphQLNullValue.cs b/src/GraphQLParser/AST/GraphQLNullValue.cs new file mode 100644 index 00000000..de4117e4 --- /dev/null +++ b/src/GraphQLParser/AST/GraphQLNullValue.cs @@ -0,0 +1,56 @@ +namespace GraphQLParser.AST +{ + /// + /// AST node for . + /// + public class GraphQLNullValue : GraphQLValue + { + /// + public override ASTNodeKind Kind => ASTNodeKind.NullValue; + + /// + /// Value represented as . + /// + public ROM Value { get; set; } + } + + internal sealed class GraphQLNullValueWithLocation : GraphQLNullValue + { + private GraphQLLocation _location; + + public override GraphQLLocation Location + { + get => _location; + set => _location = value; + } + } + + internal sealed class GraphQLNullValueWithComment : GraphQLNullValue + { + private GraphQLComment? _comment; + + public override GraphQLComment? Comment + { + get => _comment; + set => _comment = value; + } + } + + internal sealed class GraphQLNullValueFull : GraphQLNullValue + { + private GraphQLLocation _location; + private GraphQLComment? _comment; + + public override GraphQLLocation Location + { + get => _location; + set => _location = value; + } + + public override GraphQLComment? Comment + { + get => _comment; + set => _comment = value; + } + } +} diff --git a/src/GraphQLParser/AST/GraphQLObjectField.cs b/src/GraphQLParser/AST/GraphQLObjectField.cs index 56e0fba9..7764282a 100644 --- a/src/GraphQLParser/AST/GraphQLObjectField.cs +++ b/src/GraphQLParser/AST/GraphQLObjectField.cs @@ -11,7 +11,7 @@ public class GraphQLObjectField : ASTNode, INamedNode /// public GraphQLName Name { get; set; } = null!; - public GraphQLValue? Value { get; set; } + public GraphQLValue Value { get; set; } = null!; } internal sealed class GraphQLObjectFieldWithLocation : GraphQLObjectField diff --git a/src/GraphQLParser/AST/GraphQLScalarValue.cs b/src/GraphQLParser/AST/GraphQLScalarValue.cs deleted file mode 100644 index 4fae7501..00000000 --- a/src/GraphQLParser/AST/GraphQLScalarValue.cs +++ /dev/null @@ -1,102 +0,0 @@ -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("{Value}")] - public class GraphQLScalarValue : GraphQLValue - { - private readonly ASTNodeKind _kind; - - /// - /// 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; set; } - - /// - public override string? ToString() => Kind == ASTNodeKind.StringValue ? $"\"{Value}\"" : Value.ToString(); - } - - internal sealed class GraphQLScalarValueWithLocation : GraphQLScalarValue - { - private GraphQLLocation _location; - - public GraphQLScalarValueWithLocation(ASTNodeKind kind) - : base(kind) - { - } - - public override GraphQLLocation Location - { - get => _location; - set => _location = value; - } - } - - internal sealed class GraphQLScalarValueWithComment : GraphQLScalarValue - { - private GraphQLComment? _comment; - - public GraphQLScalarValueWithComment(ASTNodeKind kind) - : base(kind) - { - } - - public override GraphQLComment? Comment - { - get => _comment; - set => _comment = value; - } - } - - internal sealed class GraphQLScalarValueFull : GraphQLScalarValue - { - private GraphQLLocation _location; - private GraphQLComment? _comment; - - public GraphQLScalarValueFull(ASTNodeKind kind) - : base(kind) - { - } - - public override GraphQLLocation Location - { - get => _location; - set => _location = value; - } - - public override GraphQLComment? Comment - { - get => _comment; - set => _comment = value; - } - } -} diff --git a/src/GraphQLParser/AST/GraphQLStringValue.cs b/src/GraphQLParser/AST/GraphQLStringValue.cs new file mode 100644 index 00000000..9e4e2136 --- /dev/null +++ b/src/GraphQLParser/AST/GraphQLStringValue.cs @@ -0,0 +1,56 @@ +namespace GraphQLParser.AST +{ + /// + /// AST node for . + /// + public class GraphQLStringValue : GraphQLValue + { + /// + public override ASTNodeKind Kind => ASTNodeKind.StringValue; + + /// + /// Value represented as . + /// + public ROM Value { get; set; } + } + + internal sealed class GraphQLStringValueWithLocation : GraphQLStringValue + { + private GraphQLLocation _location; + + public override GraphQLLocation Location + { + get => _location; + set => _location = value; + } + } + + internal sealed class GraphQLStringValueWithComment : GraphQLStringValue + { + private GraphQLComment? _comment; + + public override GraphQLComment? Comment + { + get => _comment; + set => _comment = value; + } + } + + internal sealed class GraphQLStringValueFull : GraphQLStringValue + { + private GraphQLLocation _location; + private GraphQLComment? _comment; + + public override GraphQLLocation Location + { + get => _location; + set => _location = value; + } + + public override GraphQLComment? Comment + { + get => _comment; + set => _comment = value; + } + } +} diff --git a/src/GraphQLParser/AST/GraphQLValue.cs b/src/GraphQLParser/AST/GraphQLValue.cs index 8b154e9d..d16e80c2 100644 --- a/src/GraphQLParser/AST/GraphQLValue.cs +++ b/src/GraphQLParser/AST/GraphQLValue.cs @@ -1,15 +1,9 @@ namespace GraphQLParser.AST { /// - /// Base AST node for four value nodes: + /// Base AST node for all value nodes. ///
- /// Scalar - ///
- /// List - ///
- /// Object - ///
- /// Variable + /// ///
public abstract class GraphQLValue : ASTNode { diff --git a/src/GraphQLParser/NodeHelper.cs b/src/GraphQLParser/NodeHelper.cs index bcd0e0d2..cbd6b2df 100644 --- a/src/GraphQLParser/NodeHelper.cs +++ b/src/GraphQLParser/NodeHelper.cs @@ -95,18 +95,6 @@ public static GraphQLEnumTypeDefinition CreateGraphQLEnumTypeDefinition(IgnoreOp }; } - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public static GraphQLScalarValue CreateGraphQLScalarValue(IgnoreOptions options, ASTNodeKind kind) - { - return options switch - { - IgnoreOptions.All => new GraphQLScalarValue(kind), - IgnoreOptions.Comments => new GraphQLScalarValueWithLocation(kind), - IgnoreOptions.Locations => new GraphQLScalarValueWithComment(kind), - _ => new GraphQLScalarValueFull(kind), - }; - } - [MethodImpl(MethodImplOptions.AggressiveInlining)] public static GraphQLEnumValueDefinition CreateGraphQLEnumValueDefinition(IgnoreOptions options) { @@ -621,6 +609,72 @@ public static GraphQLUnionMemberTypes CreateGraphQLUnionMemberTypes(IgnoreOption }; } + public static GraphQLEnumValue CreateGraphQLEnumValue(IgnoreOptions options) + { + return options switch + { + IgnoreOptions.All => new GraphQLEnumValue(), + IgnoreOptions.Comments => new GraphQLEnumValueWithLocation(), + IgnoreOptions.Locations => new GraphQLEnumValueWithComment(), + _ => new GraphQLEnumValueFull(), + }; + } + + public static GraphQLNullValue CreateGraphQLNullValue(IgnoreOptions options) + { + return options switch + { + IgnoreOptions.All => new GraphQLNullValue(), + IgnoreOptions.Comments => new GraphQLNullValueWithLocation(), + IgnoreOptions.Locations => new GraphQLNullValueWithComment(), + _ => new GraphQLNullValueFull(), + }; + } + + public static GraphQLBooleanValue CreateGraphQLBooleanValue(IgnoreOptions options) + { + return options switch + { + IgnoreOptions.All => new GraphQLBooleanValue(), + IgnoreOptions.Comments => new GraphQLBooleanValueWithLocation(), + IgnoreOptions.Locations => new GraphQLBooleanValueWithComment(), + _ => new GraphQLBooleanValueFull(), + }; + } + + public static GraphQLFloatValue CreateGraphQLFloatValue(IgnoreOptions options) + { + return options switch + { + IgnoreOptions.All => new GraphQLFloatValue(), + IgnoreOptions.Comments => new GraphQLFloatValueWithLocation(), + IgnoreOptions.Locations => new GraphQLFloatValueWithComment(), + _ => new GraphQLFloatValueFull(), + }; + } + + public static GraphQLIntValue CreateGraphQLIntValue(IgnoreOptions options) + { + return options switch + { + IgnoreOptions.All => new GraphQLIntValue(), + IgnoreOptions.Comments => new GraphQLIntValueWithLocation(), + IgnoreOptions.Locations => new GraphQLIntValueWithComment(), + _ => new GraphQLIntValueFull(), + }; + } + + public static GraphQLStringValue CreateGraphQLStringValue(IgnoreOptions options) + { + return options switch + { + IgnoreOptions.All => new GraphQLStringValue(), + IgnoreOptions.Comments => new GraphQLStringValueWithLocation(), + IgnoreOptions.Locations => new GraphQLStringValueWithComment(), + _ => new GraphQLStringValueFull(), + }; + } + #endregion } } diff --git a/src/GraphQLParser/ParserContext.Parse.cs b/src/GraphQLParser/ParserContext.Parse.cs index 8e37d44a..685aa289 100644 --- a/src/GraphQLParser/ParserContext.Parse.cs +++ b/src/GraphQLParser/ParserContext.Parse.cs @@ -64,7 +64,7 @@ private GraphQLArgument ParseArgument() var arg = NodeHelper.CreateGraphQLArgument(_ignoreOptions); arg.Comment = GetComment(); - arg.Name = ParseName(); + arg.Name = ParseName("; for more information see http://spec.graphql.org/October2021/#Argument"); Expect(TokenKind.COLON); arg.Value = ParseValueLiteral(false); arg.Location = GetLocation(start); @@ -164,13 +164,14 @@ private GraphQLVariablesDefinition ParseVariablesDefinition() } // http://spec.graphql.org/October2021/#BooleanValue - private GraphQLValue ParseBooleanValue() + // There is no true/false value check, see calling method. + private GraphQLBooleanValue ParseBooleanValue() { IncreaseDepth(); var token = _currentToken; - var val = NodeHelper.CreateGraphQLScalarValue(_ignoreOptions, ASTNodeKind.BooleanValue); + var val = NodeHelper.CreateGraphQLBooleanValue(_ignoreOptions); val.Comment = GetComment(); Advance(); @@ -205,9 +206,9 @@ private ASTNode ParseDefinition() return Throw_Unexpected_Token(); } - private ASTNode Throw_Unexpected_Token() + private ASTNode Throw_Unexpected_Token(string? description = null) { - throw new GraphQLSyntaxErrorException($"Unexpected {_currentToken}", _source, _currentToken.Start); + throw new GraphQLSyntaxErrorException($"Unexpected {_currentToken}{description}", _source, _currentToken.Start); } private List ParseDefinitionsIfNotEOF() @@ -303,7 +304,7 @@ private GraphQLDirective ParseDirective() dir.Comment = GetComment(); Expect(TokenKind.AT); - dir.Name = ParseName(); + dir.Name = ParseName("; for more information see http://spec.graphql.org/October2021/#Directive"); dir.Arguments = Peek(TokenKind.PAREN_L) ? ParseArguments() : null; dir.Location = GetLocation(start); @@ -333,7 +334,7 @@ private GraphQLDirectiveDefinition ParseDirectiveDefinition() var def = NodeHelper.CreateGraphQLDirectiveDefinition(_ignoreOptions); - def.Name = ParseName(); + def.Name = ParseName("; for more information see http://spec.graphql.org/October2021/#DirectiveDefinition"); def.Arguments = Peek(TokenKind.PAREN_L) ? ParseArgumentsDefinition() : null; def.Repeatable = Peek(TokenKind.NAME) && ParseRepeatable(); ExpectKeyword("on"); @@ -357,7 +358,7 @@ private bool ParseRepeatable() return true; } - Throw_Unexpected_Token(); + Throw_Unexpected_Token("; did you miss 'repeatable'?"); return false; // for compiler } @@ -426,7 +427,7 @@ private GraphQLEnumTypeDefinition ParseEnumTypeDefinition() var def = NodeHelper.CreateGraphQLEnumTypeDefinition(_ignoreOptions); - def.Name = ParseName(); + def.Name = ParseName("; for more information see http://spec.graphql.org/October2021/#EnumTypeDefinition"); def.Directives = Peek(TokenKind.AT) ? ParseDirectives() : null; def.Values = Peek(TokenKind.BRACE_L) ? ParseEnumValuesDefinition() : null; def.Description = description; @@ -450,37 +451,48 @@ private GraphQLEnumTypeExtension ParseEnumTypeExtension() var extension = NodeHelper.CreateGraphQLEnumTypeExtension(_ignoreOptions); - extension.Name = ParseName(); + extension.Name = ParseName("; for more information see http://spec.graphql.org/October2021/#EnumTypeExtension"); extension.Directives = Peek(TokenKind.AT) ? ParseDirectives() : null; extension.Values = Peek(TokenKind.BRACE_L) ? ParseEnumValuesDefinition() : null; extension.Comment = comment; extension.Location = GetLocation(start); if (extension.Directives == null && extension.Values == null) - return (GraphQLEnumTypeExtension)Throw_Unexpected_Token(); + return (GraphQLEnumTypeExtension)Throw_Unexpected_Token("; for more information see http://spec.graphql.org/October2021/#EnumTypeExtension"); DecreaseDepth(); return extension; } // http://spec.graphql.org/October2021/#EnumValue - private GraphQLValue ParseEnumValue() // TODO: deal with enum value as ValueNode vs NameNode + private GraphQLEnumValue ParseEnumValue() { IncreaseDepth(); - var token = _currentToken; + int start = _currentToken.Start; - var val = NodeHelper.CreateGraphQLScalarValue(_ignoreOptions, ASTNodeKind.EnumValue); + var val = NodeHelper.CreateGraphQLEnumValue(_ignoreOptions); val.Comment = GetComment(); - Advance(); - val.Value = token.Value; - val.Location = GetLocation(token.Start); + val.Name = ParseEnumName(); + val.Location = GetLocation(start); DecreaseDepth(); return val; } + // Like ParseFragmentName but without special term in grammar. + // TODO: https://github.com/graphql/graphql-spec/issues/919 + private GraphQLName ParseEnumName() + { + if (_currentToken.Value == "true" || _currentToken.Value == "false" || _currentToken.Value == "null") + { + Throw_Unexpected_Token("; enum values are represented as unquoted names but not 'true' or 'false' or 'null'."); + } + + return ParseName("; for more information see http://spec.graphql.org/October2021/#EnumValue"); + } + // http://spec.graphql.org/October2021/#EnumValueDefinition private GraphQLEnumValueDefinition ParseEnumValueDefinition() { @@ -496,7 +508,8 @@ private GraphQLEnumValueDefinition ParseEnumValueDefinition() var def = NodeHelper.CreateGraphQLEnumValueDefinition(_ignoreOptions); def.Comment = GetComment(); - def.Name = ParseName(); + def.EnumValue = ParseEnumValue(); + def.Name = def.EnumValue.Name; // ATTENTION: should set Name property (inherited from GraphQLTypeDefinition) def.Directives = Peek(TokenKind.AT) ? ParseDirectives() : null; def.Description = description; def.Location = GetLocation(start); @@ -520,7 +533,7 @@ private GraphQLFieldDefinition ParseFieldDefinition() var def = NodeHelper.CreateGraphQLFieldDefinition(_ignoreOptions); def.Comment = GetComment(); - def.Name = ParseName(); + def.Name = ParseName("; for more information see http://spec.graphql.org/October2021/#FieldDefinition"); def.Arguments = Peek(TokenKind.PAREN_L) ? ParseArgumentsDefinition() : null; Expect(TokenKind.COLON); def.Type = ParseType(); @@ -542,7 +555,7 @@ private GraphQLField ParseField() int start = _currentToken.Start; var nameOrAliasComment = GetComment(); - var nameOrAlias = ParseName(); + var nameOrAlias = ParseName("; for more information see http://spec.graphql.org/October2021/#Field"); GraphQLName name; GraphQLName? alias; @@ -559,7 +572,7 @@ private GraphQLField ParseField() nameComment = GetComment(); aliasComment = nameOrAliasComment; - name = ParseName(); + name = ParseName("; for more information see http://spec.graphql.org/October2021/#Field"); alias = nameOrAlias; // TODO: should add Alias AST node + check depth } else @@ -595,13 +608,13 @@ private GraphQLField ParseField() } // http://spec.graphql.org/October2021/#FloatValue - private GraphQLValue ParseFloatValue(/*bool isConstant*/) + private GraphQLFloatValue ParseFloatValue(/*bool isConstant*/) { IncreaseDepth(); var token = _currentToken; - var val = NodeHelper.CreateGraphQLScalarValue(_ignoreOptions, ASTNodeKind.FloatValue); + var val = NodeHelper.CreateGraphQLFloatValue(_ignoreOptions); val.Comment = GetComment(); Advance(); @@ -682,10 +695,10 @@ private GraphQLName ParseFragmentName() { if (_currentToken.Value == "on") { - Throw_Unexpected_Token(); + Throw_Unexpected_Token("; fragment name can not be 'on'."); } - return ParseName(); + return ParseName("; for more information see http://spec.graphql.org/October2021/#FragmentName"); } // http://spec.graphql.org/October2021/#ImplementsInterfaces @@ -734,7 +747,7 @@ private GraphQLInputObjectTypeDefinition ParseInputObjectTypeDefinition() def.Comment = GetComment(); ExpectKeyword("input"); - def.Name = ParseName(); + def.Name = ParseName("; for more information see http://spec.graphql.org/October2021/#InputObjectTypeDefinition"); def.Directives = Peek(TokenKind.AT) ? ParseDirectives() : null; def.Fields = Peek(TokenKind.BRACE_L) ? ParseInputFieldsDefinition() : null; def.Description = description; @@ -756,13 +769,13 @@ private GraphQLInputObjectTypeExtension ParseInputObjectTypeExtension() extension.Comment = GetComment(); ExpectKeyword("input"); - extension.Name = ParseName(); + extension.Name = ParseName("; for more information see http://spec.graphql.org/October2021/#InputObjectTypeExtension"); extension.Directives = Peek(TokenKind.AT) ? ParseDirectives() : null; extension.Fields = Peek(TokenKind.BRACE_L) ? ParseInputFieldsDefinition() : null; extension.Location = GetLocation(start); if (extension.Directives == null && extension.Fields == null) - return (GraphQLInputObjectTypeExtension)Throw_Unexpected_Token(); + return (GraphQLInputObjectTypeExtension)Throw_Unexpected_Token("; for more information see http://spec.graphql.org/October2021/#InputObjectTypeExtension"); DecreaseDepth(); return extension; @@ -783,7 +796,7 @@ private GraphQLInputValueDefinition ParseInputValueDef() var def = NodeHelper.CreateGraphQLInputValueDefinition(_ignoreOptions); def.Comment = GetComment(); - def.Name = ParseName(); + def.Name = ParseName("; for more information see http://spec.graphql.org/October2021/#InputValueDefinition"); Expect(TokenKind.COLON); def.Type = ParseType(); def.DefaultValue = Skip(TokenKind.EQUALS) ? ParseValueLiteral(true) : null; @@ -796,13 +809,13 @@ private GraphQLInputValueDefinition ParseInputValueDef() } // http://spec.graphql.org/October2021/#IntValue - private GraphQLValue ParseIntValue(/*bool isConstant*/) + private GraphQLIntValue ParseIntValue(/*bool isConstant*/) { IncreaseDepth(); var token = _currentToken; - var val = NodeHelper.CreateGraphQLScalarValue(_ignoreOptions, ASTNodeKind.IntValue); + var val = NodeHelper.CreateGraphQLIntValue(_ignoreOptions); val.Comment = GetComment(); Advance(); @@ -829,7 +842,7 @@ private GraphQLInterfaceTypeDefinition ParseInterfaceTypeDefinition() def.Comment = GetComment(); ExpectKeyword("interface"); - def.Name = ParseName(); + def.Name = ParseName("; for more information see http://spec.graphql.org/October2021/#InterfaceTypeDefinition"); def.Interfaces = _currentToken.Value == "implements" ? ParseImplementsInterfaces() : null; def.Directives = Peek(TokenKind.AT) ? ParseDirectives() : null; def.Fields = Peek(TokenKind.BRACE_L) ? ParseFieldsDefinition() : null; @@ -852,14 +865,14 @@ private GraphQLInterfaceTypeExtension ParseInterfaceTypeExtension() extension.Comment = GetComment(); ExpectKeyword("interface"); - extension.Name = ParseName(); + extension.Name = ParseName("; for more information see http://spec.graphql.org/October2021/#InterfaceTypeExtension"); extension.Interfaces = _currentToken.Value == "implements" ? ParseImplementsInterfaces() : null; extension.Directives = Peek(TokenKind.AT) ? ParseDirectives() : null; extension.Fields = Peek(TokenKind.BRACE_L) ? ParseFieldsDefinition() : null; extension.Location = GetLocation(start); if (extension.Directives == null && extension.Fields == null && extension.Interfaces == null) - return (GraphQLInterfaceTypeExtension)Throw_Unexpected_Token(); + return (GraphQLInterfaceTypeExtension)Throw_Unexpected_Token("; for more information see http://spec.graphql.org/October2021/#InterfaceTypeExtension"); DecreaseDepth(); return extension; @@ -888,7 +901,7 @@ private GraphQLValue ParseListValue(bool isConstant) } // http://spec.graphql.org/October2021/#Name - private GraphQLName ParseName() + private GraphQLName ParseName(string description) { IncreaseDepth(); @@ -898,7 +911,7 @@ private GraphQLName ParseName() var name = NodeHelper.CreateGraphQLName(_ignoreOptions); name.Comment = GetComment(); - Expect(TokenKind.NAME); + Expect(TokenKind.NAME, description); name.Value = value; name.Location = GetLocation(start); @@ -983,7 +996,7 @@ private GraphQLNamedType ParseNamedType() var named = NodeHelper.CreateGraphQLNamedType(_ignoreOptions); named.Comment = GetComment(); - named.Name = ParseName(); + named.Name = ParseName("; for more information see http://spec.graphql.org/October2021/#NamedType"); named.Location = GetLocation(start); DecreaseDepth(); @@ -1032,7 +1045,7 @@ private GraphQLValue ParseNullValue() var token = _currentToken; - var val = NodeHelper.CreateGraphQLScalarValue(_ignoreOptions, ASTNodeKind.NullValue); + var val = NodeHelper.CreateGraphQLNullValue(_ignoreOptions); val.Comment = GetComment(); val.Value = token.Value; @@ -1053,7 +1066,7 @@ private GraphQLObjectField ParseObjectField(bool isConstant) var field = NodeHelper.CreateGraphQLObjectField(_ignoreOptions); field.Comment = GetComment(); - field.Name = ParseName(); + field.Name = ParseName("; for more information see http://spec.graphql.org/October2021/#ObjectField"); Expect(TokenKind.COLON); field.Value = ParseValueLiteral(isConstant); field.Location = GetLocation(start); @@ -1090,7 +1103,7 @@ private GraphQLObjectTypeDefinition ParseObjectTypeDefinition() def.Comment = GetComment(); ExpectKeyword("type"); - def.Name = ParseName(); + def.Name = ParseName("; for more information see http://spec.graphql.org/October2021/#ObjectTypeDefinition"); def.Interfaces = _currentToken.Value == "implements" ? ParseImplementsInterfaces() : null; def.Directives = Peek(TokenKind.AT) ? ParseDirectives() : null; def.Fields = Peek(TokenKind.BRACE_L) ? ParseFieldsDefinition() : null; @@ -1113,14 +1126,14 @@ private GraphQLObjectTypeExtension ParseObjectTypeExtension() extension.Comment = GetComment(); ExpectKeyword("type"); - extension.Name = ParseName(); + extension.Name = ParseName("; for more information see http://spec.graphql.org/October2021/#ObjectTypeExtension"); extension.Interfaces = _currentToken.Value == "implements" ? ParseImplementsInterfaces() : null; extension.Directives = Peek(TokenKind.AT) ? ParseDirectives() : null; extension.Fields = Peek(TokenKind.BRACE_L) ? ParseFieldsDefinition() : null; extension.Location = GetLocation(start); if (extension.Directives == null && extension.Fields == null && extension.Interfaces == null) - return (GraphQLObjectTypeExtension)Throw_Unexpected_Token(); + return (GraphQLObjectTypeExtension)Throw_Unexpected_Token("; for more information see http://spec.graphql.org/October2021/#ObjectTypeExtension"); DecreaseDepth(); return extension; @@ -1146,7 +1159,7 @@ private ASTNode ParseOperationDefinition() else { def.Operation = ParseOperationType(); - def.Name = Peek(TokenKind.NAME) ? ParseName() : null; // Peek(TokenKind.NAME) because of anonymous query + def.Name = Peek(TokenKind.NAME) ? ParseName("; for more information see http://spec.graphql.org/October2021/#OperationDefinition") : null; // Peek(TokenKind.NAME) because of anonymous query def.Variables = Peek(TokenKind.PAREN_L) ? ParseVariablesDefinition() : null; def.Directives = Peek(TokenKind.AT) ? ParseDirectives() : null; def.SelectionSet = ParseSelectionSet(); @@ -1237,7 +1250,7 @@ private GraphQLScalarTypeDefinition ParseScalarTypeDefinition() def.Comment = GetComment(); ExpectKeyword("scalar"); - def.Name = ParseName(); + def.Name = ParseName("; for more information see http://spec.graphql.org/October2021/#ScalarTypeDefinition"); def.Directives = Peek(TokenKind.AT) ? ParseDirectives() : null; def.Description = description; def.Location = GetLocation(start); @@ -1258,12 +1271,12 @@ private GraphQLScalarTypeExtension ParseScalarTypeExtension() extension.Comment = GetComment(); ExpectKeyword("scalar"); - extension.Name = ParseName(); + extension.Name = ParseName("; for more information see http://spec.graphql.org/October2021/#ScalarTypeExtension"); extension.Directives = Peek(TokenKind.AT) ? ParseDirectives() : null; extension.Location = GetLocation(start); if (extension.Directives == null) - return (GraphQLScalarTypeExtension)Throw_Unexpected_Token(); + return (GraphQLScalarTypeExtension)Throw_Unexpected_Token("; for more information see http://spec.graphql.org/October2021/#ScalarTypeExtension"); DecreaseDepth(); return extension; @@ -1320,13 +1333,13 @@ private GraphQLSelectionSet ParseSelectionSet() } // http://spec.graphql.org/October2021/#StringValue - private GraphQLScalarValue ParseStringValue(/*bool isConstant*/) + private GraphQLStringValue ParseStringValue(/*bool isConstant*/) { IncreaseDepth(); var token = _currentToken; - var val = NodeHelper.CreateGraphQLScalarValue(_ignoreOptions, ASTNodeKind.StringValue); + var val = NodeHelper.CreateGraphQLStringValue(_ignoreOptions); val.Comment = GetComment(); Advance(); @@ -1424,7 +1437,7 @@ private GraphQLTypeExtension ParseTypeExtension() if (value == "input") return ParseInputObjectTypeExtension(); - return (GraphQLTypeExtension)Throw_Unexpected_Token(); + return (GraphQLTypeExtension)Throw_Unexpected_Token("; for more information see http://spec.graphql.org/October2021/#TypeExtension"); } // http://spec.graphql.org/October2021/#UnionMemberTypes @@ -1473,7 +1486,7 @@ private GraphQLUnionTypeDefinition ParseUnionTypeDefinition() def.Comment = GetComment(); ExpectKeyword("union"); - def.Name = ParseName(); + def.Name = ParseName("; for more information see http://spec.graphql.org/October2021/#UnionTypeDefinition"); def.Directives = Peek(TokenKind.AT) ? ParseDirectives() : null; def.Types = Peek(TokenKind.EQUALS) ? ParseUnionMemberTypes() : null; def.Description = description; @@ -1495,13 +1508,13 @@ private GraphQLUnionTypeExtension ParseUnionTypeExtension() extension.Comment = GetComment(); ExpectKeyword("union"); - extension.Name = ParseName(); + extension.Name = ParseName("; for more information see http://spec.graphql.org/October2021/#UnionTypeExtension"); extension.Directives = Peek(TokenKind.AT) ? ParseDirectives() : null; extension.Types = Peek(TokenKind.EQUALS) ? ParseUnionMemberTypes() : null; extension.Location = GetLocation(start); if (extension.Directives == null && extension.Types == null) - return (GraphQLUnionTypeExtension)Throw_Unexpected_Token(); + return (GraphQLUnionTypeExtension)Throw_Unexpected_Token("; for more information see http://spec.graphql.org/October2021/#UnionTypeExtension"); DecreaseDepth(); return extension; @@ -1533,7 +1546,7 @@ private GraphQLVariable ParseVariable() variable.Comment = GetComment(); Expect(TokenKind.DOLLAR); - variable.Name = ParseName(); + variable.Name = ParseName("; for more information see http://spec.graphql.org/October2021/#Variable"); variable.Location = GetLocation(start); DecreaseDepth(); diff --git a/src/GraphQLParser/ParserContext.cs b/src/GraphQLParser/ParserContext.cs index d31faa29..37ee2148 100644 --- a/src/GraphQLParser/ParserContext.cs +++ b/src/GraphQLParser/ParserContext.cs @@ -166,7 +166,7 @@ private void Advance(bool fromParseComment = false) } } - private void Expect(TokenKind kind) + private void Expect(TokenKind kind, string? description = null) { if (_currentToken.Kind == kind) { @@ -174,13 +174,13 @@ private void Expect(TokenKind kind) } else { - Throw_From_Expect(kind); + Throw_From_Expect(kind, description); } } - private void Throw_From_Expect(TokenKind kind) + private void Throw_From_Expect(TokenKind kind, string? description = null) { - throw new GraphQLSyntaxErrorException($"Expected {Token.GetTokenKindDescription(kind)}, found {_currentToken}", _source, _currentToken.Start); + throw new GraphQLSyntaxErrorException($"Expected {Token.GetTokenKindDescription(kind)}, found {_currentToken}{description}", _source, _currentToken.Start); } private void ExpectKeyword(string keyword) diff --git a/src/GraphQLParser/Visitors/DefaultNodeVisitor.cs b/src/GraphQLParser/Visitors/DefaultNodeVisitor.cs index 3b0df0c1..07581bb5 100644 --- a/src/GraphQLParser/Visitors/DefaultNodeVisitor.cs +++ b/src/GraphQLParser/Visitors/DefaultNodeVisitor.cs @@ -158,33 +158,34 @@ public virtual async ValueTask VisitFragmentDefinition(GraphQLFragmentDefinition } /// - public virtual async ValueTask VisitIntValue(GraphQLScalarValue intValue, TContext context) + public virtual async ValueTask VisitIntValue(GraphQLIntValue intValue, TContext context) { await Visit(intValue.Comment, context).ConfigureAwait(false); } /// - public virtual async ValueTask VisitFloatValue(GraphQLScalarValue floatValue, TContext context) + public virtual async ValueTask VisitFloatValue(GraphQLFloatValue floatValue, TContext context) { await Visit(floatValue.Comment, context).ConfigureAwait(false); } /// - public virtual async ValueTask VisitStringValue(GraphQLScalarValue stringValue, TContext context) + public virtual async ValueTask VisitStringValue(GraphQLStringValue stringValue, TContext context) { await Visit(stringValue.Comment, context).ConfigureAwait(false); } /// - public virtual async ValueTask VisitBooleanValue(GraphQLScalarValue booleanValue, TContext context) + public virtual async ValueTask VisitBooleanValue(GraphQLBooleanValue booleanValue, TContext context) { await Visit(booleanValue.Comment, context).ConfigureAwait(false); } /// - public virtual async ValueTask VisitEnumValue(GraphQLScalarValue enumValue, TContext context) + public virtual async ValueTask VisitEnumValue(GraphQLEnumValue enumValue, TContext context) { await Visit(enumValue.Comment, context).ConfigureAwait(false); + await Visit(enumValue.Name, context).ConfigureAwait(false); } /// @@ -245,7 +246,7 @@ public virtual async ValueTask VisitNonNullType(GraphQLNonNullType nonNullType, } /// - public virtual async ValueTask VisitNullValue(GraphQLScalarValue nullValue, TContext context) + public virtual async ValueTask VisitNullValue(GraphQLNullValue nullValue, TContext context) { await Visit(nullValue.Comment, context).ConfigureAwait(false); } @@ -362,7 +363,7 @@ public virtual async ValueTask VisitEnumValueDefinition(GraphQLEnumValueDefiniti { await Visit(enumValueDefinition.Comment, context).ConfigureAwait(false); await Visit(enumValueDefinition.Description, context).ConfigureAwait(false); - await Visit(enumValueDefinition.Name, context).ConfigureAwait(false); + await Visit(enumValueDefinition.EnumValue, context).ConfigureAwait(false); await Visit(enumValueDefinition.Directives, context).ConfigureAwait(false); } @@ -496,16 +497,12 @@ public virtual ValueTask Visit(ASTNode? node, TContext context) GraphQLOperationDefinition operationDefinition => VisitOperationDefinition(operationDefinition, context), GraphQLRootOperationTypeDefinition rootOperationTypeDefinition => VisitRootOperationTypeDefinition(rootOperationTypeDefinition, context), GraphQLScalarTypeDefinition scalarTypeDefinition => VisitScalarTypeDefinition(scalarTypeDefinition, context), - GraphQLScalarValue scalarValue => scalarValue.Kind switch - { - ASTNodeKind.BooleanValue => VisitBooleanValue(scalarValue, context), - ASTNodeKind.EnumValue => VisitEnumValue(scalarValue, context), - ASTNodeKind.FloatValue => VisitFloatValue(scalarValue, context), - ASTNodeKind.IntValue => VisitIntValue(scalarValue, context), - ASTNodeKind.NullValue => VisitNullValue(scalarValue, context), - ASTNodeKind.StringValue => VisitStringValue(scalarValue, context), - _ => throw new NotSupportedException($"Unknown GraphQLScalarValue of kind '{scalarValue.Kind}'."), - }, + GraphQLBooleanValue boolValue => VisitBooleanValue(boolValue, context), + GraphQLEnumValue enumValue => VisitEnumValue(enumValue, context), + GraphQLFloatValue floatValue => VisitFloatValue(floatValue, context), + GraphQLIntValue intValue => VisitIntValue(intValue, context), + GraphQLNullValue nullValue => VisitNullValue(nullValue, context), + GraphQLStringValue stringValue => VisitStringValue(stringValue, context), GraphQLSchemaDefinition schemaDefinition => VisitSchemaDefinition(schemaDefinition, context), GraphQLSelectionSet selectionSet => VisitSelectionSet(selectionSet, context), GraphQLScalarTypeExtension scalarEx => VisitScalarTypeExtension(scalarEx, context), diff --git a/src/GraphQLParser/Visitors/INodeVisitor.cs b/src/GraphQLParser/Visitors/INodeVisitor.cs index 6aaa357a..6d12e3e5 100644 --- a/src/GraphQLParser/Visitors/INodeVisitor.cs +++ b/src/GraphQLParser/Visitors/INodeVisitor.cs @@ -81,29 +81,29 @@ public interface INodeVisitor ValueTask VisitFragmentDefinition(GraphQLFragmentDefinition fragmentDefinition, TContext context); /// - /// Visits node. + /// Visits node. /// - ValueTask VisitIntValue(GraphQLScalarValue intValue, TContext context); + ValueTask VisitIntValue(GraphQLIntValue intValue, TContext context); /// - /// Visits node. + /// Visits node. /// - ValueTask VisitFloatValue(GraphQLScalarValue floatValue, TContext context); + ValueTask VisitFloatValue(GraphQLFloatValue floatValue, TContext context); /// - /// Visits node. + /// Visits node. /// - ValueTask VisitStringValue(GraphQLScalarValue stringValue, TContext context); + ValueTask VisitStringValue(GraphQLStringValue stringValue, TContext context); /// - /// Visits node. + /// Visits node. /// - ValueTask VisitBooleanValue(GraphQLScalarValue booleanValue, TContext context); + ValueTask VisitBooleanValue(GraphQLBooleanValue booleanValue, TContext context); /// - /// Visits node. + /// Visits node. /// - ValueTask VisitEnumValue(GraphQLScalarValue enumValue, TContext context); + ValueTask VisitEnumValue(GraphQLEnumValue enumValue, TContext context); /// /// Visits node. @@ -146,9 +146,9 @@ public interface INodeVisitor ValueTask VisitNonNullType(GraphQLNonNullType nonNullType, TContext context); /// - /// Visits node. + /// Visits node. /// - ValueTask VisitNullValue(GraphQLScalarValue nullValue, TContext context); + ValueTask VisitNullValue(GraphQLNullValue nullValue, TContext context); /// /// Visits node. diff --git a/src/GraphQLParser/Visitors/SDLWriter.cs b/src/GraphQLParser/Visitors/SDLWriter.cs index 027acffb..d8dddc32 100644 --- a/src/GraphQLParser/Visitors/SDLWriter.cs +++ b/src/GraphQLParser/Visitors/SDLWriter.cs @@ -359,7 +359,7 @@ public override async ValueTask VisitVariable(GraphQLVariable variable, TContext } /// - public override async ValueTask VisitBooleanValue(GraphQLScalarValue booleanValue, TContext context) + public override async ValueTask VisitBooleanValue(GraphQLBooleanValue booleanValue, TContext context) { await Visit(booleanValue.Comment, context).ConfigureAwait(false); await context.Write(booleanValue.Value).ConfigureAwait(false); @@ -750,38 +750,38 @@ public override async ValueTask VisitListValue(GraphQLListValue listValue, TCont } /// - public override async ValueTask VisitNullValue(GraphQLScalarValue nullValue, TContext context) + public override async ValueTask VisitNullValue(GraphQLNullValue nullValue, TContext context) { await Visit(nullValue.Comment, context).ConfigureAwait(false); await context.Write("null").ConfigureAwait(false); } /// - public override async ValueTask VisitStringValue(GraphQLScalarValue stringValue, TContext context) + public override async ValueTask VisitStringValue(GraphQLStringValue stringValue, TContext context) { await Visit(stringValue.Comment, context).ConfigureAwait(false); await WriteEncodedString(context, stringValue.Value); } /// - public override async ValueTask VisitIntValue(GraphQLScalarValue intValue, TContext context) + public override async ValueTask VisitIntValue(GraphQLIntValue intValue, TContext context) { await Visit(intValue.Comment, context).ConfigureAwait(false); await context.Write(intValue.Value).ConfigureAwait(false); } /// - public override async ValueTask VisitFloatValue(GraphQLScalarValue floatValue, TContext context) + public override async ValueTask VisitFloatValue(GraphQLFloatValue floatValue, TContext context) { await Visit(floatValue.Comment, context).ConfigureAwait(false); await context.Write(floatValue.Value).ConfigureAwait(false); } /// - public override async ValueTask VisitEnumValue(GraphQLScalarValue enumValue, TContext context) + public override async ValueTask VisitEnumValue(GraphQLEnumValue enumValue, TContext context) { await Visit(enumValue.Comment, context).ConfigureAwait(false); - await context.Write(enumValue.Value).ConfigureAwait(false); + await Visit(enumValue.Name, context).ConfigureAwait(false); } ///