public void DirectiveDefinition_WithArgument_ToString() { // arrange var name = new NameNode("foo"); var description = new StringValueNode("bar"); var arguments = new List <InputValueDefinitionNode> { new InputValueDefinitionNode( null, new NameNode("abc"), new StringValueNode("def"), new NamedTypeNode("efg"), null, Array.Empty <DirectiveNode>()) }; var locations = new List <NameNode> { new NameNode(DirectiveLocation.Field.ToString()) }; // act var directiveDefinition = new DirectiveDefinitionNode( null, name, description, true, arguments, locations); // assert directiveDefinition.ToString().MatchSnapshot(); }
public void CreateDirectiveDefinitionWithLocation(bool isRepeatable) { // arrange var location = new Location(0, 0, 0, 0); var name = new NameNode("foo"); var description = new StringValueNode("bar"); var arguments = new List <InputValueDefinitionNode>(); var locations = new List <NameNode>(); // act var directiveDefinition = new DirectiveDefinitionNode( location, name, description, isRepeatable, arguments, locations); // assert Assert.Equal(NodeKind.DirectiveDefinition, directiveDefinition.Kind); Assert.Equal(location, directiveDefinition.Location); Assert.Equal(name, directiveDefinition.Name); Assert.Equal(description, directiveDefinition.Description); Assert.Equal(isRepeatable, directiveDefinition.IsRepeatable); Assert.NotEqual(isRepeatable, directiveDefinition.IsUnique); Assert.Equal(arguments, directiveDefinition.Arguments); Assert.Equal(locations, directiveDefinition.Locations); }
protected virtual void ResolveChildren( DirectiveDefinitionNode node, IList <SyntaxNodeInfo> children) { if (node.Description is not null) { ResolveChildren( nameof(node.Description), node.Description, children); } ResolveChildren( nameof(node.Name), node.Name, children); ResolveChildren( nameof(node.Arguments), node.Arguments, children); ResolveChildren( nameof(node.Locations), node.Locations, children); }
protected override void VisitDirectiveDefinition( DirectiveDefinitionNode node, DocumentWriter writer) { WriteDescription(node.Description, writer); writer.Write(Keywords.Directive); writer.WriteSpace(); writer.Write('@'); writer.WriteName(node.Name); if (node.Arguments.Any()) { writer.Write("("); writer.WriteMany( node.Arguments, VisitArgumentValueDefinition, w => w.WriteSpace()); writer.Write(")"); } writer.WriteSpace(); if (node.IsRepeatable) { writer.Write(Keywords.Repeatable); writer.WriteSpace(); } writer.Write(Keywords.On); writer.WriteSpace(); writer.WriteMany(node.Locations, (n, _) => writer.WriteName(n), " | "); }
public void WithArguments() { // arrange var name = new NameNode("foo"); var description = new StringValueNode("bar"); var arguments = new List <InputValueDefinitionNode>(); var locations = new List <NameNode>(); var directiveDefinition = new DirectiveDefinitionNode( null, name, description, true, arguments, locations); // act directiveDefinition = directiveDefinition .WithArguments(new List <InputValueDefinitionNode> { new InputValueDefinitionNode ( null, new NameNode("arg"), null, new NamedTypeNode(new NameNode("type")), NullValueNode.Default, Array.Empty <DirectiveNode>() ) }); // assert directiveDefinition.MatchSnapshot(); }
public void CreateDirectiveDefinitionWithLocation(bool isRepeatable) { // arrange var source = new Source("foo"); var start = new SyntaxToken( TokenKind.StartOfFile, 0, 0, 1, 1, null); var location = new Location(source, start, start); var name = new NameNode("foo"); var description = new StringValueNode("bar"); var arguments = new List <InputValueDefinitionNode>(); var locations = new List <NameNode>(); // act var directiveDefinition = new DirectiveDefinitionNode( location, name, description, isRepeatable, arguments, locations); // assert Assert.Equal(NodeKind.DirectiveDefinition, directiveDefinition.Kind); Assert.Equal(location, directiveDefinition.Location); Assert.Equal(name, directiveDefinition.Name); Assert.Equal(description, directiveDefinition.Description); Assert.Equal(isRepeatable, directiveDefinition.IsRepeatable); Assert.Equal(arguments, directiveDefinition.Arguments); Assert.Equal(locations, directiveDefinition.Locations); }
protected override void VisitDirectiveDefinition( DirectiveDefinitionNode node, object context) { _visited.Add(nameof(VisitDirectiveDefinition)); base.VisitDirectiveDefinition(node, context); }
protected override void VisitDirectiveDefinition( DirectiveDefinitionNode node) { VisitName(node.Name); VisitIfNotNull(node.Description, VisitStringValue); VisitMany(node.Arguments, VisitInputValueDefinition); VisitMany(node.Locations, VisitName); }
public virtual VisitorAction Leave( DirectiveDefinitionNode node, ISyntaxNode parent, IReadOnlyList <object> path, IReadOnlyList <ISyntaxNode> ancestors) { return(GetDefaultAction(node.Kind)); }
public void ParseRepeatableDirective() { // arrange var text = "directive @skip(if: Boolean!) repeatable " + "on FIELD | FRAGMENT_SPREAD | INLINE_FRAGMENT"; var parser = new Utf8GraphQLParser(Encoding.UTF8.GetBytes(text)); // assert DocumentNode document = parser.Parse(); // assert DirectiveDefinitionNode directiveDefinition = document.Definitions .OfType <DirectiveDefinitionNode>().FirstOrDefault(); Assert.NotNull(directiveDefinition); Assert.True(directiveDefinition.IsRepeatable); }
public void ParseUniqueDirective() { // arrange var text = "directive @skip(if: Boolean!) " + "on FIELD | FRAGMENT_SPREAD | INLINE_FRAGMENT"; var parser = new Parser(); // assert DocumentNode document = parser.Parse(text); // assert DirectiveDefinitionNode directiveDefinition = document.Definitions .OfType <DirectiveDefinitionNode>().FirstOrDefault(); Assert.NotNull(directiveDefinition); Assert.False(directiveDefinition.IsRepeatable); }
public void WithDescription() { // arrange var name = new NameNode("foo"); var description = new StringValueNode("bar"); var arguments = new List <InputValueDefinitionNode>(); var locations = new List <NameNode>(); var directiveDefinition = new DirectiveDefinitionNode( null, name, description, true, arguments, locations); // act directiveDefinition = directiveDefinition .WithDescription(new StringValueNode("qux")); // assert directiveDefinition.MatchSnapshot(); }
public void AsRepeatable() { // arrange var name = new NameNode("foo"); var description = new StringValueNode("bar"); var arguments = new List <InputValueDefinitionNode>(); var locations = new List <NameNode>(); var directiveDefinition = new DirectiveDefinitionNode( null, name, description, false, arguments, locations); // act directiveDefinition = directiveDefinition .AsRepeatable(); // assert directiveDefinition.MatchSnapshot(); }
protected virtual DirectiveDefinitionNode RewriteDirectiveDefinition( DirectiveDefinitionNode node, TContext context) { DirectiveDefinitionNode current = node; current = Rewrite(current, current.Name, context, RewriteName, current.WithName); current = Rewrite(current, current.Description, context, RewriteStringValue, current.WithDescription); current = RewriteMany(current, current.Arguments, context, RewriteInputValueDefinition, current.WithArguments); current = RewriteMany(current, current.Locations, context, RewriteName, current.WithLocations); return(current); }
public void CreateDirectiveDefinition() { // arrange var name = new NameNode("foo"); var description = new StringValueNode("bar"); var arguments = new List <InputValueDefinitionNode>(); var locations = new List <NameNode>(); // act var directiveDefinition = new DirectiveDefinitionNode( null, name, description, true, arguments, locations); // assert Assert.Equal(NodeKind.DirectiveDefinition, directiveDefinition.Kind); Assert.Null(directiveDefinition.Location); Assert.Equal(name, directiveDefinition.Name); Assert.Equal(description, directiveDefinition.Description); Assert.Equal(arguments, directiveDefinition.Arguments); Assert.Equal(locations, directiveDefinition.Locations); }
protected virtual void VisitDirectiveDefinition( DirectiveDefinitionNode node, TContext context) { }
protected virtual void VisitDirectiveDefinition( DirectiveDefinitionNode node) { }