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)); }
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); }
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)); }
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)); }