Пример #1
0
        protected virtual DocumentNode RewriteDocument(
            DocumentNode node,
            TContext context)
        {
            IReadOnlyList <IDefinitionNode> rewrittenDefinitions =
                RewriteMany(node.Definitions, context, RewriteDefinition);

            return(ReferenceEquals(node.Definitions, rewrittenDefinitions)
                ? node : node.WithDefinitions(rewrittenDefinitions));
        }
Пример #2
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);
        }
Пример #3
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));
        }
Пример #4
0
        protected virtual DocumentNode RewriteDocument(
            DocumentNode node,
            TContext context)
        {
            IReadOnlyList <IDefinitionNode> rewrittenDefinitions =
                RewriteMany(node.Definitions, context, (n, c) =>
            {
                if (n is ITypeSystemExtensionNode extension)
                {
                    return(RewriteTypeExtensionDefinition(extension, c));
                }

                if (n is ITypeSystemDefinitionNode definition)
                {
                    return(RewriteTypeDefinition(definition, c));
                }

                throw new NotSupportedException();
            });

            return(ReferenceEquals(node.Definitions, rewrittenDefinitions)
                ? node : node.WithDefinitions(rewrittenDefinitions));
        }