Пример #1
0
            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);
                    IPreparedSelection rootSelection = _rootSelections[0];

                    var middlewareContext = new MiddlewareContext();
                    middlewareContext.Initialize(
                        operationContext,
                        _rootSelections[0],
                        resultMap,
                        1,
                        rootValue,
                        Path.New(_rootSelections[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);
                }
            }
 public void Initialize(
     IOperationContext operationContext,
     IPreparedSelection selection,
     ResultMap resultMap,
     int responseIndex,
     object?parent,
     Path path,
     IImmutableDictionary <string, object?> scopedContextData)
 {
     _operationContext = operationContext;
     _selection        = selection;
     ResultMap         = resultMap;
     ResponseIndex     = responseIndex;
     _parent           = parent;
     Path = path;
     ScopedContextData = scopedContextData;
     LocalContextData  = ImmutableDictionary <string, object?> .Empty;
     Arguments         = _selection.Arguments;
 }