Example #1
0
        public static async Task <ExecutionResult> ExecuteMutationAsync(
            QueryContext context)
        {
            var(schema, _, operation, initialValue, coercedVariableValues) = context;
            var executionContext = context.BuildExecutorContext(new SerialExecutionStrategy());

            var mutationType = schema.Mutation;

            if (mutationType == null)
            {
                throw new GraphQLError(
                          "Schema does not support mutations. Mutation type is null.");
            }

            var selectionSet = operation.SelectionSet;
            var path         = new NodePath();
            var data         = await SelectionSets.ExecuteSelectionSetAsync(
                executionContext,
                selectionSet,
                mutationType,
                initialValue,
                coercedVariableValues,
                path).ConfigureAwait(false);


            return(new ExecutionResult
            {
                Errors = executionContext
                         .FieldErrors
                         .Select(context.FormatError).ToList(),
                Data = data
            });
        }
Example #2
0
        private static async Task <ExecutionResult> ExecuteSubscriptionEventAsync(
            IExecutorContext context,
            GraphQLOperationDefinition subscription,
            Dictionary <string, object> coercedVariableValues,
            object evnt,
            Func <Exception, Error> formatError)
        {
            var subscriptionType = context.Schema.Subscription;
            var selectionSet     = subscription.SelectionSet;
            var path             = new NodePath();
            var data             = await SelectionSets.ExecuteSelectionSetAsync(
                context,
                selectionSet,
                subscriptionType,
                evnt,
                coercedVariableValues,
                path).ConfigureAwait(false);

            var result = new ExecutionResult
            {
                Errors = context.FieldErrors.Select(formatError).ToList(),
                Data   = data
            };

            return(result);
        }
Example #3
0
        public static async Task <ExecutionResult> ExecuteQueryAsync(
            QueryContext context)
        {
            var(schema, _, operation, initialValue, coercedVariableValues) = context;
            var queryType = schema.Query;

            if (queryType == null)
            {
                throw new GraphQLError(
                          "Schema does not support queries. Query type is null.");
            }

            var selectionSet     = operation.SelectionSet;
            var executionContext = context.BuildExecutorContext(new ParallelExecutionStrategy());

            IDictionary <string, object> data = null;

            try
            {
                var path = new NodePath();
                data = await SelectionSets.ExecuteSelectionSetAsync(
                    executionContext,
                    selectionSet,
                    queryType,
                    initialValue,
                    coercedVariableValues,
                    path).ConfigureAwait(false);
            }
            catch (GraphQLError e)
            {
                executionContext.AddError(e);
                data = null;
            }

            return(new ExecutionResult
            {
                Errors = executionContext
                         .FieldErrors
                         .Select(context.FormatError)
                         .ToList(),
                Data = data
            });
        }