Skip to content

Commit 2fc51a3

Browse files
authored
[Fusion] Added fusion__inaccessible to CreateFusionDirectiveDefinitions (#8496)
1 parent 1a8a4b9 commit 2fc51a3

File tree

5 files changed

+42
-29
lines changed

5 files changed

+42
-29
lines changed

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

Lines changed: 34 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,9 @@
1616
using HotChocolate.Types.Mutable;
1717
using static HotChocolate.Fusion.StringUtilities;
1818
using ArgumentNames = HotChocolate.Fusion.WellKnownArgumentNames;
19-
using TypeNames = HotChocolate.Fusion.WellKnownTypeNames;
19+
using DirectiveNames = HotChocolate.Fusion.WellKnownDirectiveNames;
2020
using FieldNames = HotChocolate.Fusion.WellKnownFieldNames;
21+
using TypeNames = HotChocolate.Fusion.WellKnownTypeNames;
2122

2223
namespace HotChocolate.Fusion;
2324

@@ -206,7 +207,7 @@ private static MutableInputFieldDefinition MergeArguments(
206207
if (argumentGroup.Any(i => i.Argument.HasInaccessibleDirective()))
207208
{
208209
mergedArgument.Directives.Add(
209-
new Directive(new FusionInaccessibleMutableDirectiveDefinition()));
210+
new Directive(_fusionDirectiveDefinitions[DirectiveNames.FusionInaccessible]));
210211
}
211212

212213
return mergedArgument;
@@ -240,7 +241,7 @@ private MutableEnumTypeDefinition MergeEnumTypes(
240241
if (typeGroup.Any(i => i.Type.HasInaccessibleDirective()))
241242
{
242243
enumType.Directives.Add(
243-
new Directive(new FusionInaccessibleMutableDirectiveDefinition()));
244+
new Directive(_fusionDirectiveDefinitions[DirectiveNames.FusionInaccessible]));
244245
}
245246

246247
// [EnumValueName: [{EnumValue, EnumType, Schema}, ...], ...].
@@ -281,7 +282,7 @@ private MutableEnumValue MergeEnumValues(ImmutableArray<EnumValueInfo> enumValue
281282
if (enumValueGroup.Any(i => i.EnumValue.HasInaccessibleDirective()))
282283
{
283284
enumValue.Directives.Add(
284-
new Directive(new FusionInaccessibleMutableDirectiveDefinition()));
285+
new Directive(_fusionDirectiveDefinitions[DirectiveNames.FusionInaccessible]));
285286
}
286287

287288
return enumValue;
@@ -317,7 +318,7 @@ private MutableInputObjectTypeDefinition MergeInputTypes(
317318
if (typeGroup.Any(i => i.Type.HasInaccessibleDirective()))
318319
{
319320
inputObjectType.Directives.Add(
320-
new Directive(new FusionInaccessibleMutableDirectiveDefinition()));
321+
new Directive(_fusionDirectiveDefinitions[DirectiveNames.FusionInaccessible]));
321322
}
322323

323324
// [FieldName: [{Field, Type, Schema}, ...], ...].
@@ -377,7 +378,7 @@ private MutableInputFieldDefinition MergeInputFields(
377378
if (inputFieldGroup.Any(i => i.Field.HasInaccessibleDirective()))
378379
{
379380
inputField.Directives.Add(
380-
new Directive(new FusionInaccessibleMutableDirectiveDefinition()));
381+
new Directive(_fusionDirectiveDefinitions[DirectiveNames.FusionInaccessible]));
381382
}
382383

383384
return inputField;
@@ -427,7 +428,7 @@ private MutableInterfaceTypeDefinition MergeInterfaceTypes(
427428
if (typeGroup.Any(i => i.Type.HasInaccessibleDirective()))
428429
{
429430
interfaceType.Directives.Add(
430-
new Directive(new FusionInaccessibleMutableDirectiveDefinition()));
431+
new Directive(_fusionDirectiveDefinitions[DirectiveNames.FusionInaccessible]));
431432
}
432433

433434
// [FieldName: [{Field, Type, Schema}, ...], ...].
@@ -516,7 +517,7 @@ .. typeGroup.Where(
516517
if (typeGroup.Any(i => i.Type.HasInaccessibleDirective()))
517518
{
518519
objectType.Directives.Add(
519-
new Directive(new FusionInaccessibleMutableDirectiveDefinition()));
520+
new Directive(_fusionDirectiveDefinitions[DirectiveNames.FusionInaccessible]));
520521
}
521522

522523
// [FieldName: [{Field, Type, Schema}, ...], ...].
@@ -618,7 +619,7 @@ .. fieldGroup.Where(i => !i.Field.HasInternalDirective() && !i.IsOverridden(grou
618619
if (fieldGroup.Any(i => i.Field.HasInaccessibleDirective()))
619620
{
620621
outputField.Directives.Add(
621-
new Directive(new FusionInaccessibleMutableDirectiveDefinition()));
622+
new Directive(_fusionDirectiveDefinitions[DirectiveNames.FusionInaccessible]));
622623
}
623624

624625
return outputField;
@@ -660,7 +661,7 @@ .. fieldGroup.Where(i => !i.Field.HasInternalDirective() && !i.IsOverridden(grou
660661
if (typeGroup.Any(i => i.Type.HasInaccessibleDirective()))
661662
{
662663
scalarType.Directives.Add(
663-
new Directive(new FusionInaccessibleMutableDirectiveDefinition()));
664+
new Directive(_fusionDirectiveDefinitions[DirectiveNames.FusionInaccessible]));
664665
}
665666

666667
return scalarType;
@@ -710,7 +711,7 @@ private MutableUnionTypeDefinition MergeUnionTypes(
710711
if (typeGroup.Any(i => i.Type.HasInaccessibleDirective()))
711712
{
712713
unionType.Directives.Add(
713-
new Directive(new FusionInaccessibleMutableDirectiveDefinition()));
714+
new Directive(_fusionDirectiveDefinitions[DirectiveNames.FusionInaccessible]));
714715
}
715716

716717
return unionType;
@@ -892,7 +893,7 @@ private void AddFusionEnumValueDirectives(
892893

893894
enumValue.Directives.Add(
894895
new Directive(
895-
_fusionDirectiveDefinitions[WellKnownDirectiveNames.FusionEnumValue],
896+
_fusionDirectiveDefinitions[DirectiveNames.FusionEnumValue],
896897
new ArgumentAssignment(ArgumentNames.Schema, schema)));
897898
}
898899
}
@@ -925,7 +926,7 @@ private void AddFusionFieldDirectives(
925926
}
926927

927928
field.Directives.Add(
928-
new Directive(_fusionDirectiveDefinitions[WellKnownDirectiveNames.FusionField], arguments));
929+
new Directive(_fusionDirectiveDefinitions[DirectiveNames.FusionField], arguments));
929930
}
930931
}
931932

