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();
        }
        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();
        }
Пример #3
0
        private static IReadOnlyList <VariableValue> ResolveScopedVariables(
            IResolverContext context,
            NameString schemaName,
            OperationType operationType,
            IEnumerable <SelectionPathComponent> components)
        {
            IStitchingContext stitchingContext =
                context.Service <IStitchingContext>();

            ISchema remoteSchema =
                stitchingContext.GetRemoteSchema(schemaName);

            IComplexOutputType type =
                remoteSchema.GetOperationType(operationType);

            var variables = new List <VariableValue>();

            SelectionPathComponent[] comps = components.Reverse().ToArray();

            for (int i = 0; i < comps.Length; i++)
            {
                SelectionPathComponent component = comps[i];

                if (!type.Fields.TryGetField(component.Name.Value,
                                             out IOutputField field))
                {
                    throw new QueryException(new Error
                    {
                        Message = string.Format(
                            CultureInfo.InvariantCulture,
                            StitchingResources
                            .DelegationMiddleware_PathElementInvalid,
                            component.Name.Value,
                            type.Name)
                    });
                }

                ResolveScopedVariableArguments(
                    context, component, field, variables);

                if (i + 1 < comps.Length)
                {
                    if (!field.Type.IsComplexType())
                    {
                        throw new QueryException(new Error
                        {
                            Message = StitchingResources
                                      .DelegationMiddleware_PathElementTypeUnexpected
                        });
                    }
                    type = (IComplexOutputType)field.Type.NamedType();
                }
            }

            return(variables);
        }
 public RemoteQueryBatchOperation(IStitchingContext context)
 {
     _subscription = context.Subscribe(this);
 }