-
-
Notifications
You must be signed in to change notification settings - Fork 725
/
UnionTypeFactory.cs
50 lines (43 loc) · 1.39 KB
/
UnionTypeFactory.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
using System;
using HotChocolate.Configuration;
using HotChocolate.Language;
namespace HotChocolate.Types.Factories
{
internal sealed class UnionTypeFactory
: ITypeFactory<UnionTypeDefinitionNode, UnionType>
{
public UnionType Create(
IBindingLookup bindingLookup,
UnionTypeDefinitionNode node)
{
if (bindingLookup is null)
{
throw new ArgumentNullException(nameof(bindingLookup));
}
if (node is null)
{
throw new ArgumentNullException(nameof(node));
}
ITypeBindingInfo bindingInfo =
bindingLookup.GetBindingInfo(node.Name.Value);
return new UnionType(d =>
{
d.SyntaxNode(node)
.Name(node.Name.Value)
.Description(node.Description?.Value);
if (bindingInfo.SourceType != null)
{
d.Extend().OnBeforeCreate(t => t.RuntimeType = bindingInfo.SourceType);
}
foreach (NamedTypeNode namedType in node.Types)
{
d.Type(namedType);
}
foreach (DirectiveNode directive in node.Directives)
{
d.Directive(directive);
}
});
}
}
}