예제 #1
0
        protected virtual FragmentDefinitionNode RewriteFragmentDefinition(
            FragmentDefinitionNode node,
            TContext context)
        {
            FragmentDefinitionNode current = node;

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

            current = Rewrite(current, current.TypeCondition, context,
                              RewriteNamedType, current.WithTypeCondition);

            current = Rewrite(current, current.VariableDefinitions, context,
                              (p, c) => RewriteMany(p, c, RewriteVariableDefinition),
                              current.WithVariableDefinitions);

            current = Rewrite(current, current.Directives, context,
                              (p, c) => RewriteMany(p, c, RewriteDirective),
                              current.WithDirectives);

            if (current.SelectionSet != null)
            {
                current = Rewrite(current, current.SelectionSet, context,
                                  RewriteSelectionSet, current.WithSelectionSet);
            }

            return(current);
        }
예제 #2
0
        protected virtual void ResolveChildren(
            FragmentDefinitionNode node,
            IList <SyntaxNodeInfo> children)
        {
            ResolveChildren(
                nameof(node.Name),
                node.Name,
                children);

            if (node.VariableDefinitions.Count != 0)
            {
                ResolveChildren(
                    nameof(node.VariableDefinitions),
                    node.VariableDefinitions,
                    children);
            }

            ResolveChildren(
                nameof(node.TypeCondition),
                node.TypeCondition,
                children);

            if (node.Directives.Count != 0)
            {
                ResolveChildren(
                    nameof(node.Directives),
                    node.Directives,
                    children);
            }

            ResolveChildren(
                nameof(node.SelectionSet),
                node.SelectionSet,
                children);
        }
예제 #3
0
        protected override void VisitFragmentDefinition(
            FragmentDefinitionNode node)
        {
            _writer.Write(Keywords.Fragment);
            _writer.WriteSpace();

            VisitName(node.Name);
            _writer.WriteSpace();

            if (node.VariableDefinitions.Any())
            {
                _writer.Write('(');

                WriteMany(node.VariableDefinitions, VisitVariableDefinition);

                _writer.Write(')');
                _writer.WriteSpace();
            }

            _writer.Write(Keywords.On);
            _writer.WriteSpace();

            VisitNamedType(node.TypeCondition);

            WriteMany(node.Directives, VisitDirective);

            if (node.SelectionSet != null)
            {
                _writer.WriteSpace();
                VisitSelectionSet(node.SelectionSet);
            }
        }
 protected override void VisitFragmentDefinition(
     FragmentDefinitionNode node,
     object context)
 {
     VisitedFragmentDefinition = true;
     base.VisitFragmentDefinition(node, context);
 }
예제 #5
0
 public virtual VisitorAction Leave(
     FragmentDefinitionNode node,
     ISyntaxNode parent,
     IReadOnlyList <object> path,
     IReadOnlyList <ISyntaxNode> ancestors)
 {
     return(GetDefaultAction(node.Kind));
 }
예제 #6
0
 protected override void VisitFragmentDefinition(
     FragmentDefinitionNode node)
 {
     VisitName(node.Name);
     VisitMany(node.VariableDefinitions, VisitVariableDefinition);
     VisitNamedType(node.TypeCondition);
     VisitMany(node.Directives, VisitDirective);
     VisitSelectionSet(node.SelectionSet);
 }
예제 #7
0
        public void CreateDocument()
        {
            // arrange
            var fragment = new FragmentDefinitionNode(
                null, new NameNode("foo"),
                Array.Empty <VariableDefinitionNode>(),
                new NamedTypeNode("foo"),
                Array.Empty <DirectiveNode>(),
                new SelectionSetNode(Array.Empty <ISelectionNode>()));

            // act
            var document = new DocumentNode(new IDefinitionNode[] { fragment });

            // assert
            Assert.Equal(SyntaxKind.Document, document.Kind);
            Assert.Null(document.Location);
            Assert.Collection(document.Definitions, d => Assert.Equal(fragment, d));
        }
예제 #8
0
        public void Document_With_Definitions_Null()
        {
            // arrange
            var fragment = new FragmentDefinitionNode(
                null, new NameNode("foo"),
                Array.Empty <VariableDefinitionNode>(),
                new NamedTypeNode("foo"),
                Array.Empty <DirectiveNode>(),
                new SelectionSetNode(Array.Empty <ISelectionNode>()));

            var document = new DocumentNode(new IDefinitionNode[] { });

            // act
            void Action() => document.WithDefinitions(null);

            // assert
            Assert.Throws <ArgumentNullException>(Action);
        }
예제 #9
0
        public void Document_With_Definitions()
        {
            // arrange
            var location = new Location(0, 0, 0, 0);

            var fragment = new FragmentDefinitionNode(
                null, new NameNode("foo"),
                Array.Empty <VariableDefinitionNode>(),
                new NamedTypeNode("foo"),
                Array.Empty <DirectiveNode>(),
                new SelectionSetNode(Array.Empty <ISelectionNode>()));

            var document = new DocumentNode(location, new IDefinitionNode[] { });

            // act
            document = document.WithDefinitions(new IDefinitionNode[] { fragment });

            // assert
            Assert.Collection(document.Definitions, d => Assert.Equal(fragment, d));
        }
예제 #10
0
        public void Document_With_Location_Null()
        {
            // arrange
            var location = new Location(0, 0, 0, 0);

            var fragment = new FragmentDefinitionNode(
                null, new NameNode("foo"),
                Array.Empty <VariableDefinitionNode>(),
                new NamedTypeNode("foo"),
                Array.Empty <DirectiveNode>(),
                new SelectionSetNode(Array.Empty <ISelectionNode>()));

            var document = new DocumentNode(location, new IDefinitionNode[] { fragment });

            // act
            document = document.WithLocation(null);

            // assert
            Assert.Null(document.Location);
        }
        protected override void VisitFragmentDefinition(
            FragmentDefinitionNode node,
            DocumentWriter writer)
        {
            writer.Write(Keywords.Fragment);
            writer.WriteSpace();

            writer.WriteName(node.Name);
            writer.WriteSpace();

            if (node.VariableDefinitions.Any())
            {
                writer.Write('(');

                writer.WriteMany(
                    node.VariableDefinitions,
                    VisitVariableDefinition);

                writer.Write(')');
                writer.WriteSpace();
            }

            writer.Write(Keywords.On);
            writer.WriteSpace();

            writer.WriteNamedType(node.TypeCondition);

            writer.WriteMany(node.Directives,
                             (n, w) => w.WriteDirective(n));

            if (node.SelectionSet != null)
            {
                writer.WriteSpace();
                VisitSelectionSet(node.SelectionSet, writer);
            }
        }
예제 #12
0
 protected override void VisitFragmentDefinition(
     FragmentDefinitionNode node)
 {
     VisitedFragmentDefinition = true;
     base.VisitFragmentDefinition(node);
 }
예제 #13
0
 protected virtual void VisitFragmentDefinition(
     FragmentDefinitionNode node)
 {
 }
예제 #14
0
 protected virtual void VisitFragmentDefinition(
     FragmentDefinitionNode node,
     TContext context)
 {
 }