예제 #1
0
        public async Task <object?> GetValue(FinalizerContext context)
        {
            try
            {
                var task = taskFactory();
                await task.ConfigureAwait(false);

                var type = GetTaskType(task.GetType());
                if (type != null)
                {
                    var result = GetResultFrom(task, type);
                    return(await context.UnrollResults(result, context).ConfigureAwait(false));
                }
                return(null);
            }
#pragma warning disable CA1031 // Do not catch general exception types
            catch (Exception ex)
            {
                var errors = ex.HasGraphQlErrors(out var e) ? e : new[] { new GraphQlError(WellKnownErrorCodes.UnhandledError) };
                foreach (var error in errors)
                {
                    error.Fixup(fieldContext);
                }
                throw new InvalidOperationException("Caught error in task", ex).AddGraphQlErrors(errors);
            }
        }
예제 #2
0
        public async Task <object?> GetValue(FinalizerContext context)
        {
            try
            {
                return(await context.UnrollResults(valueAccessor(), context).ConfigureAwait(false));
            }
#pragma warning disable CA1031 // Do not catch general exception types
            catch (Exception ex)
            {
                var errors = ex.HasGraphQlErrors(out var e) ? e : new[] { new GraphQlError(WellKnownErrorCodes.UnhandledError) };
                foreach (var error in errors)
                {
                    error.Fixup(fieldContext);
                }
                context.Logger.LogError(new EventId(10000, "FieldResolutionCaught"), ex, WellKnownErrorCodes.GetStaticMessage(WellKnownErrorCodes.UnhandledError, errors[0].Arguments), expression);
                context.Errors.AddRange(errors);
                return(null);
            }
        }