Skip to content

Commit ad98734

Browse files
authored
Accept structs in ObjectTypeAttribute<T> (#7116)
1 parent b17aca0 commit ad98734

File tree

3 files changed

+18
-2
lines changed

3 files changed

+18
-2
lines changed

src/HotChocolate/Core/src/Types/Types/Attributes/ObjectTypeAttribute.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -68,9 +68,9 @@ protected override void OnConfigure(
6868
/// interpreted as a GraphQL object type.
6969
/// This class is used by the Hot Chocolate source generator.
7070
/// </summary>
71-
[AttributeUsage(AttributeTargets.Class)]
71+
[AttributeUsage(AttributeTargets.Class | AttributeTargets.Struct)]
7272
public sealed class ObjectTypeAttribute<T>
73-
: Attribute where T : class
73+
: Attribute
7474
{
7575
public Type Type => typeof(T);
7676
}

src/HotChocolate/Core/test/Types.Analyzers.Tests/BookType.cs

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,15 +13,25 @@ public class Book
1313
public string? Title { get; set; }
1414

1515
public Author? Author => null;
16+
17+
public Publisher? Publisher => null;
1618
}
1719

1820
public class Author
1921
{
2022
public string Name { get; set; } = default!;
2123
}
2224

25+
public readonly record struct Publisher(string Name);
26+
2327
[ObjectType<Author>]
2428
public static partial class AuthorNode
2529
{
2630
public static string Address([Parent] Author author) => "something";
2731
}
32+
33+
[ObjectType<Publisher>]
34+
public static partial class PublisherNode
35+
{
36+
public static string Company([Parent] Publisher author) => "something";
37+
}

src/HotChocolate/Core/test/Types.Analyzers.Tests/__snapshots__/SchemaTests.SchemaSnapshot.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,11 @@ type Person implements Node & Entity {
3333
address: String!
3434
}
3535

36+
type Publisher {
37+
company: String!
38+
name: String!
39+
}
40+
3641
type Query {
3742
"Fetches an object given its ID."
3843
node("ID of the object." id: ID!): Node
@@ -50,6 +55,7 @@ type Query {
5055
type SomeBook {
5156
title: String
5257
author: Author
58+
publisher: Publisher
5359
}
5460

5561
type Subscription {

0 commit comments

Comments
 (0)