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

        var mutationType = schema.Mutation;

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

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


        return(new ExecutionResult
        {
            Errors = executionContext
                     .FieldErrors
                     .Select(context.FormatError).ToList(),
            Data = data?.ToDictionary(kv => kv.Key, kv => kv.Value)
        });
    }
コード例 #2
0
    private static async Task <ExecutionResult> ExecuteSubscriptionEventAsync(
        IExecutorContext context,
        OperationDefinition subscription,
        IReadOnlyDictionary <string, object?> coercedVariableValues,
        object evnt,
        Func <Exception, ExecutionError> formatError)
    {
        var subscriptionType = context.Schema.Subscription;
        var selectionSet     = subscription.SelectionSet;
        var path             = new NodePath();
        var data             = await SelectionSets.ExecuteSelectionSetAsync(
            context,
            selectionSet,
            subscriptionType,
            evnt,
            path).ConfigureAwait(false);

        var result = new ExecutionResult
        {
            Errors = context.FieldErrors.Select(formatError).ToList(),
            Data   = data?.ToDictionary(kv => kv.Key, kv => kv.Value)
        };

        return(result);
    }
コード例 #3
0
        private static async Task <object> CompleteInterfaceValueAsync(
            IExecutorContext executorContext,
            ObjectType actualType,
            IReadOnlyCollection <GraphQLFieldSelection> fields,
            object value,
            NodePath path,
            InterfaceType interfaceType)
        {
            if (!actualType.Implements(interfaceType))
            {
                throw new CompleteValueException(
                          "Cannot complete value as interface. " +
                          $"Actual type {actualType.Name} does not implement {interfaceType.Name}",
                          path,
                          fields.First());
            }

            var subSelectionSet = SelectionSets.MergeSelectionSets(fields);
            var data            = await SelectionSets.ExecuteSelectionSetAsync(
                executorContext,
                subSelectionSet,
                actualType,
                value,
                path).ConfigureAwait(false);

            return(data);
        }
コード例 #4
0
        private static async Task <object> CompleteUnionValueAsync(
            IExecutorContext executorContext,
            ObjectType actualType,
            IReadOnlyCollection <GraphQLFieldSelection> fields,
            object value,
            NodePath path,
            UnionType unionType)
        {
            if (!unionType.IsPossible(actualType))
            {
                throw new CompleteValueException(
                          "Cannot complete value as union. " +
                          $"Actual type {actualType.Name} is not possible for {unionType.Name}",
                          path,
                          fields.First());
            }

            var subSelectionSet = SelectionSets.MergeSelectionSets(fields);
            var data            = await SelectionSets.ExecuteSelectionSetAsync(
                executorContext,
                subSelectionSet,
                actualType,
                value,
                path).ConfigureAwait(false);

            return(data);
        }
コード例 #5
0
        private static async Task <object> CompleteObjectValueAsync(IExecutorContext executorContext, List <GraphQLFieldSelection> fields, object value,
                                                                    Dictionary <string, object> coercedVariableValues, NodePath path, ObjectType fieldObjectType)
        {
            var subSelectionSet = SelectionSets.MergeSelectionSets(fields);
            var data            = await SelectionSets.ExecuteSelectionSetAsync(
                executorContext,
                subSelectionSet,
                fieldObjectType,
                value,
                coercedVariableValues,
                path).ConfigureAwait(false);

            return(data);
        }
コード例 #6
0
        private static async Task <object> CompleteObjectValueAsync(
            IExecutorContext executorContext,
            IReadOnlyCollection <GraphQLFieldSelection> fields,
            object value,
            NodePath path,
            ObjectType fieldObjectType)
        {
            var subSelectionSet = SelectionSets.MergeSelectionSets(fields);
            var data            = await SelectionSets.ExecuteSelectionSetAsync(
                executorContext,
                subSelectionSet,
                fieldObjectType,
                value,
                path).ConfigureAwait(false);

            return(data);
        }
コード例 #7
0
ファイル: Query.cs プロジェクト: pekkah/tanka-graphql
    public static async Task <ExecutionResult> ExecuteQueryAsync(
        QueryContext context)
    {
        var(schema, _, operation, initialValue, coercedVariableValues) = context;
        var queryType = schema.Query;
        var path      = new NodePath();

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

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

        IDictionary <string, object?>?data;

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

        return(new ExecutionResult
        {
            Errors = executionContext
                     .FieldErrors
                     .Select(context.FormatError)
                     .ToList(),
            Data = data?.ToDictionary(kv => kv.Key, kv => kv.Value)
        });
    }