/
RequestContext.cs
63 lines (54 loc) · 2.13 KB
/
RequestContext.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
using System;
using System.Collections.Concurrent;
using System.Collections.Generic;
using HotChocolate.Execution.Instrumentation;
using HotChocolate.Language;
using HotChocolate.Resolvers;
using HotChocolate.Types;
using Microsoft.Extensions.DependencyInjection;
namespace HotChocolate.Execution
{
internal class RequestContext
: IRawRequestContext
{
private readonly Func<ObjectField, FieldNode, FieldDelegate> _factory;
public RequestContext(
IRequestServiceScope serviceScope,
Func<ObjectField, FieldNode, FieldDelegate> middlewareFactory,
ICachedQuery cachedQuery,
IDictionary<string, object> contextData,
QueryExecutionDiagnostics diagnostics)
{
ServiceScope = serviceScope
?? throw new ArgumentNullException(nameof(serviceScope));
_factory = middlewareFactory
?? throw new ArgumentNullException(nameof(middlewareFactory));
CachedQuery = cachedQuery
?? throw new ArgumentNullException(nameof(cachedQuery));
ContextData = contextData
?? throw new ArgumentNullException(nameof(contextData));
Diagnostics = diagnostics
?? throw new ArgumentNullException(nameof(diagnostics));
}
public IRequestServiceScope ServiceScope { get; }
public IDictionary<string, object> ContextData { get; }
public QueryExecutionDiagnostics Diagnostics { get; }
public ICachedQuery CachedQuery { get; }
public FieldDelegate ResolveMiddleware(
ObjectField field,
FieldNode selection)
{
return _factory(field, selection);
}
public IRawRequestContext Clone()
{
IServiceScope serviceScope = ServiceScope.ServiceProvider.CreateScope();
return new RequestContext(
new RequestServiceScope(serviceScope.ServiceProvider, serviceScope),
_factory,
CachedQuery,
new ConcurrentDictionary<string, object>(ContextData),
Diagnostics);
}
}
}