-
-
Notifications
You must be signed in to change notification settings - Fork 725
/
RootScopedVariableResolver.cs
48 lines (43 loc) · 1.62 KB
/
RootScopedVariableResolver.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
using System;
using System.Collections.Generic;
using HotChocolate.Execution;
using HotChocolate.Resolvers;
using HotChocolate.Stitching.Properties;
using HotChocolate.Types;
namespace HotChocolate.Stitching.Delegation.ScopedVariables
{
internal class RootScopedVariableResolver
: IScopedVariableResolver
{
private readonly Dictionary<string, IScopedVariableResolver> _resolvers =
new Dictionary<string, IScopedVariableResolver>
{
{ ScopeNames.Arguments, new ArgumentScopedVariableResolver() },
{ ScopeNames.Fields, new FieldScopedVariableResolver() },
{ ScopeNames.ContextData, new ContextDataScopedVariableResolver() },
{ ScopeNames.ScopedContextData, new ScopedContextDataScopedVariableResolver() }
};
public VariableValue Resolve(
IResolverContext context,
ScopedVariableNode variable,
IInputType targetType)
{
if (context is null)
{
throw new ArgumentNullException(nameof(context));
}
if (variable is null)
{
throw new ArgumentNullException(nameof(variable));
}
if (_resolvers.TryGetValue(variable.Scope.Value, out IScopedVariableResolver? resolver))
{
return resolver.Resolve(context, variable, targetType);
}
throw ThrowHelper.RootScopedVariableResolver_ScopeNotSupported(
variable.Scope.Value,
context.FieldSelection,
context.Path);
}
}
}