Skip to content

Commit 9a9d0ca

Browse files
glen-84michaelstaib
authored andcommitted
Prevented type descriptions from being overwritten while merging (#7751)
1 parent 3d6748b commit 9a9d0ca

File tree

4 files changed

+55
-1
lines changed

4 files changed

+55
-1
lines changed

src/HotChocolate/Core/src/Types/Types/Descriptors/Definitions/DefinitionBase.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -199,7 +199,7 @@ protected void MergeInto(DefinitionBase target)
199199
}
200200
}
201201

202-
if (Description is not null)
202+
if (target.Description is null && Description is not null)
203203
{
204204
target.Description = Description;
205205
}
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
namespace HotChocolate.Types.Descriptors;
2+
3+
/// <summary>
4+
/// QueryExtWithDocs1
5+
/// </summary>
6+
[QueryType]
7+
public static class QueryExtWithDocs1
8+
{
9+
public static int GetFoo1() => 1;
10+
}
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
namespace HotChocolate.Types.Descriptors;
2+
3+
/// <summary>
4+
/// QueryExtWithDocs2
5+
/// </summary>
6+
[QueryType]
7+
public static class QueryExtWithDocs2
8+
{
9+
public static int GetFoo2() => 1;
10+
}
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
using CookieCrumble;
2+
using HotChocolate.Execution;
3+
using Microsoft.Extensions.DependencyInjection;
4+
5+
namespace HotChocolate.Types.Descriptors.Definitions;
6+
7+
public class DefinitionBaseTests
8+
{
9+
[Fact]
10+
public async Task MergeInto_MultipleTypeExtensionXmlDescriptions_UsesQueryTypeDescription()
11+
{
12+
// arrange & act
13+
var schema = await new ServiceCollection()
14+
.AddGraphQL()
15+
.AddQueryType(d => d.Description("Query"))
16+
.AddTypeExtension(typeof(QueryExtWithDocs1))
17+
.AddTypeExtension(typeof(QueryExtWithDocs2))
18+
.BuildSchemaAsync();
19+
20+
// assert
21+
schema.MatchInlineSnapshot(
22+
"""
23+
schema {
24+
query: Query
25+
}
26+
27+
"Query"
28+
type Query {
29+
foo1: Int!
30+
foo2: Int!
31+
}
32+
""");
33+
}
34+
}

0 commit comments

Comments
 (0)