@@ -937,7 +938,7 @@ private void AddFusionImplementsDirectives(
937938
{
938939
complexType.Directives.Add(
939940
new Directive(
940-
_fusionDirectiveDefinitions[WellKnownDirectiveNames.FusionImplements],
941+
_fusionDirectiveDefinitions[DirectiveNames.FusionImplements],
941942
new ArgumentAssignment(
942943
ArgumentNames.Schema,
943944
new EnumValueNode(_schemaConstantNames[sourceSchema])),
@@ -964,7 +965,7 @@ private void AddFusionInputFieldDirectives(
964965

965966
argument.Directives.Add(
966967
new Directive(
967-
_fusionDirectiveDefinitions[WellKnownDirectiveNames.FusionInputField],
968+
_fusionDirectiveDefinitions[DirectiveNames.FusionInputField],
968969
arguments));
969970
}
970971
}
@@ -988,7 +989,7 @@ private void AddFusionInputFieldDirectives(
988989

989990
inputField.Directives.Add(
990991
new Directive(
991-
_fusionDirectiveDefinitions[WellKnownDirectiveNames.FusionInputField],
992+
_fusionDirectiveDefinitions[DirectiveNames.FusionInputField],
992993
arguments));
993994
}
994995
}
@@ -1027,7 +1028,7 @@ private void AddFusionLookupDirectives(
10271028

10281029
type.Directives.Add(
10291030
new Directive(
1030-
_fusionDirectiveDefinitions[WellKnownDirectiveNames.FusionLookup],
1031+
_fusionDirectiveDefinitions[DirectiveNames.FusionLookup],
10311032
new ArgumentAssignment(ArgumentNames.Schema, schemaArgument),
10321033
new ArgumentAssignment(ArgumentNames.Key, keyArgument),
10331034
new ArgumentAssignment(ArgumentNames.Field, fieldArgument),
@@ -1064,7 +1065,7 @@ private void AddFusionRequiresDirectives(
10641065

10651066
foreach (var argument in sourceField.Arguments)
10661067
{
1067-
var requireDirective = argument.Directives.FirstOrDefault(WellKnownDirectiveNames.Require);
1068+
var requireDirective = argument.Directives.FirstOrDefault(DirectiveNames.Require);
10681069

10691070
if (requireDirective?.Arguments[ArgumentNames.Field] is StringValueNode fieldArg)
10701071
{
@@ -1107,7 +1108,7 @@ private void AddFusionRequiresDirectives(
11071108

11081109
field.Directives.Add(
11091110
new Directive(
1110-
_fusionDirectiveDefinitions[WellKnownDirectiveNames.FusionRequires],
1111+
_fusionDirectiveDefinitions[DirectiveNames.FusionRequires],
11111112
new ArgumentAssignment(ArgumentNames.Schema, schemaArgument),
11121113
new ArgumentAssignment(ArgumentNames.Requirements, requirementsArgument),
11131114
new ArgumentAssignment(ArgumentNames.Field, fieldArgument),
@@ -1126,7 +1127,7 @@ private void AddFusionTypeDirectives(
11261127

11271128
type.Directives.Add(
11281129
new Directive(
1129-
_fusionDirectiveDefinitions[WellKnownDirectiveNames.FusionType],
1130+
_fusionDirectiveDefinitions[DirectiveNames.FusionType],
11301131
new ArgumentAssignment(ArgumentNames.Schema, schema)));
11311132
}
11321133
}
@@ -1141,7 +1142,7 @@ private void AddFusionUnionMemberDirectives(
11411142

11421143
unionType.Directives.Add(
11431144
new Directive(
1144-
_fusionDirectiveDefinitions[WellKnownDirectiveNames.FusionUnionMember],
1145+
_fusionDirectiveDefinitions[DirectiveNames.FusionUnionMember],
11451146
new ArgumentAssignment(ArgumentNames.Schema, schema),
11461147
new ArgumentAssignment(ArgumentNames.Member, sourceMemberType.Name)));
11471148
}
@@ -1194,27 +1195,31 @@ private FrozenDictionary<string, MutableDirectiveDefinition> CreateFusionDirecti
11941195
return new Dictionary<string, MutableDirectiveDefinition>()
11951196
{
11961197
{
1197-
WellKnownDirectiveNames.FusionEnumValue,
1198+
DirectiveNames.FusionEnumValue,
11981199
new FusionEnumValueMutableDirectiveDefinition(schemaEnumType)
11991200
},
12001201
{
1201-
WellKnownDirectiveNames.FusionField,
1202+
DirectiveNames.FusionField,
12021203
new FusionFieldMutableDirectiveDefinition(
12031204
schemaEnumType,
12041205
stringType,
12051206
fieldSelectionSetType,
12061207
booleanType)
12071208
},
12081209
{
1209-
WellKnownDirectiveNames.FusionImplements,
1210+
DirectiveNames.FusionImplements,
12101211
new FusionImplementsMutableDirectiveDefinition(schemaEnumType, stringType)
12111212
},
12121213
{
1213-
WellKnownDirectiveNames.FusionInputField,
1214+
DirectiveNames.FusionInaccessible,
1215+
new FusionInaccessibleMutableDirectiveDefinition()
1216+
},
1217+
{
1218+
DirectiveNames.FusionInputField,
12141219
new FusionInputFieldMutableDirectiveDefinition(schemaEnumType, stringType)
12151220
},
12161221
{
1217-
WellKnownDirectiveNames.FusionLookup,
1222+
DirectiveNames.FusionLookup,
12181223
new FusionLookupMutableDirectiveDefinition(
12191224
schemaEnumType,
12201225
fieldSelectionSetType,
@@ -1223,19 +1228,19 @@ private FrozenDictionary<string, MutableDirectiveDefinition> CreateFusionDirecti
12231228
fieldSelectionPathType)
12241229
},
12251230
{
1226-
WellKnownDirectiveNames.FusionRequires,
1231+
DirectiveNames.FusionRequires,
12271232
new FusionRequiresMutableDirectiveDefinition(
12281233
schemaEnumType,
12291234
fieldSelectionSetType,
12301235
fieldDefinitionType,
12311236
fieldSelectionMapType)
12321237
},
12331238
{
1234-
WellKnownDirectiveNames.FusionType,
1239+
DirectiveNames.FusionType,
12351240
new FusionTypeMutableDirectiveDefinition(schemaEnumType)
12361241
},
12371242
{
1238-
WellKnownDirectiveNames.FusionUnionMember,
1243+
DirectiveNames.FusionUnionMember,
12391244
new FusionUnionMemberMutableDirectiveDefinition(schemaEnumType, stringType)
12401245
}
12411246
}.ToFrozenDictionary();

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

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -72,3 +72,5 @@ enum fusion__Schema {
7272
A
7373
B
7474
}
75+
76+
directive @fusion__inaccessible on SCALAR | OBJECT | FIELD_DEFINITION | ARGUMENT_DEFINITION | INTERFACE | UNION | ENUM | ENUM_VALUE | INPUT_OBJECT | INPUT_FIELD_DEFINITION

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

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,8 @@ directive @fusion__field("Indicates that this field is only partially provided a
4949
"The @fusion__implements directive specifies on which source schema an interface is implemented by an object or interface type."
5050
directive @fusion__implements("The name of the interface type." interface: String! "The name of the source schema on which the annotated type implements the specified interface." schema: fusion__Schema!) repeatable on OBJECT | INTERFACE
5151

52+
directive @fusion__inaccessible on SCALAR | OBJECT | FIELD_DEFINITION | ARGUMENT_DEFINITION | INTERFACE | UNION | ENUM | ENUM_VALUE | INPUT_OBJECT | INPUT_FIELD_DEFINITION
53+
5254
"The @fusion__inputField directive specifies which source schema provides an input field in a composite input type."
5355
directive @fusion__inputField("The name of the source schema that originally provided this input field." schema: fusion__Schema! "The field type in the source schema if it differs in nullability or structure." sourceType: String) repeatable on ARGUMENT_DEFINITION | INPUT_FIELD_DEFINITION
5456

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

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,8 @@ directive @fusion__field("Indicates that this field is only partially provided a
3333
"The @fusion__implements directive specifies on which source schema an interface is implemented by an object or interface type."
3434
directive @fusion__implements("The name of the interface type." interface: String! "The name of the source schema on which the annotated type implements the specified interface." schema: fusion__Schema!) repeatable on OBJECT | INTERFACE
3535

36+
directive @fusion__inaccessible on SCALAR | OBJECT | FIELD_DEFINITION | ARGUMENT_DEFINITION | INTERFACE | UNION | ENUM | ENUM_VALUE | INPUT_OBJECT | INPUT_FIELD_DEFINITION
37+
3638
"The @fusion__inputField directive specifies which source schema provides an input field in a composite input type."
3739
directive @fusion__inputField("The name of the source schema that originally provided this input field." schema: fusion__Schema! "The field type in the source schema if it differs in nullability or structure." sourceType: String) repeatable on ARGUMENT_DEFINITION | INPUT_FIELD_DEFINITION
3840

src/HotChocolate/Fusion-vnext/test/Fusion.Composition.Tests/__snapshots__/SourceSchemaMergerTests.Merge_FourNamedSchemas_AddsFusionDefinitions.graphql

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,8 @@ directive @fusion__field("Indicates that this field is only partially provided a
2222
"The @fusion__implements directive specifies on which source schema an interface is implemented by an object or interface type."
2323
directive @fusion__implements("The name of the interface type." interface: String! "The name of the source schema on which the annotated type implements the specified interface." schema: fusion__Schema!) repeatable on OBJECT | INTERFACE
2424

25+
directive @fusion__inaccessible on SCALAR | OBJECT | FIELD_DEFINITION | ARGUMENT_DEFINITION | INTERFACE | UNION | ENUM | ENUM_VALUE | INPUT_OBJECT | INPUT_FIELD_DEFINITION
26+
2527
"The @fusion__inputField directive specifies which source schema provides an input field in a composite input type."
2628
directive @fusion__inputField("The name of the source schema that originally provided this input field." schema: fusion__Schema! "The field type in the source schema if it differs in nullability or structure." sourceType: String) repeatable on ARGUMENT_DEFINITION | INPUT_FIELD_DEFINITION
2729

0 commit comments

Comments
 (0)