Skip to content

Commit cd76363

Browse files
Ignore type members in TypeInspector (#8389)
1 parent 09c3585 commit cd76363

File tree

3 files changed

+44
-2
lines changed

3 files changed

+44
-2
lines changed

src/HotChocolate/Core/src/Types/Types/Descriptors/Conventions/DefaultTypeInspector.cs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -643,8 +643,9 @@ private bool CanBeHandled(
643643
return false;
644644
}
645645

646-
if (member.IsDefined(typeof(GraphQLTypeAttribute), true) ||
647-
member.IsDefined(typeof(DescriptorAttribute), true))
646+
if ((member.IsDefined(typeof(GraphQLTypeAttribute), true) ||
647+
member.IsDefined(typeof(DescriptorAttribute), true)) &&
648+
member is PropertyInfo or MethodInfo)
648649
{
649650
return true;
650651
}

src/HotChocolate/Core/test/Types.Tests/Types/ObjectTypeTests.cs

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2124,6 +2124,35 @@ public async Task Ignore_Object_Lists()
21242124
schema.MatchSnapshot();
21252125
}
21262126

2127+
[Fact]
2128+
public async Task Ignore_Type_Members()
2129+
{
2130+
var schema = await new ServiceCollection()
2131+
.AddGraphQL()
2132+
.AddQueryType<QueryWithTypeExtension>()
2133+
.AddTypeExtension<QueryWithTypeExtension.SomeClassExtension>()
2134+
.BuildSchemaAsync();
2135+
2136+
schema.MatchSnapshot();
2137+
}
2138+
2139+
[GraphQLName("Query")]
2140+
public class QueryWithTypeExtension
2141+
{
2142+
public SomeClass GetSomeClass() => null!;
2143+
2144+
[ExtendObjectType("SomeClass")]
2145+
public class SomeClassExtension
2146+
{
2147+
public int SomethingElse { get; set; }
2148+
}
2149+
}
2150+
2151+
public class SomeClass
2152+
{
2153+
public int Something { get; set; }
2154+
}
2155+
21272156
public abstract class ResolverBase
21282157
{
21292158
public int GetValue() => 1024;
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
schema {
2+
query: Query
3+
}
4+
5+
type Query {
6+
someClass: SomeClass
7+
}
8+
9+
type SomeClass {
10+
something: Int!
11+
somethingElse: Int!
12+
}

0 commit comments

Comments
 (0)