-
-
Notifications
You must be signed in to change notification settings - Fork 722
/
OperationContext.Pooling.cs
138 lines (128 loc) · 4.97 KB
/
OperationContext.Pooling.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
using System;
using System.Collections.Generic;
using System.Runtime.CompilerServices;
using System.Threading;
using HotChocolate.Execution.DependencyInjection;
using HotChocolate.Execution.Instrumentation;
using HotChocolate.Execution.Processing.Tasks;
using HotChocolate.Fetching;
using HotChocolate.Types;
using HotChocolate.Utilities;
using Microsoft.Extensions.DependencyInjection;
using static HotChocolate.Execution.ThrowHelper;
namespace HotChocolate.Execution.Processing;
internal sealed partial class OperationContext
{
private readonly IFactory<ResolverTask> _resolverTaskFactory;
private readonly WorkScheduler _workScheduler;
private readonly DeferredWorkScheduler _deferredWorkScheduler;
private readonly ResultBuilder _resultBuilder;
private readonly PooledPathFactory _pathFactory;
private ISchema _schema = default!;
private IErrorHandler _errorHandler = default!;
private IActivator _activator = default!;
private IExecutionDiagnosticEvents _diagnosticEvents = default!;
private IDictionary<string, object?> _contextData = default!;
private CancellationToken _requestAborted;
private IOperation _operation = default!;
private IVariableValueCollection _variables = default!;
private IServiceProvider _services = default!;
private Func<object?> _resolveQueryRootValue = default!;
private IBatchDispatcher _batchDispatcher = default!;
private InputParser _inputParser = default!;
private object? _rootValue;
private bool _isInitialized;
public OperationContext(
IFactory<ResolverTask> resolverTaskFactory,
PooledPathFactory pathFactory,
ResultBuilder resultBuilder,
ITypeConverter typeConverter)
{
_resolverTaskFactory = resolverTaskFactory;
_pathFactory = pathFactory;
_workScheduler = new(this);
_deferredWorkScheduler = new();
_resultBuilder = resultBuilder;
Converter = typeConverter;
}
public bool IsInitialized => _isInitialized;
public void Initialize(
IRequestContext requestContext,
IServiceProvider scopedServices,
IBatchDispatcher batchDispatcher,
IOperation operation,
IVariableValueCollection variables,
object? rootValue,
Func<object?> resolveQueryRootValue)
{
_schema = requestContext.Schema;
_errorHandler = requestContext.ErrorHandler;
_activator = requestContext.Activator;
_diagnosticEvents = requestContext.DiagnosticEvents;
_contextData = requestContext.ContextData;
_requestAborted = requestContext.RequestAborted;
_operation = operation;
_variables = variables;
_services = scopedServices;
_inputParser = scopedServices.GetRequiredService<InputParser>();
_rootValue = rootValue;
_resolveQueryRootValue = resolveQueryRootValue;
_batchDispatcher = batchDispatcher;
_isInitialized = true;
IncludeFlags = _operation.CreateIncludeFlags(variables);
_workScheduler.Initialize(batchDispatcher);
_deferredWorkScheduler.Initialize(this);
_resultBuilder.Initialize(_operation, _errorHandler, _diagnosticEvents);
}
public void InitializeFrom(OperationContext context)
{
_schema = context._schema;
_errorHandler = context._errorHandler;
_activator = context._activator;
_diagnosticEvents = context._diagnosticEvents;
_contextData = context.ContextData;
_requestAborted = context._requestAborted;
_operation = context._operation;
_variables = context._variables;
_services = context._services;
_inputParser = context._inputParser;
_rootValue = context._rootValue;
_resolveQueryRootValue = context._resolveQueryRootValue;
_batchDispatcher = context._batchDispatcher;
_isInitialized = true;
IncludeFlags = _operation.CreateIncludeFlags(_variables);
_workScheduler.Initialize(_batchDispatcher);
_deferredWorkScheduler.InitializeFrom(this, context._deferredWorkScheduler);
_resultBuilder.Initialize(_operation, _errorHandler, _diagnosticEvents);
}
public void Clean()
{
if (_isInitialized)
{
_pathFactory.Clear();
_workScheduler.Clear();
_resultBuilder.Clear();
_deferredWorkScheduler.Clear();
_schema = default!;
_errorHandler = default!;
_activator = default!;
_diagnosticEvents = default!;
_contextData = default!;
_operation = default!;
_variables = default!;
_services = default!;
_rootValue = null;
_resolveQueryRootValue = default!;
_batchDispatcher = default!;
_isInitialized = false;
}
}
[MethodImpl(MethodImplOptions.AggressiveInlining)]
private void AssertInitialized()
{
if (!_isInitialized)
{
throw Object_Not_Initialized();
}
}
}