private async ValueTask <ISourceStream> SubscribeAsync() { OperationContext operationContext = _operationContextPool.Get(); try { object?rootValue = RootValueResolver.TryResolve( _requestContext, _requestContext.Services, _subscriptionType, ref _cachedRootValue); operationContext.Initialize( _requestContext, _requestContext.Services, NoopBatchDispatcher.Default, _requestContext.Operation !, rootValue, _requestContext.Variables !); ResultMap resultMap = operationContext.Result.RentResultMap(1); ISelection rootSelection = _rootSelections.Selections[0]; var middlewareContext = new MiddlewareContext(); middlewareContext.Initialize( operationContext, _rootSelections.Selections[0], resultMap, 1, rootValue, Path.New(_rootSelections.Selections[0].ResponseName), ImmutableDictionary <string, object?> .Empty); ISourceStream sourceStream = await rootSelection.Field.SubscribeResolver !.Invoke(middlewareContext) .ConfigureAwait(false); if (operationContext.Result.Errors.Count > 0) { throw new GraphQLException(operationContext.Result.Errors); } return(sourceStream); } finally { operationContext.Result.DropResult(); _operationContextPool.Return(operationContext); } }
private async Task <IQueryResult> OnEvent(object payload) { using IServiceScope serviceScope = _requestContext.Services.CreateScope(); IServiceProvider eventServices = serviceScope.ServiceProvider; IBatchDispatcher dispatcher = eventServices.GetRequiredService <IBatchDispatcher>(); OperationContext operationContext = _operationContextPool.Get(); try { ImmutableDictionary <string, object?> scopedContext = ImmutableDictionary <string, object?> .Empty .SetItem(WellKnownContextData.EventMessage, payload); object?rootValue = RootValueResolver.TryResolve( _requestContext, eventServices, _subscriptionType, ref _cachedRootValue); operationContext.Initialize( _requestContext, eventServices, dispatcher, _requestContext.Operation !, rootValue, _requestContext.Variables !); return(await _queryExecutor .ExecuteAsync(operationContext, scopedContext) .ConfigureAwait(false)); } finally { _operationContextPool.Return(operationContext); } }