Exemple #1
0
        public async Task <string> GetWithStackedDataLoader(
            string key,
            [DataLoader("fooBar")] TestDataLoader testDataLoader,
            CancellationToken cancellationToken)
        {
            var s = await testDataLoader.LoadAsync(key + "a", cancellationToken);

            s += await testDataLoader.LoadAsync(key + "b", cancellationToken);

            s += await testDataLoader.LoadAsync(key + "c", cancellationToken);

            s += await testDataLoader.LoadAsync(key + "d", cancellationToken);

            await Task.Delay(10, cancellationToken);

            s += await testDataLoader.LoadAsync(key + "e", cancellationToken);

            s += await testDataLoader.LoadAsync(key + "f", cancellationToken);

            s += await testDataLoader.LoadAsync(key + "g", cancellationToken);

            await Task.Delay(10, cancellationToken);

            s += await testDataLoader.LoadAsync(key + "h", cancellationToken);

            return(s);
        }
Exemple #2
0
 public Task <string> GetWithDataLoader(
     string key,
     FieldNode fieldSelection,
     [DataLoader] TestDataLoader testDataLoader,
     CancellationToken cancellationToken)
 {
     return(testDataLoader.LoadAsync(key, cancellationToken));
 }
Exemple #3
0
        public async Task ClassDataLoader()
        {
            // arrange
            IRequestExecutor executor = await CreateExecutorAsync(c => c
                                                                  .AddQueryType <Query>()
                                                                  .AddDataLoader <ITestDataLoader, TestDataLoader>()
                                                                  .ModifyRequestOptions(o => o.IncludeExceptionDetails = true)
                                                                  .UseRequest(next => async context =>
            {
                await next(context);

                TestDataLoader dataLoader =
                    context.Services
                    .GetRequiredService <IDataLoaderRegistry>()
                    .GetOrRegister <TestDataLoader>(() => throw new Exception());

                context.Result = QueryResultBuilder
                                 .FromResult(((IQueryResult)context.Result !))
                                 .AddExtension("loads", dataLoader.Loads)
                                 .Create();
            })
                                                                  .UseDefaultPipeline());

            // act
            var results = new List <IExecutionResult>
            {
                await executor.ExecuteAsync(
                    QueryRequestBuilder.New()
                    .SetQuery(
                        @"{
                            a: withDataLoader(key: ""a"")
                            b: withDataLoader(key: ""b"")
                            bar {
                                c: withDataLoader(key: ""c"")
                            }
                        }")
                    .Create()),
                await executor.ExecuteAsync(
                    QueryRequestBuilder.New()
                    .SetQuery(
                        @"{
                            a: withDataLoader(key: ""a"")
                        }")
                    .Create()),
                await executor.ExecuteAsync(
                    QueryRequestBuilder.New()
                    .SetQuery(
                        @"{
                            c: withDataLoader(key: ""c"")
                        }")
                    .Create())
            };

            // assert
            results.MatchSnapshot();
        }
Exemple #4
0
        public async Task <string> GetWithStackedDataLoader(
            string key,
            FieldNode fieldSelection,
            [DataLoader("fooBar")] TestDataLoader testDataLoader,
            CancellationToken cancellationToken)
        {
            string s = await testDataLoader.LoadAsync(key + "a", cancellationToken);

            s += await testDataLoader.LoadAsync(key + "b", cancellationToken);

            s += await testDataLoader.LoadAsync(key + "c", cancellationToken);

            s += await testDataLoader.LoadAsync(key + "d", cancellationToken);

            s += await testDataLoader.LoadAsync(key + "e", cancellationToken);

            return(s);
        }