public GetQueryMiddleware(
     RequestDelegate next,
     IQueryExecuter queryExecuter,
     QueryMiddlewareOptions options)
     : base(next, queryExecuter, options)
 {
 }
Exemplo n.º 2
0
        public async Task FetchSingleDataLoader()
        {
            // arrange
            IServiceProvider serviceProvider = new ServiceCollection()
                                               .AddDataLoaderRegistry()
                                               .BuildServiceProvider();

            var schema = Schema.Create(
                @"type Query { fetchItem: String }",
                c =>
            {
                c.BindResolver(async ctx =>
                {
                    IDataLoader <string, string> dataLoader =
                        ctx.DataLoader <string, string>(
                            "fetchItems",
                            key => Task.FromResult(key));
                    return(await dataLoader.LoadAsync("fooBar"));
                }).To("Query", "fetchItem");
            });

            IQueryExecuter executer = schema.MakeExecutable();
            IServiceScope  scope    = serviceProvider.CreateScope();

            // act
            IExecutionResult result = await executer.ExecuteAsync(
                new QueryRequest("{ fetchItem }")
            {
                Services = scope.ServiceProvider
            });;

            // assert
            result.Snapshot();
        }
Exemplo n.º 3
0
        public async Task RequestDataLoader()
        {
            // arrange
            ISchema schema = CreateSchema(ExecutionScope.Request);
            IQueryExecutionOptionsAccessor options = CreateOptions();
            IQueryExecuter executer = QueryExecutionBuilder
                                      .BuildDefault(schema, options);

            // act
            List <IExecutionResult> results = new List <IExecutionResult>();

            results.Add(await executer.ExecuteAsync(new QueryRequest(
                                                        @"{
                    a: withDataLoader(key: ""a"")
                    b: withDataLoader(key: ""b"")
                }")));
            results.Add(await executer.ExecuteAsync(new QueryRequest(
                                                        @"{
                    a: withDataLoader(key: ""a"")
                }")));
            results.Add(await executer.ExecuteAsync(new QueryRequest(
                                                        @"{
                    c: withDataLoader(key: ""c"")
                }")));
            results.Add(await executer.ExecuteAsync(new QueryRequest(
                                                        "{ loads }")));

            // assert
            Assert.Collection(results,
                              t => Assert.Null(t.Errors),
                              t => Assert.Null(t.Errors),
                              t => Assert.Null(t.Errors),
                              t => Assert.Null(t.Errors));
            results.Snapshot();
        }
Exemplo n.º 4
0
        public async Task ExecuteQueryWithPaging()
        {
            // arrange
            ISchema schema = Schema.Create(
                c => c.RegisterQueryType <QueryType>());
            IQueryExecuter executer = schema.MakeExecutable();

            string query = @"
            {
                s(last:2)
                {
                    edges {
                        cursor
                        node
                    }
                    pageInfo
                    {
                        hasNextPage
                    }
                }
            }
            ";

            // act
            IExecutionResult result = await executer
                                      .ExecuteAsync(new QueryRequest(query));

            // assert
            result.Snapshot();
        }
Exemplo n.º 5
0
        public async Task MiddlewareConfig_MapWithDelegate()
        {
            // arrange
            ISchema schema = Schema.Create(
                "type Query { a: String b: String }",
                c => c.Map(
                    new FieldReference("Query", "a"),
                    next => context =>
            {
                context.Result = "123";
                return(Task.CompletedTask);
            })
                .Map(
                    new FieldReference("Query", "b"),
                    next => context =>
            {
                context.Result = "456";
                return(Task.CompletedTask);
            }));

            IQueryExecuter executer = schema.MakeExecutable();

            // act
            IExecutionResult result = await executer.ExecuteAsync("{ a b }");

            // assert
            result.Snapshot();
        }
Exemplo n.º 6
0
        public async Task AddClassErrorFilter()
        {
            // arrange
            ISchema schema = Schema.Create("type Query { foo: String }",
                                           c => c.BindResolver(
                                               ctx =>
            {
                throw new Exception("Foo");
            }).To("Query", "foo"));

            var options = new QueryExecutionOptions
            {
                IncludeExceptionDetails = false
            };

            IQueryExecuter executer = schema.MakeExecutable(builder =>
                                                            builder.UseDefaultPipeline(options)
                                                            .AddErrorFilter <DummyErrorFilter>());

            // act
            IExecutionResult result = await executer.ExecuteAsync("{ foo }");

            // assert
            result.Snapshot();
        }
        public void GraphQLOrgMetaFieldAndUnionExample()
        {
            // arrange
            var query = @"
            {
                search(text: ""an"") {
                    __typename
                    ... on Human {
                        name
                        height
                    }
                    ... on Droid {
                        name
                        primaryFunction
                    }
                    ... on Starship {
                        name
                        length
                    }
                }
            }";

            IQueryExecuter executer = CreateSchema().MakeExecutable();

            // act
            IExecutionResult result = executer.Execute(query);

            // assert
            result.Snapshot();
        }
        public async Task SubscribeToReview()
        {
            // arrange
            IQueryExecuter executer = CreateSchema().MakeExecutable();

            // act
            var responseStream =
                (IResponseStream)await executer.ExecuteAsync(
                    "subscription { onCreateReview(episode: NEWHOPE) " +
                    "{ stars } }");

            // assert
            IExecutionResult result = await executer.ExecuteAsync(@"
                mutation {
                    createReview(episode: NEWHOPE,
                        review: { stars: 5 commentary: ""foo"" }) {
                        stars
                        commentary
                    }
                }");

            IReadOnlyQueryResult eventResult;

            using (var cts = new CancellationTokenSource(2000))
            {
                eventResult = await responseStream.ReadAsync();
            }

            eventResult.Snapshot();
        }
        public void GraphQLOrgMutationExample()
        {
            // arrange
            var query = @"
            mutation CreateReviewForEpisode($ep: Episode!, $review: ReviewInput!) {
                createReview(episode: $ep, review: $review) {
                    stars
                    commentary
                }
            }";

            var variables = new Dictionary <string, object>
            {
                { "ep", new EnumValueNode("JEDI") },
                { "review", new ObjectValueNode(
                      new ObjectFieldNode("stars", new IntValueNode(5)),
                      new ObjectFieldNode("commentary",
                                          new StringValueNode("This is a great movie!"))) }
            };

            IQueryExecuter executer = CreateSchema().MakeExecutable();

            // act
            IExecutionResult result = executer.Execute(query, variables);

            // assert
            result.Snapshot();
        }
        public void GraphQLOrgInlineFragmentExample2()
        {
            // arrange
            var query = @"
            query HeroForEpisode($ep: Episode!) {
                hero(episode: $ep) {
                    name
                    ... on Droid {
                        primaryFunction
                    }
                    ... on Human {
                        height
                    }
                }
            }";

            var variables = new Dictionary <string, object>
            {
                { "ep", new EnumValueNode("EMPIRE") },
            };

            IQueryExecuter executer = CreateSchema().MakeExecutable();

            // act
            IExecutionResult result = executer.Execute(query, variables);

            // assert
            result.Snapshot();
        }
        public void GraphQLOrgDirectiveSkipExample2()
        {
            // arrange
            var query = @"
            query Hero($episode: Episode, $withFriends: Boolean!) {
                hero(episode: $episode) {
                    name
                    friends @skip(if: $withFriends) {
                        name
                    }
                }
            }";

            var variables = new Dictionary <string, object>
            {
                { "episode", new EnumValueNode("JEDI") },
                { "withFriends", new BooleanValueNode(true) }
            };

            IQueryExecuter executer = CreateSchema().MakeExecutable();

            // act
            IExecutionResult result = executer.Execute(query, variables);

            // assert
            result.Snapshot();
        }
        public void GraphQLOrgVariableExample()
        {
            // arrange
            var query = @"
            query HeroNameAndFriends($episode: Episode) {
                hero(episode: $episode) {
                    name
                    friends {
                        name
                    }
                }
            }";

            var variables = new Dictionary <string, object>
            {
                { "episode", new EnumValueNode("JEDI") }
            };

            IQueryExecuter executer = CreateSchema().MakeExecutable();

            // act
            IExecutionResult result = executer.Execute(query, variables);

            // assert
            result.Snapshot();
        }
        public void GraphQLOrgFragmentExample()
        {
            // arrange
            var query = @"
            {
                leftComparison: hero(episode: EMPIRE) {
                    ...comparisonFields
                }
                rightComparison: hero(episode: JEDI) {
                    ...comparisonFields
                }
            }

            fragment comparisonFields on Character {
                name
                appearsIn
                friends {
                    name
                }
            }";

            IQueryExecuter executer = CreateSchema().MakeExecutable();

            // act
            IExecutionResult result = executer.Execute(query);

            // assert
            result.Snapshot();
        }
Exemplo n.º 14
0
        public async Task RequestCustomContext()
        {
            // arrange
            var options = new Mock <IQueryExecutionOptionsAccessor>();

            options
            .SetupGet(o => o.ExecutionTimeout)
            .Returns(TimeSpan.FromSeconds(30));

            ISchema        schema   = CreateSchema(ExecutionScope.Request);
            IQueryExecuter executer = QueryExecutionBuilder
                                      .BuildDefault(schema, options.Object);

            // act
            var results = new List <IExecutionResult>();

            results.Add(await executer.ExecuteAsync(
                            new QueryRequest("{ a: a b: a }")));
            results.Add(await executer.ExecuteAsync(
                            new QueryRequest("{ a: a b: a }")));
            results.Add(await executer.ExecuteAsync(
                            new QueryRequest("{ a: a b: a }")));
            results.Add(await executer.ExecuteAsync(
                            new QueryRequest("{ a: a b: a }")));

            // assert
            Assert.Collection(results,
                              t => Assert.Null(t.Errors),
                              t => Assert.Null(t.Errors),
                              t => Assert.Null(t.Errors),
                              t => Assert.Null(t.Errors));
            results.Snapshot();
        }
 public static Task <IExecutionResult> ExecuteAsync(
     this IQueryExecuter executer,
     string query)
 {
     return(executer.ExecuteAsync(
                new QueryRequest(query),
                CancellationToken.None));
 }
Exemplo n.º 16
0
 public PostQueryMiddleware(
     RequestDelegate next,
     IQueryExecuter queryExecuter,
     IQueryResultSerializer resultSerializer,
     QueryMiddlewareOptions options)
     : base(next, queryExecuter, resultSerializer, options)
 {
 }
Exemplo n.º 17
0
        public UpdateUserProcess(IQueryExecuter queryExecuter, ICommandHandler commandHandler, IUserStorage userStorage, ILogger <UpdateUserProcess> log)
        {
            _queryExecuter  = queryExecuter;
            _commandHandler = commandHandler;
            _userStorage    = userStorage;

            _log = log;
        }
 public OlapProvider(IQueryExecuter queryExecuter)
 {
     if (queryExecuter == null)
     {
         throw new ArgumentNullException("queryExecuter");
     }
     m_QueryExecuter = queryExecuter;
 }
Exemplo n.º 19
0
 public QueryExecuterBenchmarkBase(int cacheSize)
 {
     _schema        = SchemaFactory.Create();
     _queryExecuter = QueryExecutionBuilder.New()
                      .UseDefaultPipeline()
                      .AddQueryCache(cacheSize)
                      .Build(_schema);
 }
 public static Task <IExecutionResult> ExecuteAsync(
     this IQueryExecuter executer,
     QueryRequest request)
 {
     return(executer.ExecuteAsync(
                request,
                CancellationToken.None));
 }
Exemplo n.º 21
0
        public async Task ClassDataLoaderWithKey()
        {
            // arrange
            IServiceProvider serviceProvider = new ServiceCollection()
                                               .AddDataLoaderRegistry()
                                               .BuildServiceProvider();

            var schema = Schema.Create(c =>
            {
                c.RegisterQueryType <Query>();
                c.Options.DeveloperMode = true;
            });

            IQueryExecuter executer = schema.MakeExecutable();
            IServiceScope  scope    = serviceProvider.CreateScope();

            // act
            var results = new List <IExecutionResult>();

            results.Add(await executer.ExecuteAsync(new QueryRequest(
                                                        @"{
                    a: withDataLoader2(key: ""a"")
                    b: withDataLoader2(key: ""b"")
                }")
            {
                Services = scope.ServiceProvider
            }));

            results.Add(await executer.ExecuteAsync(new QueryRequest(
                                                        @"{
                    a: withDataLoader2(key: ""a"")
                }")
            {
                Services = scope.ServiceProvider
            }));

            results.Add(await executer.ExecuteAsync(new QueryRequest(
                                                        @"{
                    c: withDataLoader2(key: ""c"")
                }")
            {
                Services = scope.ServiceProvider
            }));

            results.Add(await executer.ExecuteAsync(new QueryRequest(
                                                        "{ loads loads2 }")
            {
                Services = scope.ServiceProvider
            }));

            // assert
            Assert.Collection(results,
                              t => Assert.Empty(t.Errors),
                              t => Assert.Empty(t.Errors),
                              t => Assert.Empty(t.Errors),
                              t => Assert.Empty(t.Errors));
            results.Snapshot();
        }
 public static IExecutionResult Execute(
     this IQueryExecuter executer,
     QueryRequest request)
 {
     return(Task.Factory.StartNew(
                () => ExecuteAsync(executer, request))
            .Unwrap()
            .GetAwaiter()
            .GetResult());
 }
 public static async Task <IExecutionResult> ExecuteAsync(
     this ISchema schema, QueryRequest request,
     CancellationToken cancellationToken = default)
 {
     using (IQueryExecuter executer = QueryExecutionBuilder.New()
                                      .UseDefaultPipeline().Build(schema))
     {
         return(await executer.ExecuteAsync(request, cancellationToken));
     }
 }
Exemplo n.º 24
0
        public UpdateUserProcessTests()
        {
            _queryExecuter  = Substitute.For <IQueryExecuter>();
            _commandHandler = Substitute.For <ICommandHandler>();

            _sut = new UpdateUserProcess(
                _queryExecuter,
                _commandHandler,
                Substitute.For <IUserStorage>(),
                new NullLogger <UpdateUserProcess>());
        }
 public static IExecutionResult Execute(
     this IQueryExecuter executer,
     string query,
     IReadOnlyDictionary <string, object> variableValues)
 {
     return(executer.Execute(
                new QueryRequest(query)
     {
         VariableValues = variableValues
     }));
 }
Exemplo n.º 26
0
 public SubscriptionMiddleware(
     RequestDelegate next,
     IQueryExecuter queryExecuter,
     QueryMiddlewareOptions options)
 {
     _next = next
             ?? throw new ArgumentNullException(nameof(next));
     Executer = queryExecuter
                ?? throw new ArgumentNullException(nameof(queryExecuter));
     Options = options
               ?? throw new ArgumentNullException(nameof(options));
 }
 public static Task <IExecutionResult> ExecuteAsync(
     this IQueryExecuter executer,
     string query,
     IReadOnlyDictionary <string, object> variableValues)
 {
     return(executer.ExecuteAsync(
                new QueryRequest(query)
     {
         VariableValues = variableValues
     },
                CancellationToken.None));
 }
Exemplo n.º 28
0
        private void inicjalizacja()
        {
            _executer = new ChangingMoneyExecuter();

            string consult = String.Format("consult('{0}\\ChangingMoney.pl')", Environment.CurrentDirectory);

            consult = consult.Replace("\\", "\\\\");

            PrologConnector.Code.Add(consult);

            zmienSciezke(Properties.Settings.Default.swiprolog);
        }
Exemplo n.º 29
0
        public async Task TypeIntrospectionOnQuery()
        {
            // arrange
            string         query    = "{ __type (type: \"Foo\") { name } }";
            IQueryExecuter executer = CreateSchema().MakeExecutable();

            // act
            IExecutionResult result = await executer.ExecuteAsync(query);

            // assert
            Assert.Empty(result.Errors);
            result.Snapshot();
        }
Exemplo n.º 30
0
        private async Task <IExecutionResult> ExecuteQuery(
            string query,
            Action errorHandled)
        {
            IQueryExecuter queryExecuter = CreateSchema().MakeExecutable(
                b => b.UseDefaultPipeline().AddErrorFilter((error, ex) =>
            {
                errorHandled();
                return(error);
            }));

            return(await queryExecuter.ExecuteAsync(query));
        }
 public OlapProvider(IQueryExecuter queryExecuter)
 {
     if (queryExecuter == null)
         throw new ArgumentNullException("queryExecuter");
     m_QueryExecuter = queryExecuter;
 }