Skip to content

Commit 68a2115

Browse files
authored
[Fusion] Added @fusion__schema_metadata to fusion__Schema enum values (#8508)
1 parent 94823ab commit 68a2115

File tree

11 files changed

+92
-1
lines changed

11 files changed

+92
-1
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
using HotChocolate.Types;
2+
using HotChocolate.Types.Mutable;
3+
using static HotChocolate.Fusion.Properties.CompositionResources;
4+
using static HotChocolate.Fusion.WellKnownDirectiveNames;
5+
using argNames = HotChocolate.Fusion.WellKnownArgumentNames;
6+
7+
namespace HotChocolate.Fusion.Definitions;
8+
9+
/// <summary>
10+
/// The <c>@fusion__schema_metadata</c> directive is used to provide additional metadata for a
11+
/// source schema.
12+
/// </summary>
13+
internal sealed class FusionSchemaMetadataMutableDirectiveDefinition : MutableDirectiveDefinition
14+
{
15+
public FusionSchemaMetadataMutableDirectiveDefinition(MutableScalarTypeDefinition stringType)
16+
: base(FusionSchemaMetadata)
17+
{
18+
Description = FusionSchemaMetadataMutableDirectiveDefinition_Description;
19+
20+
Arguments.Add(new MutableInputFieldDefinition(argNames.Name, new NonNullType(stringType))
21+
{
22+
Description = FusionSchemaMetadataMutableDirectiveDefinition_Argument_Name_Description
23+
});
24+
25+
Locations = DirectiveLocation.EnumValue;
26+
}
27+
}

src/HotChocolate/Fusion-vnext/src/Fusion.Composition/Definitions/FusionSchemaMutableEnumTypeDefinition.cs

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
using System.Collections.Immutable;
2+
using HotChocolate.Types;
23
using HotChocolate.Types.Mutable;
34
using static HotChocolate.Fusion.Properties.CompositionResources;
45
using static HotChocolate.Fusion.StringUtilities;
@@ -19,7 +20,18 @@ public FusionSchemaMutableEnumTypeDefinition(ImmutableArray<string> schemaNames)
1920

2021
foreach (var schemaName in schemaNames)
2122
{
22-
Values.Add(new MutableEnumValue(ToConstantCase(schemaName)));
23+
var enumValue = new MutableEnumValue(ToConstantCase(schemaName))
24+
{
25+
Directives =
26+
{
27+
new Directive(
28+
new FusionSchemaMetadataMutableDirectiveDefinition(
29+
BuiltIns.String.Create()),
30+
new ArgumentAssignment(WellKnownArgumentNames.Name, schemaName))
31+
}
32+
};
33+
34+
Values.Add(enumValue);
2335
}
2436
}
2537
}

src/HotChocolate/Fusion-vnext/src/Fusion.Composition/Properties/CompositionResources.Designer.cs

