-
-
Notifications
You must be signed in to change notification settings - Fork 722
/
InputObjectType.cs
93 lines (81 loc) · 2.84 KB
/
InputObjectType.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
using System;
using HotChocolate.Language;
using HotChocolate.Types.Descriptors.Definitions;
#nullable enable
namespace HotChocolate.Types;
/// <summary>
/// <para>
/// A GraphQL Input Object defines a set of input fields; the input fields are either scalars,
/// enums, or other input objects. This allows arguments to accept arbitrarily complex structs.
/// </para>
/// <para>In this example, an Input Object called Point2D describes x and y inputs:</para>
///
/// <code>
/// input Point2D {
/// x: Float
/// y: Float
/// }
/// </code>
/// </summary>
public partial class InputObjectType
: NamedTypeBase<InputObjectTypeDefinition>
, IInputObjectType
{
/// <summary>
/// Initializes a new instance of <see cref="InputObjectType"/>.
/// </summary>
protected InputObjectType()
{
_configure = Configure;
}
/// <summary>
/// Initializes a new instance of <see cref="InputObjectType"/>.
/// </summary>
/// <param name="configure">
/// A delegate to specify the properties of this type.
/// </param>
/// <exception cref="ArgumentNullException">
/// <paramref name="configure"/> is <c>null</c>.
/// </exception>
public InputObjectType(Action<IInputObjectTypeDescriptor> configure)
{
_configure = configure ?? throw new ArgumentNullException(nameof(configure));
}
/// <summary>
/// Create an input object type from a type definition.
/// </summary>
/// <param name="definition">
/// The input object type definition that specifies the properties of the
/// newly created input object type.
/// </param>
/// <returns>
/// Returns the newly created input object type.
/// </returns>
public static InputObjectType CreateUnsafe(InputObjectTypeDefinition definition)
=> new() { Definition = definition };
/// <inheritdoc />
public override TypeKind Kind => TypeKind.InputObject;
/// <summary>
/// Gets the GraphQL syntax representation of this type
/// if it was provided during initialization.
/// </summary>
public InputObjectTypeDefinitionNode? SyntaxNode { get; private set; }
/// <summary>
/// Gets the fields of this type.
/// </summary>
public FieldCollection<InputField> Fields { get; private set; } = default!;
IFieldCollection<IInputField> IInputObjectType.Fields => Fields;
internal object CreateInstance(object?[] fieldValues)
=> _createInstance(fieldValues);
internal void GetFieldValues(object runtimeValue, object?[] fieldValues)
=> _getFieldValues(runtimeValue, fieldValues);
/// <summary>
/// Override this to configure the type.
/// </summary>
/// <param name="descriptor">
/// The descriptor allows to configure the interface type.
/// </param>
protected virtual void Configure(IInputObjectTypeDescriptor descriptor)
{
}
}