public void Parse_PathWithVarArgs_ThreeComponentsOneWithVarArgs() { // arrange var serializedPath = "foo(a: $foo:bar).bar.baz"; // act IImmutableStack <SelectionPathComponent> path = SelectionPathParser.Parse(serializedPath); // assert Assert.Collection(path.Reverse(), c => { Assert.Equal("foo", c.Name.Value); Assert.Collection(c.Arguments, a => { Assert.Equal("a", a.Name.Value); Assert.IsType <ScopedVariableNode>(a.Value); var v = (ScopedVariableNode)a.Value; Assert.Equal("foo_bar", v.ToVariableName()); }); }, c => { Assert.Equal("bar", c.Name.Value); Assert.Empty(c.Arguments); }, c => { Assert.Equal("baz", c.Name.Value); Assert.Empty(c.Arguments); }); }
public void Parse_PathWithoutArgs_ThreeComponentsFound() { // arrange var serializedPath = "foo.bar.baz"; // act IImmutableStack <SelectionPathComponent> path = SelectionPathParser.Parse(serializedPath); // assert Assert.Collection(path.Reverse(), t => { Assert.Equal("foo", t.Name.Value); Assert.Empty(t.Arguments); }, t => { Assert.Equal("bar", t.Name.Value); Assert.Empty(t.Arguments); }, t => { Assert.Equal("baz", t.Name.Value); Assert.Empty(t.Arguments); }); }
public void BuildRemoteQueryCanOverrideOperationName() { // arrange IImmutableStack<SelectionPathComponent> path = SelectionPathParser.Parse("a.b.c.d(a: $fields:bar)"); DocumentNode initialQuery = Utf8GraphQLParser.Parse( @"{ foo { bar { baz { ... on Baz { qux } } } } } "); FieldNode field = initialQuery.Definitions .OfType<OperationDefinitionNode>().Single() .SelectionSet.Selections .OfType<FieldNode>().Single() .SelectionSet.Selections .OfType<FieldNode>().Single(); // act DocumentNode newQuery = RemoteQueryBuilder.New() .SetOperation(new NameNode( nameof(BuildRemoteQueryCanOverrideOperationName)), OperationType.Query) .SetSelectionPath(path) .SetRequestField(field) .AddVariable("__fields_bar", new NamedTypeNode(null, new NameNode("String"))) .Build("abc", new Dictionary<(NameString Type, NameString Schema), NameString>()); // assert QuerySyntaxSerializer.Serialize(newQuery).MatchSnapshot(); }
public void BuildRemoteQuery() { // arrange IImmutableStack <SelectionPathComponent> path = SelectionPathParser.Parse("a.b.c.d(a: $fields:bar)"); DocumentNode initialQuery = Parser.Default.Parse( @"{ foo { bar { baz { ... on Baz { qux } } } } } "); FieldNode field = initialQuery.Definitions .OfType <OperationDefinitionNode>().Single() .SelectionSet.Selections .OfType <FieldNode>().Single() .SelectionSet.Selections .OfType <FieldNode>().Single(); // act DocumentNode newQuery = RemoteQueryBuilder.New() .SetOperation(OperationType.Query) .SetSelectionPath(path) .SetRequestField(field) .AddVariable("fields_bar", new NamedTypeNode(null, new NameNode("String"))) .Build(); // assert QuerySyntaxSerializer.Serialize(newQuery).MatchSnapshot(); }
public async Task InvokeAsync(IMiddlewareContext context) { DelegateDirective?delegateDirective = context.Field .Directives[DirectiveNames.Delegate] .FirstOrDefault()?.ToObject <DelegateDirective>(); if (delegateDirective != null) { IImmutableStack <SelectionPathComponent> path; IImmutableStack <SelectionPathComponent> reversePath; if (delegateDirective.Path is null) { path = ImmutableStack <SelectionPathComponent> .Empty; reversePath = ImmutableStack <SelectionPathComponent> .Empty; } else { path = SelectionPathParser.Parse(delegateDirective.Path); reversePath = ImmutableStack.CreateRange(path); } IReadOnlyQueryRequest request = CreateQuery(context, delegateDirective.Schema, path, reversePath); IReadOnlyQueryResult result = await ExecuteQueryAsync( context, request, delegateDirective.Schema) .ConfigureAwait(false); UpdateContextData(context, result, delegateDirective); object?value = ExtractData(result.Data, reversePath, context.ResponseName); context.Result = new SerializedData(value); if (result.Errors is not null) { ReportErrors(delegateDirective.Schema, context, result.Errors); } } await _next.Invoke(context).ConfigureAwait(false); }
public void Parse_PathWithArgs_ThreeComponentsTwoWithArgs() { // arrange var serializedPath = "foo(a: 1).bar.baz(b: \"s\")"; // act IImmutableStack <SelectionPathComponent> path = SelectionPathParser.Parse(serializedPath); // assert Assert.Collection(path.Reverse(), c => { Assert.Equal("foo", c.Name.Value); Assert.Collection(c.Arguments, a => { Assert.Equal("a", a.Name.Value); Assert.IsType <IntValueNode>(a.Value); }); }, c => { Assert.Equal("bar", c.Name.Value); Assert.Empty(c.Arguments); }, c => { Assert.Equal("baz", c.Name.Value); Assert.Collection(c.Arguments, a => { Assert.Equal("b", a.Name.Value); Assert.IsType <StringValueNode>(a.Value); }); }); }