-
-
Notifications
You must be signed in to change notification settings - Fork 722
/
ObjectTypeAttribute.cs
64 lines (53 loc) · 1.59 KB
/
ObjectTypeAttribute.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
using System;
using HotChocolate.Internal;
using HotChocolate.Types.Descriptors;
using static HotChocolate.Types.FieldBindingFlags;
#nullable enable
namespace HotChocolate.Types;
/// <summary>
/// Specifies that the annotated class, struct or interface shall be
/// interpreted as a GraphQL object type.
/// </summary>
[AttributeUsage(
AttributeTargets.Class |
AttributeTargets.Struct |
AttributeTargets.Interface)]
public sealed class ObjectTypeAttribute
: ObjectTypeDescriptorAttribute
, ITypeAttribute
{
public ObjectTypeAttribute(string? name = null)
{
Name = name;
}
/// <summary>
/// Gets or sets the GraphQL type name.
/// </summary>
public string? Name { get; set; }
/// <summary>
/// Defines if this attribute is inherited. The default is <c>false</c>.
/// </summary>
public bool Inherited { get; set; }
/// <summary>
/// Defines that static members are included.
/// </summary>
public bool IncludeStaticMembers { get; set; }
TypeKind ITypeAttribute.Kind => TypeKind.Object;
bool ITypeAttribute.IsTypeExtension => false;
protected override void OnConfigure(
IDescriptorContext context,
IObjectTypeDescriptor descriptor,
Type type)
{
if (!string.IsNullOrEmpty(Name))
{
descriptor.Name(Name);
}
var definition = descriptor.Extend().Definition;
definition.Fields.BindingBehavior = BindingBehavior.Implicit;
if (IncludeStaticMembers)
{
definition.FieldBindingFlags = Instance | Static;
}
}
}