Exemple #1
0
        private async Task EndExecuteResolverBatchAsync(
            IExecutionContext executionContext,
            IEnumerable <ResolverTask> currentBatch,
            Action <ResolverTask> enqueueTask,
            CancellationToken cancellationToken)
        {
            foreach (ResolverTask resolverTask in currentBatch)
            {
                // complete resolver tasks
                if (resolverTask.Task.IsCompleted)
                {
                    resolverTask.ResolverResult = resolverTask.Task.Result;
                }
                else
                {
                    resolverTask.ResolverResult = await resolverTask.Task;
                }

                // serialize and integrate result into final query result
                var completionContext = new FieldValueCompletionContext(
                    executionContext, resolverTask.ResolverContext,
                    resolverTask, enqueueTask);

                CompleteValue(completionContext);

                cancellationToken.ThrowIfCancellationRequested();
            }
        }
Exemple #2
0
        private async Task ExecuteResolverSeriallyAsync(
            IExecutionContext executionContext,
            ResolverTask resolverTask,
            List <ResolverTask> nextBatch,
            CancellationToken cancellationToken)
        {
            resolverTask.ResolverResult = ExecuteResolver(
                resolverTask, executionContext.Options.DeveloperMode,
                cancellationToken);

            await CompleteDataLoadersAsync(
                executionContext.DataLoaders,
                cancellationToken);

            // await async results
            resolverTask.ResolverResult = await FinalizeResolverResultAsync(
                resolverTask.FieldSelection.Node,
                resolverTask.ResolverResult,
                executionContext.Options.DeveloperMode);

            // serialize and integrate result into final query result
            var completionContext = new FieldValueCompletionContext(
                executionContext, resolverTask.ResolverContext,
                resolverTask, t => nextBatch.Add(t));

            CompleteValue(completionContext);
        }
Exemple #3
0
        private async Task ExecuteResolverSeriallyAsync(
            IExecutionContext executionContext,
            ResolverTask resolverTask,
            Action <ResolverTask> enqueueTask,
            CancellationToken cancellationToken)
        {
            resolverTask.Task = ExecuteResolverAsync(
                resolverTask,
                cancellationToken);

            await CompleteDataLoadersAsync(
                executionContext.DataLoaders,
                cancellationToken);

            if (resolverTask.Task.IsCompleted)
            {
                resolverTask.ResolverResult = resolverTask.Task.Result;
            }
            else
            {
                resolverTask.ResolverResult = await resolverTask.Task;
            }

            // serialize and integrate result into final query result
            var completionContext = new FieldValueCompletionContext(
                executionContext, resolverTask.ResolverContext,
                resolverTask, enqueueTask);

            CompleteValue(completionContext);
        }
        private async Task ExecuteResolverSeriallyAsync(
            IExecutionContext executionContext,
            ResolverTask resolverTask,
            Action <ResolverTask> enqueueTask,
            BatchOperationHandler batchOperationHandler,
            CancellationToken cancellationToken)
        {
            resolverTask.Task = ExecuteResolverAsync(
                resolverTask,
                executionContext.ErrorHandler,
                cancellationToken);
            await CompleteBatchOperationsAsync(
                new[] { resolverTask.Task },
                batchOperationHandler,
                cancellationToken)
            .ConfigureAwait(false);

            resolverTask.ResolverResult = await resolverTask.Task
                                          .ConfigureAwait(false);

            // serialize and integrate result into final query result
            var completionContext = new FieldValueCompletionContext(
                executionContext,
                resolverTask.ResolverContext,
                resolverTask,
                enqueueTask);

            CompleteValue(completionContext);
        }
Exemple #5
0
        private async Task ExecuteFieldResolverBatchSeriallyAsync(
            ExecutionContext executionContext,
            List <FieldResolverTask> batch,
            CancellationToken cancellationToken)
        {
            List <(FieldResolverTask task, object resolverResult)> runningTasks =
                new List <(FieldResolverTask, object)>();

            foreach (FieldResolverTask task in batch)
            {
                // execute resolver
                ResolverContext resolverContext = new ResolverContext(
                    executionContext, task);
                object resolverResult = ExecuteFieldResolver(
                    resolverContext, task.FieldSelection.Field,
                    task.FieldSelection.Node, cancellationToken);

                // handle async results
                resolverResult = await HandleFieldValueAsync(
                    resolverResult);

                FieldValueCompletionContext completionContext =
                    new FieldValueCompletionContext(
                        executionContext, resolverContext,
                        task.FieldSelection, task.SetValue,
                        resolverResult);

                CompleteValue(completionContext);

                // execute sub-selection fields normally
                await ExecuteFieldResolversAsync(executionContext, cancellationToken);

                cancellationToken.ThrowIfCancellationRequested();
            }
        }
