Skip to content

Commit 4128aaa

Browse files
[Fusion] Remove descriptions from field definitions in @fusion__ directives (#8679)
1 parent 7f8f9e5 commit 4128aaa

File tree

4 files changed

+68
-15
lines changed

4 files changed

+68
-15
lines changed

src/HotChocolate/Fusion-vnext/src/Fusion.Composition/SourceSchemaMerger.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ namespace HotChocolate.Fusion;
2424

2525
internal sealed class SourceSchemaMerger
2626
{
27-
private static readonly RemoveDirectiveNodesSyntaxRewriter s_removeDirectivesRewriter = new();
27+
private static readonly FusionFieldDefinitionSyntaxRewriter s_fieldDefinitionRewriter = new();
2828
private readonly ImmutableSortedSet<MutableSchemaDefinition> _schemas;
2929
private readonly FrozenDictionary<MutableSchemaDefinition, string> _schemaConstantNames;
3030
private readonly SourceSchemaMergerOptions _options;
@@ -1026,7 +1026,7 @@ private void AddFusionLookupDirectives(
10261026
mergedSelectionSet.ToString(indented: false).AsSpan()[2..^2].ToString();
10271027

10281028
var fieldArgument =
1029-
s_removeDirectivesRewriter
1029+
s_fieldDefinitionRewriter
10301030
.Rewrite(sourceField.ToSyntaxNode())!
10311031
.ToString(indented: false);
10321032

@@ -1111,7 +1111,7 @@ private void AddFusionRequiresDirectives(
11111111
mergedSelectionSet.ToString(indented: false).AsSpan()[2..^2].ToString();
11121112

11131113
var fieldArgument =
1114-
s_removeDirectivesRewriter
1114+
s_fieldDefinitionRewriter
11151115
.Rewrite(sourceField.ToSyntaxNode())!
11161116
.ToString(indented: false);
11171117

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
using HotChocolate.Language;
2+
using HotChocolate.Language.Visitors;
3+
4+
namespace HotChocolate.Fusion.SyntaxRewriters;
5+
6+
/// <summary>
7+
/// Rewrites a field definition to remove any directives and descriptions.
8+
/// </summary>
9+
public sealed class FusionFieldDefinitionSyntaxRewriter : SyntaxRewriter<object?>
10+
{
11+
protected override DirectiveNode? RewriteDirective(DirectiveNode node, object? context)
12+
{
13+
return null;
14+
}
15+
16+
protected override FieldDefinitionNode? RewriteFieldDefinition(FieldDefinitionNode node, object? context)
17+
{
18+
var rewrittenNode = base.RewriteFieldDefinition(node, context);
19+
return rewrittenNode?.WithDescription(null);
20+
}
21+
22+
protected override InputValueDefinitionNode? RewriteInputValueDefinition(
23+
InputValueDefinitionNode node,
24+
object? context)
25+
{
26+
var rewrittenNode = base.RewriteInputValueDefinition(node, context);
27+
28+
return rewrittenNode?.WithDescription(null);
29+
}
30+
}

src/HotChocolate/Fusion-vnext/src/Fusion.Utilities/SyntaxRewriters/RemoveDirectiveNodesSyntaxRewriter.cs

Lines changed: 0 additions & 12 deletions
This file was deleted.

src/HotChocolate/Fusion-vnext/test/Fusion.Composition.Tests/SourceSchemaMerger.Object.Tests.cs

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -569,6 +569,41 @@ type Product
569569
@fusion__field(schema: A)
570570
}
571571
"""
572+
},
573+
// Lookup field and argument have a description
574+
{
575+
[
576+
"""
577+
type Query {
578+
"Fetches a product"
579+
productById("The product id" id: ID!): Product @lookup
580+
}
581+
582+
type Product @key(fields: "id") {
583+
id: ID!
584+
}
585+
"""
586+
],
587+
"""
588+
schema {
589+
query: Query
590+
}
591+
592+
type Query
593+
@fusion__type(schema: A) {
594+
"Fetches a product"
595+
productById("The product id" id: ID!
596+
@fusion__inputField(schema: A)): Product
597+
@fusion__field(schema: A)
598+
}
599+
600+
type Product
601+
@fusion__type(schema: A)
602+
@fusion__lookup(schema: A, key: "id", field: "productById(id: ID!): Product", map: [ "id" ], path: null, internal: false) {
603+
id: ID!
604+
@fusion__field(schema: A)
605+
}
606+
"""
572607
}
573608
};
574609
}

0 commit comments

Comments
 (0)