示例#1
0
    public static object?Handle(
        IExecutorContext context,
        ObjectDefinition objectDefinition,
        string fieldName,
        TypeBase fieldType,
        FieldSelection fieldSelection,
        object?completedValue,
        Exception error,
        NodePath path)
    {
        if (error is not QueryExecutionException)
        {
            error = new QueryExecutionException(
                "",
                error,
                path,
                fieldSelection);
        }

        if (fieldType is NonNullType)
        {
            throw error;
        }

        context.AddError(error);
        return(completedValue);
    }
示例#2
0
        public static object Handle(
            IExecutorContext context,
            ObjectType objectType,
            string fieldName,
            IType fieldType,
            GraphQLFieldSelection fieldSelection,
            object completedValue,
            Exception error,
            NodePath path)
        {
            if (!(error is QueryExecutionException))
            {
                error = new QueryExecutionException(
                    "",
                    error,
                    path,
                    fieldSelection);
            }

            if (fieldType is NonNull)
            {
                throw error;
            }

            context.AddError(error);
            return(completedValue);
        }
示例#3
0
        public override async Task <IDictionary <string, object> > ExecuteGroupedFieldSetAsync(IExecutorContext context,
                                                                                               Dictionary <string, List <GraphQLFieldSelection> > groupedFieldSet,
                                                                                               ObjectType objectType, object objectValue,
                                                                                               Dictionary <string, object> coercedVariableValues,
                                                                                               NodePath path)
        {
            var responseMap = new Dictionary <string, object>();

            foreach (var fieldGroup in groupedFieldSet)
            {
                var responseKey = fieldGroup.Key;

                try
                {
                    var result = await ExecuteFieldGroupAsync(
                        context,
                        objectType,
                        objectValue,
                        coercedVariableValues,
                        fieldGroup,
                        path.Fork()).ConfigureAwait(false);

                    responseMap[responseKey] = result;
                }
                catch (GraphQLError e)
                {
                    responseMap[responseKey] = null;
                    context.AddError(e);
                }
            }

            return(responseMap);
        }
    public async Task <IDictionary <string, object?> > ExecuteGroupedFieldSetAsync(
        IExecutorContext context,
        IReadOnlyDictionary <string, List <FieldSelection> > groupedFieldSet,
        ObjectDefinition objectDefinition,
        object?objectValue,
        NodePath path)
    {
        var responseMap = new Dictionary <string, object?>();

        foreach (var fieldGroup in groupedFieldSet)
        {
            var responseKey = fieldGroup.Key;

            try
            {
                var result = await FieldGroups.ExecuteFieldGroupAsync(
                    context,
                    objectDefinition,
                    objectValue,
                    new KeyValuePair <string, IReadOnlyCollection <FieldSelection> >(fieldGroup.Key, fieldGroup.Value),
                    path.Fork()).ConfigureAwait(false);

                responseMap[responseKey] = result;
            }
            catch (QueryExecutionException e)
            {
                responseMap[responseKey] = null;
                context.AddError(e);
            }
        }

        return(responseMap);
    }
示例#5
0
        private async Task <object> CompleteListValueAsync(
            IExecutorContext executorContext,
            ObjectType objectType,
            IField field,
            IType fieldType,
            ObjectType actualType,
            GraphQLFieldSelection selection,
            IReadOnlyCollection <GraphQLFieldSelection> fields,
            object value,
            NodePath path,
            List listType)
        {
            if (!(value is IEnumerable values))
            {
                throw new CompleteValueException(
                          $"Cannot complete value for list field '{selection.Name.Value}':'{fieldType}'. " +
                          "Resolved value is not a collection",
                          path,
                          selection);
            }

            var innerType = listType.OfType;
            var result    = new List <object>();
            int i         = 0;

            foreach (var resultItem in values)
            {
                var itemPath = path.Fork().Append(i++);
                try
                {
                    var completedResultItem = await CompleteValueAsync(
                        executorContext,
                        objectType,
                        field,
                        innerType,
                        actualType,
                        selection,
                        fields,
                        resultItem,
                        itemPath).ConfigureAwait(false);

                    result.Add(completedResultItem);
                }
                catch (Exception e)
                {
                    if (innerType is NonNull)
                    {
                        throw;
                    }

                    executorContext.AddError(e);
                    result.Add(null);
                }
            }

            return(result);
        }