示例#1
0
    public async Task <IDictionary <string, object?> > ExecuteGroupedFieldSetAsync(
        IExecutorContext context,
        IReadOnlyDictionary <string, List <FieldSelection> > groupedFieldSet,
        ObjectDefinition objectDefinition,
        object?objectValue,
        NodePath path)
    {
        var tasks = new Dictionary <string, Task <object?> >();

        foreach (var fieldGroup in groupedFieldSet)
        {
            var executionTask = FieldGroups.ExecuteFieldGroupAsync(
                context,
                objectDefinition,
                objectValue,
                //todo: following is dirty
                new KeyValuePair <string, IReadOnlyCollection <FieldSelection> >(fieldGroup.Key,
                                                                                 fieldGroup.Value),
                path.Fork());

            tasks.Add(fieldGroup.Key, executionTask);
        }

        await Task.WhenAll(tasks.Values).ConfigureAwait(false);

        return(tasks.ToDictionary(kv => kv.Key, kv => kv.Value.Result));
    }
    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);
    }