Lines changed: 18 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/HotChocolate/Fusion-vnext/src/Fusion.Composition/Properties/CompositionResources.resx

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -123,6 +123,12 @@
123123
<data name="FusionRequiresMutableDirectiveDefinition_Description" xml:space="preserve">
124124
<value>The @fusion__requires directive specifies if a field has requirements on a source schema.</value>
125125
</data>
126+
<data name="FusionSchemaMetadataMutableDirectiveDefinition_Argument_Name_Description" xml:space="preserve">
127+
<value>The name of the source schema.</value>
128+
</data>
129+
<data name="FusionSchemaMetadataMutableDirectiveDefinition_Description" xml:space="preserve">
130+
<value>The @fusion__schema_metadata directive is used to provide additional metadata for a source schema.</value>
131+
</data>
126132
<data name="FusionSchemaMutableEnumTypeDefinition_Description" xml:space="preserve">
127133
<value>The fusion__Schema enum is a generated type used within an execution schema document to refer to a source schema in a type-safe manner.</value>
128134
</data>

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

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1235,6 +1235,10 @@ private FrozenDictionary<string, MutableDirectiveDefinition> CreateFusionDirecti
12351235
fieldDefinitionType,
12361236
fieldSelectionMapType)
12371237
},
1238+
{
1239+
DirectiveNames.FusionSchemaMetadata,
1240+
new FusionSchemaMetadataMutableDirectiveDefinition(stringType)
1241+
},
12381242
{
12391243
DirectiveNames.FusionType,
12401244
new FusionTypeMutableDirectiveDefinition(schemaEnumType)

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ internal static class WellKnownArgumentNames
1010
public const string Key = "key";
1111
public const string Map = "map";
1212
public const string Member = "member";
13+
public const string Name = "name";
1314
public const string Partial = "partial";
1415
public const string Path = "path";
1516
public const string Provides = "provides";

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ internal static class WellKnownDirectiveNames
1010
public const string FusionInputField = "fusion__inputField";
1111
public const string FusionLookup = "fusion__lookup";
1212
public const string FusionRequires = "fusion__requires";
13+
public const string FusionSchemaMetadata = "fusion__schema_metadata";
1314
public const string FusionType = "fusion__type";
1415
public const string FusionUnionMember = "fusion__unionMember";
1516
public const string Inaccessible = "inaccessible";

src/HotChocolate/Fusion-vnext/test/Fusion.AspNetCore.Tests/__snapshots__/IntrospectionTests.Download_Schema.graphql

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -71,8 +71,13 @@ type PageInfo {
7171
"The fusion__Schema enum is a generated type used within an execution schema document to refer to a source schema in a type-safe manner."
7272
enum fusion__Schema {
7373
A
74+
@fusion__schema_metadata(name: "A")
7475
B
76+
@fusion__schema_metadata(name: "B")
7577
}
7678

7779
"The @fusion__inaccessible directive is used to prevent specific type system members from being accessible through the client-facing composite schema, even if they are accessible in the underlying source schemas."
7880
directive @fusion__inaccessible on SCALAR | OBJECT | FIELD_DEFINITION | ARGUMENT_DEFINITION | INTERFACE | UNION | ENUM | ENUM_VALUE | INPUT_OBJECT | INPUT_FIELD_DEFINITION
81+
82+
"The @fusion__schema_metadata directive is used to provide additional metadata for a source schema."
83+
directive @fusion__schema_metadata("The name of the source schema." name: String!) on ENUM_VALUE

src/HotChocolate/Fusion-vnext/test/Fusion.CommandLine.Tests/__resources__/invalid-example-1-result/composite-schema.graphqls

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,9 @@ type User
3030
"The fusion__Schema enum is a generated type used within an execution schema document to refer to a source schema in a type-safe manner."
3131
enum fusion__Schema {
3232
SCHEMA1
33+
@fusion__schema_metadata(name: "Schema1")
3334
SCHEMA2
35+
@fusion__schema_metadata(name: "Schema2")
3436
}
3537

3638
"The fusion__FieldDefinition scalar is used to represent a GraphQL field definition specified in the GraphQL spec."
@@ -66,6 +68,9 @@ directive @fusion__lookup("The GraphQL field definition in the source schema tha
6668
"The @fusion__requires directive specifies if a field has requirements on a source schema."
6769
directive @fusion__requires("The GraphQL field definition in the source schema that this field depends on." field: fusion__FieldDefinition! "The map describes how the argument values for the source schema are resolved from the arguments of the field exposed in the client-facing composite schema and from required data relative to the current type." map: [fusion__FieldSelectionMap]! "A selection set on the annotated field that describes its requirements." requirements: fusion__FieldSelectionSet! "The name of the source schema where this field has requirements to data on other source schemas." schema: fusion__Schema!) repeatable on FIELD_DEFINITION
6870

71+
"The @fusion__schema_metadata directive is used to provide additional metadata for a source schema."
72+
directive @fusion__schema_metadata("The name of the source schema." name: String!) on ENUM_VALUE
73+
6974
"The @fusion__type directive specifies which source schemas provide parts of a composite type."
7075
directive @fusion__type("The name of the source schema that originally provided part of the annotated type." schema: fusion__Schema!) repeatable on SCALAR | OBJECT | INTERFACE | UNION | ENUM | INPUT_OBJECT
7176

src/HotChocolate/Fusion-vnext/test/Fusion.CommandLine.Tests/__resources__/valid-example-1-result/composite-schema.graphqls

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,9 @@ type Query
1414
"The fusion__Schema enum is a generated type used within an execution schema document to refer to a source schema in a type-safe manner."
1515
enum fusion__Schema {
1616
SCHEMA1
17+
@fusion__schema_metadata(name: "Schema1")
1718
SCHEMA2
19+
@fusion__schema_metadata(name: "Schema2")
1820
}
1921

2022
"The fusion__FieldDefinition scalar is used to represent a GraphQL field definition specified in the GraphQL spec."
@@ -50,6 +52,9 @@ directive @fusion__lookup("The GraphQL field definition in the source schema tha
5052
"The @fusion__requires directive specifies if a field has requirements on a source schema."
5153
directive @fusion__requires("The GraphQL field definition in the source schema that this field depends on." field: fusion__FieldDefinition! "The map describes how the argument values for the source schema are resolved from the arguments of the field exposed in the client-facing composite schema and from required data relative to the current type." map: [fusion__FieldSelectionMap]! "A selection set on the annotated field that describes its requirements." requirements: fusion__FieldSelectionSet! "The name of the source schema where this field has requirements to data on other source schemas." schema: fusion__Schema!) repeatable on FIELD_DEFINITION
5254

55+
"The @fusion__schema_metadata directive is used to provide additional metadata for a source schema."
56+
directive @fusion__schema_metadata("The name of the source schema." name: String!) on ENUM_VALUE
57+
5358
"The @fusion__type directive specifies which source schemas provide parts of a composite type."
5459
directive @fusion__type("The name of the source schema that originally provided part of the annotated type." schema: fusion__Schema!) repeatable on SCALAR | OBJECT | INTERFACE | UNION | ENUM | INPUT_OBJECT
5560

0 commit comments

Comments
 (0)