public async Task Int_Variable_Is_Converted_To_Int_Literal()
        {
            // arrange
            var serviceCollection = new ServiceCollection();

            serviceCollection.AddSingleton(CreateFooServer());
            serviceCollection.AddStitchedSchema(builder => builder
                                                .AddSchemaFromString("foo", "type Query { foo(a: Int!) : Int! }"));

            IServiceProvider services = serviceCollection.BuildServiceProvider();

            IStitchingContext  stitchingContext    = services.GetRequiredService <IStitchingContext>();
            IRemoteQueryClient customerQueryClient = stitchingContext.GetRemoteQueryClient("foo");

            IReadOnlyQueryRequest request = QueryRequestBuilder.New()
                                            .SetQuery("query ($foo: Int!) { foo(a: $foo) }")
                                            .SetVariableValue("foo", 1)
                                            .Create();

            Task <IExecutionResult> executeTask = customerQueryClient.ExecuteAsync(request);
            await customerQueryClient.DispatchAsync(CancellationToken.None);

            IExecutionResult result = await executeTask;

            result.MatchSnapshot();
        }
        public async Task String_Variable_Is_Converted_To_String_Literal()
        {
            // arrange
            var serviceCollection = new ServiceCollection();

            serviceCollection.AddSingleton(CreateRemoteSchemas());
            serviceCollection.AddStitchedSchema(builder => builder
                                                .AddSchemaFromHttp("contract")
                                                .AddSchemaFromHttp("customer"));

            IServiceProvider services = serviceCollection.BuildServiceProvider();

            IStitchingContext  stitchingContext    = services.GetRequiredService <IStitchingContext>();
            IRemoteQueryClient customerQueryClient = stitchingContext.GetRemoteQueryClient("customer");

            IReadOnlyQueryRequest request = QueryRequestBuilder.New()
                                            .SetQuery("query ($id: ID!) { customer(id: $id) { name } }")
                                            .SetVariableValue("id", "Q3VzdG9tZXIKZDE=")
                                            .Create();

            Task <IExecutionResult> executeTask = customerQueryClient.ExecuteAsync(request);
            await customerQueryClient.DispatchAsync(CancellationToken.None);

            IExecutionResult result = await executeTask;

            result.MatchSnapshot();
        }
示例#3
0
        private static async Task <IReadOnlyQueryResult> ExecuteQueryAsync(
            IResolverContext context,
            IReadOnlyQueryRequest request,
            string schemaName)
        {
            IRemoteQueryClient remoteQueryClient =
                context.Service <IStitchingContext>()
                .GetRemoteQueryClient(schemaName);

            IExecutionResult result = await remoteQueryClient
                                      .ExecuteAsync(request)
                                      .ConfigureAwait(false);

            if (result is IReadOnlyQueryResult queryResult)
            {
                return(queryResult);
            }

            throw new QueryException(
                      StitchingResources.DelegationMiddleware_OnlyQueryResults);
        }