Skip to content

Commit 4dce3e3

Browse files
tobias-tenglermichaelstaib
authored andcommitted
Ignore type members in TypeInspector (#8389)
1 parent 4cbc751 commit 4dce3e3

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
@@ -715,8 +715,9 @@ private bool CanBeHandled(
715715
return false;
716716
}
717717

718-
if(member.IsDefined(typeof(GraphQLTypeAttribute), true) ||
719-
member.IsDefined(typeof(DescriptorAttribute), true))
718+
if ((member.IsDefined(typeof(GraphQLTypeAttribute), true) ||
719+
member.IsDefined(typeof(DescriptorAttribute), true)) &&
720+
member is PropertyInfo or MethodInfo)
720721
{
721722
return true;
722723
}

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

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

2128+
[Fact]
2129+
public async Task Ignore_Type_Members()
2130+
{
2131+
var schema = await new ServiceCollection()
2132+
.AddGraphQL()
2133+
.AddQueryType<QueryWithTypeExtension>()
2134+
.AddTypeExtension<QueryWithTypeExtension.SomeClassExtension>()
2135+
.BuildSchemaAsync();
2136+
2137+
schema.MatchSnapshot();
2138+
}
2139+
2140+
[GraphQLName("Query")]
2141+
public class QueryWithTypeExtension
2142+
{
2143+
public SomeClass GetSomeClass() => null!;
2144+
2145+
[ExtendObjectType("SomeClass")]
2146+
public class SomeClassExtension
2147+
{
2148+
public int SomethingElse { get; set; }
2149+
}
2150+
}
2151+
2152+
public class SomeClass
2153+
{
2154+
public int Something { get; set; }
2155+
}
2156+
21282157
public abstract class ResolverBase
21292158
{
21302159
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)