Exemple #6
0
        private FieldValueCompletionContext(
            FieldValueCompletionContext context,
            IType type, bool isNullable)
        {
            _setResult       = context._setResult;
            ExecutionContext = context.ExecutionContext;
            ResolverContext  = context.ResolverContext;
            Source           = context.Source;
            Selection        = context.Selection;
            SelectionSet     = context.SelectionSet;
            Path             = context.Path;
            Value            = context.Value;

            Type       = type;
            IsNullable = isNullable;
        }
Exemple #7
0
        private FieldValueCompletionContext(
            FieldValueCompletionContext context,
            Path elementPath, IType elementType,
            object element, Action <object> addElementToList)
        {
            ExecutionContext = context.ExecutionContext;
            ResolverContext  = context.ResolverContext;
            Source           = context.Source;
            Selection        = context.Selection;
            SelectionSet     = context.SelectionSet;
            IsNullable       = context.IsNullable;

            Path       = elementPath;
            Type       = elementType;
            Value      = element;
            _setResult = addElementToList;
        }
Exemple #8
0
        private async Task ExecuteFieldResolverBatchAsync(
            ExecutionContext executionContext,
            List <FieldResolverTask> batch,
            CancellationToken cancellationToken)
        {
            List <(FieldResolverTask task, IResolverContext context, object resolverResult)> runningTasks =
                new List <(FieldResolverTask, IResolverContext, object)>();

            foreach (FieldResolverTask task in batch)
            {
                IResolverContext resolverContext = new ResolverContext(
                    executionContext, task);

                if (task.Path.Depth <= _maxExecutionDepth)
                {
                    object resolverResult = ExecuteFieldResolver(
                        resolverContext, task.FieldSelection.Field,
                        task.FieldSelection.Node, cancellationToken);
                    runningTasks.Add((task, resolverContext, resolverResult));
                }
                else
                {
                    runningTasks.Add((task, resolverContext,
                                      new FieldError(
                                          $"The field has a depth of {task.Path.Depth}, " +
                                          "which exceeds max allowed depth of " +
                                          $"{_maxExecutionDepth}", task.FieldSelection.Node)));
                }
            }

            foreach (var runningTask in runningTasks)
            {
                object fieldValue = await HandleFieldValueAsync(
                    runningTask.resolverResult);

                FieldValueCompletionContext completionContext =
                    new FieldValueCompletionContext(
                        executionContext, runningTask.context,
                        runningTask.task.FieldSelection,
                        runningTask.task.SetValue,
                        fieldValue);
                CompleteValue(completionContext);

                cancellationToken.ThrowIfCancellationRequested();
            }
        }
        private FieldValueCompletionContext(
            FieldValueCompletionContext completionContext,
            IType type, bool isNullable)
        {
            _integrateResult     = completionContext._integrateResult;
            _enqueueResolverTask = completionContext._enqueueResolverTask;

            ExecutionContext = completionContext.ExecutionContext;
            ResolverContext  = completionContext.ResolverContext;
            Source           = completionContext.Source;
            Selection        = completionContext.Selection;
            SelectionSet     = completionContext.SelectionSet;
            Path             = completionContext.Path;
            Value            = completionContext.Value;
            Converter        = completionContext.Converter;

            Type       = type;
            IsNullable = isNullable;
        }
        private FieldValueCompletionContext(
            FieldValueCompletionContext completionContext,
            Path elementPath, IType elementType,
            object element, Action <object> addElementToList)
        {
            _integrateResult     = addElementToList;
            _enqueueResolverTask = completionContext._enqueueResolverTask;

            ExecutionContext = completionContext.ExecutionContext;
            ResolverContext  = completionContext.ResolverContext;
            Source           = completionContext.Source;
            Selection        = completionContext.Selection;
            SelectionSet     = completionContext.SelectionSet;
            IsNullable       = completionContext.IsNullable;
            Converter        = completionContext.Converter;

            Path  = elementPath;
            Type  = elementType;
            Value = element;
        }
Exemple #11
0
        private async Task EndExecuteResolverBatchAsync(
            IExecutionContext executionContext,
            IEnumerable <ResolverTask> currentBatch,
            List <ResolverTask> nextBatch,
            CancellationToken cancellationToken)
        {
            foreach (ResolverTask resolverTask in currentBatch)
            {
                // await async results
                resolverTask.ResolverResult = await FinalizeResolverResultAsync(
                    resolverTask.FieldSelection.Node,
                    resolverTask.ResolverResult,
                    executionContext.Options.DeveloperMode);

                // serialize and integrate result into final query result
                var completionContext = new FieldValueCompletionContext(
                    executionContext, resolverTask.ResolverContext,
                    resolverTask, t => nextBatch.Add(t));

                CompleteValue(completionContext);

                cancellationToken.ThrowIfCancellationRequested();
            }
        }
 protected void CompleteValue(
     FieldValueCompletionContext completionContext)
 {
     _fieldValueCompleter.CompleteValue(completionContext);
 }
Exemple #13
0
 private void CompleteValue(FieldValueCompletionContext completionContext)
 {
     _valueCompleter.CompleteValue(completionContext);
 }