Ejemplo n.º 1
0
        private async Task DispatchRequestsAsync(
            IList <BufferedRequest> requests,
            DocumentNode mergedQuery,
            NameNode operationName,
            IReadOnlyDictionary <string, object> variableValues,
            CancellationToken cancellationToken)
        {
            int index = 0;

            try
            {
                IReadOnlyQueryRequest mergedRequest =
                    QueryRequestBuilder.New()
                    .SetQuery(mergedQuery)
                    .SetOperation(operationName.Value)
                    .SetVariableValues(variableValues)
                    .SetServices(_services)
                    .Create();

                var mergedResult = (IReadOnlyQueryResult)await _queryExecutor
                                   .ExecuteAsync(mergedRequest, cancellationToken)
                                   .ConfigureAwait(false);

                var handledErrors = new HashSet <IError>();

                for (int i = 0; i < requests.Count; i++)
                {
                    index = i;

                    QueryResultBuilder result = ExtractResult(
                        requests[i].Aliases,
                        mergedResult,
                        handledErrors);

                    IReadOnlyList <IError> mergedErrors = mergedResult.Errors ?? Array.Empty <IError>();

                    if (handledErrors.Count < mergedErrors.Count &&
                        i == requests.Count - 1)
                    {
                        foreach (IError error in mergedErrors.Except(handledErrors))
                        {
                            result.AddError(error);
                        }
                    }

                    requests[i].Promise.SetResult(result.Create());
                }
            }
            catch (Exception ex)
            {
                for (int i = index; i < requests.Count; i++)
                {
                    requests[i].Promise.SetException(ex);
                }
            }
        }
Ejemplo n.º 2
0
 private static void ExtractErrors(
     IDictionary <string, string> aliases,
     IQueryResult mergedResult,
     ICollection <IError> handledErrors,
     QueryResultBuilder result)
 {
     if (mergedResult.Errors is not null)
     {
         foreach (IError error in mergedResult.Errors)
         {
             if (TryResolveField(error, aliases, out var responseName))
             {
                 handledErrors.Add(error);
                 result.AddError(RewriteError(error, responseName));
             }
         }
     }
 }