public FragmentDefinitionNode( Location location, NameNode name, IReadOnlyCollection <VariableDefinitionNode> variableDefinitions, NamedTypeNode typeCondition, IReadOnlyCollection <DirectiveNode> directives, SelectionSetNode selectionSet) : base(location, name, directives) { if (variableDefinitions == null) { throw new ArgumentNullException(nameof(variableDefinitions)); } if (typeCondition == null) { throw new ArgumentNullException(nameof(typeCondition)); } if (selectionSet == null) { throw new ArgumentNullException(nameof(selectionSet)); } VariableDefinitions = variableDefinitions; TypeCondition = typeCondition; SelectionSet = selectionSet; }
public InlineFragmentNode WithTypeCondition( NamedTypeNode typeCondition) { return(new InlineFragmentNode( Location, typeCondition, Directives, SelectionSet)); }
public virtual VisitorAction Leave( NamedTypeNode node, ISyntaxNode parent, IReadOnlyList <object> path, IReadOnlyList <ISyntaxNode> ancestors) { return(GetDefaultAction(node.Kind)); }
public FragmentDefinitionNode WithTypeCondition( NamedTypeNode typeCondition) { return(new FragmentDefinitionNode( Location, Name, VariableDefinitions, typeCondition, Directives, SelectionSet)); }
public OperationTypeDefinitionNode( Location?location, OperationType operation, NamedTypeNode type) { Location = location; Operation = operation; Type = type ?? throw new ArgumentNullException(nameof(type)); }
protected virtual void ResolveChildren( NamedTypeNode node, IList <SyntaxNodeInfo> children) { ResolveChildren( nameof(node.Name), node.Name, children); }
public void NamedType_ExtractType_ExtractSuccessfull(string fieldType) { // arrange ITypeNode type = GetType(fieldType); // act NamedTypeNode name = type.NamedType(); // assert Assert.Equal("Foo", name.Print()); }
public void Create_With_Type() { // arrange var namedType = new NamedTypeNode("abc"); // act var type = new NonNullTypeNode(namedType); // assert Assert.Equal(namedType, type.Type); }
protected virtual NamedTypeNode RewriteNamedType( NamedTypeNode node, TContext context) { NamedTypeNode current = node; current = Rewrite(current, node.Name, context, RewriteName, current.WithName); return(current); }
public void Create_With_Location_And_Type_Where_Location_Is_Null() { // arrange var namedType = new NamedTypeNode("abc"); // act var type = new NonNullTypeNode(null, namedType); // assert Assert.Null(type.Location); Assert.Equal(namedType, type.Type); }
/// <summary> /// Parses a fragment definition. /// <see cref="FragmentDefinitionNode" />: /// fragment FragmentName on TypeCondition Directives? SelectionSet /// </summary> /// <param name="context">The parser context.</param> private static FragmentDefinitionNode ParseFragmentDefinition( ParserContext context) { SyntaxToken start = context.Current; context.ExpectFragmentKeyword(); // Experimental support for defining variables within fragments // changesthe grammar of FragmentDefinition: // fragment FragmentName VariableDefinitions? on TypeCondition Directives? SelectionSet if (context.Options.Experimental.AllowFragmentVariables) { NameNode name = ParseFragmentName(context); List <VariableDefinitionNode> variableDefinitions = ParseVariableDefinitions(context); context.ExpectOnKeyword(); NamedTypeNode typeCondition = ParseNamedType(context); List <DirectiveNode> directives = ParseDirectives(context, false); SelectionSetNode selectionSet = ParseSelectionSet(context); Location location = context.CreateLocation(start); return(new FragmentDefinitionNode ( location, name, variableDefinitions, typeCondition, directives, selectionSet )); } else { NameNode name = ParseFragmentName(context); context.ExpectOnKeyword(); NamedTypeNode typeCondition = ParseNamedType(context); List <DirectiveNode> directives = ParseDirectives(context, false); SelectionSetNode selectionSet = ParseSelectionSet(context); Location location = context.CreateLocation(start); return(new FragmentDefinitionNode ( location, name, Array.Empty <VariableDefinitionNode>(), typeCondition, directives, selectionSet )); } }
public void InnerTypeFromListType() { // arrange var namedType = new NamedTypeNode(null, new NameNode("Foo")); var listType = new ListTypeNode(null, namedType); // act ITypeNode innerType = listType.InnerType(); // assert Assert.Equal(namedType, innerType); }
public InlineFragmentNode( Location location, NamedTypeNode typeCondition, IReadOnlyList <DirectiveNode> directives, SelectionSetNode selectionSet) { Location = location; TypeCondition = typeCondition; Directives = directives ?? throw new ArgumentNullException(nameof(directives)); SelectionSet = selectionSet ?? throw new ArgumentNullException(nameof(selectionSet)); }
public void WithType_Where_Type_Is_Null() { // arrange var location = new Location(1, 1, 1, 1); var initialType = new NamedTypeNode("abc"); var type = new NonNullTypeNode(location, initialType); // act Action action = () => type.WithType(null); // assert Assert.Throws <ArgumentNullException>(action); }
public void Create_With_Location_And_Type() { // arrange var location = new Location(1, 1, 1, 1); var namedType = new NamedTypeNode("abc"); // act var type = new NonNullTypeNode(location, namedType); // assert Assert.Equal(location, type.Location); Assert.Equal(namedType, type.Type); }
/// <summary> /// Parses a fragment definition. /// <see cref="FragmentDefinitionNode" />: /// fragment FragmentName on TypeCondition Directives? SelectionSet /// </summary> /// <param name="context">The parser context.</param> private FragmentDefinitionNode ParseFragmentDefinition() { TokenInfo start = Start(); ExpectFragmentKeyword(); // Experimental support for defining variables within fragments // changesthe grammar of FragmentDefinition: // fragment FragmentName VariableDefinitions? on // TypeCondition Directives? SelectionSet if (_allowFragmentVars) { NameNode name = ParseFragmentName(); List <VariableDefinitionNode> variableDefinitions = ParseVariableDefinitions(); ExpectOnKeyword(); NamedTypeNode typeCondition = ParseNamedType(); List <DirectiveNode> directives = ParseDirectives(false); SelectionSetNode selectionSet = ParseSelectionSet(); Location location = CreateLocation(in start); return(new FragmentDefinitionNode ( location, name, variableDefinitions, typeCondition, directives, selectionSet )); } else { NameNode name = ParseFragmentName(); ExpectOnKeyword(); NamedTypeNode typeCondition = ParseNamedType(); List <DirectiveNode> directives = ParseDirectives(false); SelectionSetNode selectionSet = ParseSelectionSet(); Location location = CreateLocation(in start); return(new FragmentDefinitionNode ( location, name, Array.Empty <VariableDefinitionNode>(), typeCondition, directives, selectionSet )); } }
public void NamedTypeFromNonNullList() { // arrange var namedType = new NamedTypeNode(null, new NameNode("Foo")); var listType = new ListTypeNode(null, new NonNullTypeNode(null, namedType)); var nonNullType = new NonNullTypeNode(null, listType); // act NamedTypeNode retrievedNamedType = nonNullType.NamedType(); // assert Assert.Equal(namedType, retrievedNamedType); }
public void NullableType() { // arrange var namedType = new NamedTypeNode(null, new NameNode("Foo")); var nonNullType = new NonNullTypeNode(null, namedType); // act ITypeNode a = nonNullType.NullableType(); ITypeNode b = namedType.NullableType(); // assert Assert.Equal(namedType, a); Assert.Equal(namedType, b); }
public void InvalidTypeStructure() { // arrange var namedType = new NamedTypeNode(null, new NameNode("Foo")); var listType = new ListTypeNode(null, new ListTypeNode(null, new NonNullTypeNode(null, namedType))); var nonNullType = new NonNullTypeNode(null, listType); // act Action a = () => nonNullType.NamedType(); // assert Assert.Throws <NotSupportedException>(a); }
public void WithLocation_Where_Location_Is_Null() { // arrange var initialLocation = new Location(1, 1, 1, 1); var namedType = new NamedTypeNode("abc"); var type = new NonNullTypeNode(initialLocation, namedType); // act type = type.WithLocation(null); // assert Assert.Null(type.Location); Assert.Equal(namedType, type.Type); }
public void IsNonNullType() { // arrange var namedType = new NamedTypeNode(null, new NameNode("Foo")); var nonNullType = new NonNullTypeNode(null, namedType); // act bool shouldBeFalse = namedType.IsNonNullType(); bool shouldBeTrue = nonNullType.IsNonNullType(); // assert Assert.False(shouldBeFalse); Assert.True(shouldBeTrue); }
public void WithType() { // arrange var location = new Location(1, 1, 1, 1); var initialType = new NamedTypeNode("abc"); var type = new NonNullTypeNode(location, initialType); // act var newType = new NamedTypeNode("def"); type = type.WithType(newType); // assert Assert.Equal(location, type.Location); Assert.Equal(newType, type.Type); }
public void WithLocation() { // arrange var initialLocation = new Location(1, 1, 1, 1); var namedType = new NamedTypeNode("abc"); var type = new NonNullTypeNode(initialLocation, namedType); // act var newLocation = new Location(2, 2, 2, 2); type = type.WithLocation(newLocation); // assert Assert.Equal(newLocation, type.Location); Assert.Equal(namedType, type.Type); }
public FragmentDefinitionNode( Location location, NameNode name, IReadOnlyList <VariableDefinitionNode> variableDefinitions, NamedTypeNode typeCondition, IReadOnlyList <DirectiveNode> directives, SelectionSetNode selectionSet) : base(location, name, directives) { VariableDefinitions = variableDefinitions ?? throw new ArgumentNullException(nameof(variableDefinitions)); TypeCondition = typeCondition ?? throw new ArgumentNullException(nameof(typeCondition)); SelectionSet = selectionSet ?? throw new ArgumentNullException(nameof(selectionSet)); }
/// <summary> /// Parses an operation type definition. /// <see cref="OperationTypeDefinitionNode" />: /// OperationType : NamedType /// </summary> /// <param name="context">The parser context.</param> private OperationTypeDefinitionNode ParseOperationTypeDefinition( ParserContext context) { SyntaxToken start = context.Current; OperationType operation = ParseOperationType(context); context.ExpectColon(); NamedTypeNode type = ParseNamedType(context); Location location = context.CreateLocation(start); return(new OperationTypeDefinitionNode ( location, operation, type )); }
/// <summary> /// Parses an inline fragment. /// <see cref="FragmentSpreadNode" />: /// ... TypeCondition? Directives? SelectionSet /// </summary> /// <param name="context">The parser context.</param> /// <param name="start">The start token of the current fragment node.</param> /// <param name="typeCondition">The fragment type condition.</param> private InlineFragmentNode ParseInlineFragment( ParserContext context, SyntaxToken start, NamedTypeNode typeCondition) { List <DirectiveNode> directives = ParseDirectives(context, false); SelectionSetNode selectionSet = ParseSelectionSet(context); Location location = context.CreateLocation(start); return(new InlineFragmentNode ( location, typeCondition, directives, selectionSet )); }
/// <summary> /// Parses an operation type definition. /// <see cref="OperationTypeDefinitionNode" />: /// OperationType : NamedType /// </summary> /// <param name="context">The parser context.</param> private OperationTypeDefinitionNode ParseOperationTypeDefinition() { TokenInfo start = Start(); OperationType operation = ParseOperationType(); ExpectColon(); NamedTypeNode type = ParseNamedType(); Location location = CreateLocation(in start); return(new OperationTypeDefinitionNode ( location, operation, type )); }
public InlineFragmentNode( Location location, NamedTypeNode typeCondition, IReadOnlyCollection <DirectiveNode> directives, SelectionSetNode selectionSet) { if (directives == null) { throw new ArgumentNullException(nameof(directives)); } if (selectionSet == null) { throw new ArgumentNullException(nameof(selectionSet)); } Location = location; TypeCondition = typeCondition; Directives = directives; SelectionSet = selectionSet; }
private ISelectionNode ParseFragment() { TokenInfo start = Start(); ExpectSpread(); var isOnKeyword = _reader.Value.SequenceEqual(GraphQLKeywords.On); if (!isOnKeyword && _reader.Kind == TokenKind.Name) { return(ParseFragmentSpread(in start)); } NamedTypeNode typeCondition = null; if (isOnKeyword) { MoveNext(); typeCondition = ParseNamedType(); } return(ParseInlineFragment(in start, typeCondition)); }
/// <summary> /// Parses a fragment spred or inline fragment within a selection set. /// <see cref="ParseFragmentSpread" /> and /// <see cref="ParseInlineFragment" />. /// </summary> /// <param name="context">The parser context.</param> private static ISelectionNode ParseFragment(ParserContext context) { SyntaxToken start = context.Current; context.ExpectSpread(); var isOnKeyword = context.Current.IsOnKeyword(); if (!isOnKeyword && context.Current.IsName()) { return(ParseFragmentSpread(context, start)); } NamedTypeNode typeCondition = null; if (isOnKeyword) { context.MoveNext(); typeCondition = ParseNamedType(context); } return(ParseInlineFragment(context, start, typeCondition)); }