private ResolveEventStreamResult GenerateError( ResolveEventStreamResult resolveResult, Field field, ExecutionContext context, Exception exc, IEnumerable <string> path) { var error = new ExecutionError("Error trying to resolve {0}.".ToFormat(field.Name), exc); error.AddLocation(field, context.Document); error.Path = path; context.Errors.Add(error); resolveResult.Skip = false; return(resolveResult); }
private ResolveEventStreamResult ResolveEventStream( ExecutionContext context, IObjectGraphType parentType, object source, Field field, IEnumerable <string> path) { context.CancellationToken.ThrowIfCancellationRequested(); var fieldPath = path?.ToList() ?? new List <string>(); var resolveResult = new ResolveEventStreamResult { Skip = false }; if (!(GetFieldDefinition(context.Document, context.Schema, parentType, field) is EventStreamFieldType fieldDefinition)) { resolveResult.Skip = true; return(resolveResult); } var arguments = GetArgumentValues( context.Schema, fieldDefinition.Arguments, field.Arguments, context.Variables); try { var resolveContext = new ResolveEventStreamContext(); resolveContext.FieldName = field.Name; resolveContext.FieldAst = field; resolveContext.FieldDefinition = fieldDefinition; resolveContext.ReturnType = fieldDefinition.ResolvedType; resolveContext.ParentType = parentType; resolveContext.Arguments = arguments; resolveContext.Source = source; resolveContext.Schema = context.Schema; resolveContext.Document = context.Document; resolveContext.Fragments = context.Fragments; resolveContext.RootValue = context.RootValue; resolveContext.UserContext = context.UserContext; resolveContext.Operation = context.Operation; resolveContext.Variables = context.Variables; resolveContext.CancellationToken = context.CancellationToken; resolveContext.Metrics = context.Metrics; resolveContext.Errors = context.Errors; resolveContext.Path = fieldPath; if (fieldDefinition.Subscriber == null) { return(GenerateError(resolveResult, field, context, new InvalidOperationException($"Subscriber not set for field {field.Name}"), fieldPath)); } var result = fieldDefinition.Subscriber.Subscribe(resolveContext); var valueTransformer = result .SelectMany(async value => { var fieldResolveResult = await ResolveFieldAsync(context, parentType, value, field, fieldPath); return(new ExecutionResult { Data = fieldResolveResult.Value }); }) .Catch <ExecutionResult, Exception>(exception => Observable.Return( new ExecutionResult { Errors = new ExecutionErrors { new ExecutionError( $"Could not subscribe to field '{field.Name}' in query '{context.Document.OriginalQuery}'", exception) { Path = path } } })); resolveResult.Value = valueTransformer; return(resolveResult); } catch (Exception exc) { return(GenerateError(resolveResult, field, context, exc, path)); } }