Ejemplo n.º 1
0
        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;
        }
Ejemplo n.º 2
0
 public InlineFragmentNode WithTypeCondition(
     NamedTypeNode typeCondition)
 {
     return(new InlineFragmentNode(
                Location, typeCondition,
                Directives, SelectionSet));
 }
Ejemplo n.º 3
0
 public virtual VisitorAction Leave(
     NamedTypeNode node,
     ISyntaxNode parent,
     IReadOnlyList <object> path,
     IReadOnlyList <ISyntaxNode> ancestors)
 {
     return(GetDefaultAction(node.Kind));
 }
Ejemplo n.º 4
0
 public FragmentDefinitionNode WithTypeCondition(
     NamedTypeNode typeCondition)
 {
     return(new FragmentDefinitionNode(
                Location, Name,
                VariableDefinitions,
                typeCondition,
                Directives, SelectionSet));
 }
Ejemplo n.º 5
0
 public OperationTypeDefinitionNode(
     Location?location,
     OperationType operation,
     NamedTypeNode type)
 {
     Location  = location;
     Operation = operation;
     Type      = type ?? throw new ArgumentNullException(nameof(type));
 }
Ejemplo n.º 6
0
 protected virtual void ResolveChildren(
     NamedTypeNode node,
     IList <SyntaxNodeInfo> children)
 {
     ResolveChildren(
         nameof(node.Name),
         node.Name,
         children);
 }
Ejemplo n.º 7
0
        public void NamedType_ExtractType_ExtractSuccessfull(string fieldType)
        {
            // arrange
            ITypeNode type = GetType(fieldType);

            // act
            NamedTypeNode name = type.NamedType();

            // assert
            Assert.Equal("Foo", name.Print());
        }
Ejemplo n.º 8
0
        public void Create_With_Type()
        {
            // arrange
            var namedType = new NamedTypeNode("abc");

            // act
            var type = new NonNullTypeNode(namedType);

            // assert
            Assert.Equal(namedType, type.Type);
        }
Ejemplo n.º 9
0
        protected virtual NamedTypeNode RewriteNamedType(
            NamedTypeNode node,
            TContext context)
        {
            NamedTypeNode current = node;

            current = Rewrite(current, node.Name, context,
                              RewriteName, current.WithName);

            return(current);
        }
Ejemplo n.º 10
0
        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);
        }
Ejemplo n.º 11
0
        /// <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);
        }
Ejemplo n.º 13
0
 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));
 }
Ejemplo n.º 14
0
        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);
        }
Ejemplo n.º 15
0
        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);
        }
Ejemplo n.º 20
0
        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);
        }
Ejemplo n.º 22
0
        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);
        }
Ejemplo n.º 23
0
        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);
        }
Ejemplo n.º 24
0
 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));
 }
Ejemplo n.º 25
0
        /// <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
                   ));
        }
Ejemplo n.º 26
0
        /// <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
                   ));
        }
Ejemplo n.º 28
0
        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));
        }
Ejemplo n.º 30
0
        /// <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));
        }