Ejemplo n.º 1
0
        public async Task InvokeAsync(IMiddlewareContext context)
        {
            DelegateDirective delegateDirective = context.Field
                                                  .Directives[DirectiveNames.Delegate]
                                                  .FirstOrDefault()?.ToObject <DelegateDirective>();

            if (delegateDirective != null)
            {
                IImmutableStack <SelectionPathComponent> path =
                    delegateDirective.Path is null
                    ? ImmutableStack <SelectionPathComponent> .Empty
                    : SelectionPathParser.Parse(delegateDirective.Path);

                IRemoteQueryRequest request =
                    CreateQuery(context, delegateDirective.Schema, path);

                IReadOnlyQueryResult result = await ExecuteQueryAsync(
                    context, request, delegateDirective.Schema)
                                              .ConfigureAwait(false);

                UpdateContextData(context, result, delegateDirective);

                context.Result = ExtractData(result.Data, path.Count());
                ReportErrors(context, result.Errors);
            }

            await _next.Invoke(context).ConfigureAwait(false);
        }
Ejemplo n.º 2
0
        public void BuildRequest_OnlyQueryIsSet_RequestHasOnlyQuery()
        {
            // arrange
            DocumentNode query = Parser.Default.Parse("{ foo }");

            // act
            IRemoteQueryRequest request =
                RemoteQueryRequestBuilder.New()
                .SetQuery(query)
                .Create();

            // assert
            request.MatchSnapshot();
        }