-
-
Notifications
You must be signed in to change notification settings - Fork 722
/
ArgumentScopedVariableResolver.cs
59 lines (53 loc) · 1.88 KB
/
ArgumentScopedVariableResolver.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
using System;
using System.Linq;
using HotChocolate.Language;
using HotChocolate.Resolvers;
using HotChocolate.Stitching.Properties;
using HotChocolate.Types;
using HotChocolate.Utilities;
using static HotChocolate.Stitching.ThrowHelper;
using static HotChocolate.Stitching.Properties.StitchingResources;
namespace HotChocolate.Stitching.Delegation.ScopedVariables
{
internal class ArgumentScopedVariableResolver : IScopedVariableResolver
{
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 (!ScopeNames.Arguments.Equals(variable.Scope.Value))
{
throw new ArgumentException(
ArgumentScopedVariableResolver_CannotHandleVariable,
nameof(variable));
}
IInputField? argument = context.Field.Arguments.FirstOrDefault(
t => t.Name.Value.EqualsOrdinal(variable.Name.Value));
if (argument is null)
{
throw ArgumentScopedVariableResolver_InvalidArgumentName(
variable.Name.Value,
context.FieldSelection,
context.Path);
}
return new VariableValue
(
variable.ToVariableName(),
argument.Type.ToTypeNode(),
context.ArgumentLiteral<IValueNode>(variable.Name.Value),
argument.Type.IsNonNullType() && argument.DefaultValue.IsNull()
? null
: argument.DefaultValue
);
}
}
}