diff --git a/graphql-java-support/src/main/java/com/apollographql/federation/graphqljava/Federation.java b/graphql-java-support/src/main/java/com/apollographql/federation/graphqljava/Federation.java index fb86503a..f30ecbd4 100644 --- a/graphql-java-support/src/main/java/com/apollographql/federation/graphqljava/Federation.java +++ b/graphql-java-support/src/main/java/com/apollographql/federation/graphqljava/Federation.java @@ -3,6 +3,7 @@ import static com.apollographql.federation.graphqljava.directives.LinkDirectiveProcessor.loadFederationImportedDefinitions; import graphql.language.DirectiveDefinition; +import graphql.language.EnumTypeDefinition; import graphql.language.FieldDefinition; import graphql.language.ObjectTypeDefinition; import graphql.language.SDLNamedDefinition; @@ -160,9 +161,8 @@ private static RuntimeWiring ensureFederationV2DirectiveDefinitionsExist( if (def instanceof DirectiveDefinition && !typeRegistry.getDirectiveDefinition(def.getName()).isPresent()) { typeRegistry.add(def); - } - if (def instanceof ScalarTypeDefinition - && !runtimeWiring.getScalars().containsKey(def.getName())) { + } else if (def instanceof ScalarTypeDefinition + && !typeRegistry.scalars().containsKey(def.getName())) { typeRegistry.add(def); scalarTypesToAdd.add( GraphQLScalarType.newScalar() @@ -170,6 +170,9 @@ private static RuntimeWiring ensureFederationV2DirectiveDefinitionsExist( .description(null) .coercing(_Any.type.getCoercing()) .build()); + } else if (def instanceof EnumTypeDefinition + && !typeRegistry.types().containsKey(def.getName())) { + typeRegistry.add(def); } }); diff --git a/graphql-java-support/src/main/java/com/apollographql/federation/graphqljava/directives/LinkImportsRenamingVisitor.java b/graphql-java-support/src/main/java/com/apollographql/federation/graphqljava/directives/LinkImportsRenamingVisitor.java index 5f017b08..04634afd 100644 --- a/graphql-java-support/src/main/java/com/apollographql/federation/graphqljava/directives/LinkImportsRenamingVisitor.java +++ b/graphql-java-support/src/main/java/com/apollographql/federation/graphqljava/directives/LinkImportsRenamingVisitor.java @@ -4,6 +4,7 @@ import com.apollographql.federation.graphqljava.exceptions.UnsupportedRenameException; import graphql.language.DirectiveDefinition; +import graphql.language.EnumTypeDefinition; import graphql.language.NamedNode; import graphql.language.Node; import graphql.language.NodeVisitorStub; @@ -43,6 +44,9 @@ protected TraversalControl visitNode(Node node, TraverserContext context) } else if (node instanceof DirectiveDefinition) { String newName = newName(((NamedNode) node).getName(), fed2Imports, true); newNode = ((DirectiveDefinition) node).transform(builder -> builder.name(newName)); + } else if (node instanceof EnumTypeDefinition) { + String newName = newName(((NamedNode) node).getName(), fed2Imports, true); + newNode = ((EnumTypeDefinition) node).transform(builder -> builder.name(newName)); } if (newNode != null) { return changeNode(context, newNode); @@ -78,7 +82,7 @@ private String newName(String name, Map fed2Imports, boolean isD } else { if (name.equals("inaccessible") || name.equals("tag")) { return name; - } else if (name.equals("Import")) { + } else if (name.equals("Import") || name.equals("Purpose")) { return "link__" + name; } else { // apply default namespace diff --git a/graphql-java-support/src/main/resources/definitions_fed2_0.graphqls b/graphql-java-support/src/main/resources/definitions_fed2_0.graphqls index 4ece1778..3166ba79 100644 --- a/graphql-java-support/src/main/resources/definitions_fed2_0.graphqls +++ b/graphql-java-support/src/main/resources/definitions_fed2_0.graphqls @@ -40,7 +40,13 @@ scalar FieldSet directive @link( url: String!, as: String, - import: [Import]) + import: [Import], + for: Purpose) repeatable on SCHEMA scalar Import + +enum Purpose { + SECURITY + EXECUTION +} diff --git a/graphql-java-support/src/main/resources/definitions_fed2_1.graphqls b/graphql-java-support/src/main/resources/definitions_fed2_1.graphqls index 5d39d31e..462a4cd4 100644 --- a/graphql-java-support/src/main/resources/definitions_fed2_1.graphqls +++ b/graphql-java-support/src/main/resources/definitions_fed2_1.graphqls @@ -33,12 +33,6 @@ directive @tag(name: String!) repeatable on | INPUT_FIELD_DEFINITION scalar FieldSet -# -# federation-v2.1 -# - -directive @composeDirective(name: String!) repeatable on SCHEMA - # # https://specs.apollo.dev/link/v1.0/link-v1.0.graphql # @@ -46,7 +40,19 @@ directive @composeDirective(name: String!) repeatable on SCHEMA directive @link( url: String!, as: String, - import: [Import]) + import: [Import], + for: Purpose) repeatable on SCHEMA scalar Import + +enum Purpose { + SECURITY + EXECUTION +} + +# +# federation-v2.1 +# + +directive @composeDirective(name: String!) repeatable on SCHEMA diff --git a/graphql-java-support/src/main/resources/definitions_fed2_2.graphqls b/graphql-java-support/src/main/resources/definitions_fed2_2.graphqls index de346da0..112a355f 100644 --- a/graphql-java-support/src/main/resources/definitions_fed2_2.graphqls +++ b/graphql-java-support/src/main/resources/definitions_fed2_2.graphqls @@ -32,12 +32,6 @@ directive @tag(name: String!) repeatable on | INPUT_FIELD_DEFINITION scalar FieldSet -# -# federation-v2.1 -# - -directive @composeDirective(name: String!) repeatable on SCHEMA - # # https://specs.apollo.dev/link/v1.0/link-v1.0.graphql # @@ -45,11 +39,23 @@ directive @composeDirective(name: String!) repeatable on SCHEMA directive @link( url: String!, as: String, - import: [Import]) + import: [Import], + for: Purpose) repeatable on SCHEMA scalar Import +enum Purpose { + SECURITY + EXECUTION +} + +# +# federation-v2.1 +# + +directive @composeDirective(name: String!) repeatable on SCHEMA + # # federation-v2.2 # diff --git a/graphql-java-support/src/main/resources/definitions_fed2_3.graphqls b/graphql-java-support/src/main/resources/definitions_fed2_3.graphqls index 4466f960..b4a2a697 100644 --- a/graphql-java-support/src/main/resources/definitions_fed2_3.graphqls +++ b/graphql-java-support/src/main/resources/definitions_fed2_3.graphqls @@ -32,12 +32,6 @@ directive @tag(name: String!) repeatable on | INPUT_FIELD_DEFINITION scalar FieldSet -# -# federation-v2.1 -# - -directive @composeDirective(name: String!) repeatable on SCHEMA - # # https://specs.apollo.dev/link/v1.0/link-v1.0.graphql # @@ -45,11 +39,23 @@ directive @composeDirective(name: String!) repeatable on SCHEMA directive @link( url: String!, as: String, - import: [Import]) + import: [Import], + for: Purpose) repeatable on SCHEMA scalar Import +enum Purpose { + SECURITY + EXECUTION +} + +# +# federation-v2.1 +# + +directive @composeDirective(name: String!) repeatable on SCHEMA + # # federation-v2.2 # diff --git a/graphql-java-support/src/main/resources/definitions_fed2_5.graphqls b/graphql-java-support/src/main/resources/definitions_fed2_5.graphqls index f924f930..aaf4899d 100644 --- a/graphql-java-support/src/main/resources/definitions_fed2_5.graphqls +++ b/graphql-java-support/src/main/resources/definitions_fed2_5.graphqls @@ -39,11 +39,17 @@ scalar FieldSet directive @link( url: String!, as: String, - import: [Import]) + import: [Import], + for: Purpose) repeatable on SCHEMA scalar Import +enum Purpose { + SECURITY + EXECUTION +} + # # federation-v2.1 # diff --git a/graphql-java-support/src/test/resources/schemas/authorization_federated.graphql b/graphql-java-support/src/test/resources/schemas/authorization_federated.graphql index d4e4111d..9f0aa1ab 100644 --- a/graphql-java-support/src/test/resources/schemas/authorization_federated.graphql +++ b/graphql-java-support/src/test/resources/schemas/authorization_federated.graphql @@ -24,7 +24,7 @@ directive @inaccessible on SCALAR | OBJECT | FIELD_DEFINITION | ARGUMENT_DEFINIT directive @key(fields: FieldSet!, resolvable: Boolean = true) repeatable on OBJECT | INTERFACE -directive @link(as: String, import: [link__Import], url: String!) repeatable on SCHEMA +directive @link(as: String, for: link__Purpose, import: [link__Import], url: String!) repeatable on SCHEMA directive @requiresScopes(scopes: [[Scope!]!]!) on SCALAR | OBJECT | FIELD_DEFINITION | INTERFACE | ENUM @@ -48,6 +48,11 @@ type _Service { sdl: String! } +enum link__Purpose { + EXECUTION + SECURITY +} + scalar FieldSet scalar Scope diff --git a/graphql-java-support/src/test/resources/schemas/composeDirective_federated.graphql b/graphql-java-support/src/test/resources/schemas/composeDirective_federated.graphql index 4e8c4a51..253b54bc 100644 --- a/graphql-java-support/src/test/resources/schemas/composeDirective_federated.graphql +++ b/graphql-java-support/src/test/resources/schemas/composeDirective_federated.graphql @@ -22,7 +22,7 @@ directive @inaccessible on SCALAR | OBJECT | FIELD_DEFINITION | ARGUMENT_DEFINIT directive @key(fields: federation__FieldSet!, resolvable: Boolean = true) repeatable on OBJECT | INTERFACE -directive @link(as: String, import: [link__Import], url: String!) repeatable on SCHEMA +directive @link(as: String, for: link__Purpose, import: [link__Import], url: String!) repeatable on SCHEMA directive @myDirective(foo: String!) on FIELD_DEFINITION @@ -46,6 +46,11 @@ type _Service { sdl: String! } +enum link__Purpose { + EXECUTION + SECURITY +} + scalar _Any scalar federation__FieldSet diff --git a/graphql-java-support/src/test/resources/schemas/customAuthenticated_federated.graphql b/graphql-java-support/src/test/resources/schemas/customAuthenticated_federated.graphql index 6ad49229..453daf09 100644 --- a/graphql-java-support/src/test/resources/schemas/customAuthenticated_federated.graphql +++ b/graphql-java-support/src/test/resources/schemas/customAuthenticated_federated.graphql @@ -28,7 +28,7 @@ directive @inaccessible on SCALAR | OBJECT | FIELD_DEFINITION | ARGUMENT_DEFINIT directive @key(fields: federation__FieldSet!, resolvable: Boolean = true) repeatable on OBJECT | INTERFACE -directive @link(as: String, import: [link__Import], url: String!) repeatable on SCHEMA +directive @link(as: String, for: link__Purpose, import: [link__Import], url: String!) repeatable on SCHEMA directive @tag(name: String!) repeatable on SCALAR | OBJECT | FIELD_DEFINITION | ARGUMENT_DEFINITION | INTERFACE | UNION | ENUM | ENUM_VALUE | INPUT_OBJECT | INPUT_FIELD_DEFINITION @@ -50,6 +50,11 @@ type _Service { sdl: String! } +enum link__Purpose { + EXECUTION + SECURITY +} + scalar _Any scalar federation__FieldSet diff --git a/graphql-java-support/src/test/resources/schemas/extendSchema_federated.graphql b/graphql-java-support/src/test/resources/schemas/extendSchema_federated.graphql index 061c0f6b..02836b7b 100644 --- a/graphql-java-support/src/test/resources/schemas/extendSchema_federated.graphql +++ b/graphql-java-support/src/test/resources/schemas/extendSchema_federated.graphql @@ -18,7 +18,7 @@ directive @inaccessible on SCALAR | OBJECT | FIELD_DEFINITION | ARGUMENT_DEFINIT directive @key(fields: federation__FieldSet!, resolvable: Boolean = true) repeatable on OBJECT | INTERFACE -directive @link(as: String, import: [link__Import], url: String!) repeatable on SCHEMA +directive @link(as: String, for: link__Purpose, import: [link__Import], url: String!) repeatable on SCHEMA directive @tag(name: String!) repeatable on SCALAR | OBJECT | FIELD_DEFINITION | ARGUMENT_DEFINITION | INTERFACE | UNION | ENUM | ENUM_VALUE | INPUT_OBJECT | INPUT_FIELD_DEFINITION @@ -38,6 +38,11 @@ type _Service { sdl: String! } +enum link__Purpose { + EXECUTION + SECURITY +} + scalar _Any scalar federation__FieldSet diff --git a/graphql-java-support/src/test/resources/schemas/federationV2_federated.graphql b/graphql-java-support/src/test/resources/schemas/federationV2_federated.graphql index d0707b74..2ffa9871 100644 --- a/graphql-java-support/src/test/resources/schemas/federationV2_federated.graphql +++ b/graphql-java-support/src/test/resources/schemas/federationV2_federated.graphql @@ -16,7 +16,7 @@ directive @interfaceObject on OBJECT directive @key(fields: federation__FieldSet!, resolvable: Boolean = true) repeatable on OBJECT | INTERFACE -directive @link(as: String, import: [link__Import], url: String!) repeatable on SCHEMA +directive @link(as: String, for: link__Purpose, import: [link__Import], url: String!) repeatable on SCHEMA directive @override(from: String!) on FIELD_DEFINITION @@ -92,6 +92,11 @@ type _Service { sdl: String! } +enum link__Purpose { + EXECUTION + SECURITY +} + scalar _Any scalar federation__FieldSet diff --git a/graphql-java-support/src/test/resources/schemas/interfaceEntity_federated.graphql b/graphql-java-support/src/test/resources/schemas/interfaceEntity_federated.graphql index 096a9553..20decd75 100644 --- a/graphql-java-support/src/test/resources/schemas/interfaceEntity_federated.graphql +++ b/graphql-java-support/src/test/resources/schemas/interfaceEntity_federated.graphql @@ -22,7 +22,7 @@ directive @inaccessible on SCALAR | OBJECT | FIELD_DEFINITION | ARGUMENT_DEFINIT directive @key(fields: federation__FieldSet!, resolvable: Boolean = true) repeatable on OBJECT | INTERFACE -directive @link(as: String, import: [link__Import], url: String!) repeatable on SCHEMA +directive @link(as: String, for: link__Purpose, import: [link__Import], url: String!) repeatable on SCHEMA directive @tag(name: String!) repeatable on SCALAR | OBJECT | FIELD_DEFINITION | ARGUMENT_DEFINITION | INTERFACE | UNION | ENUM | ENUM_VALUE | INPUT_OBJECT | INPUT_FIELD_DEFINITION @@ -58,6 +58,11 @@ type _Service { sdl: String! } +enum link__Purpose { + EXECUTION + SECURITY +} + scalar _Any scalar federation__FieldSet diff --git a/graphql-java-support/src/test/resources/schemas/interfaceObject_federated.graphql b/graphql-java-support/src/test/resources/schemas/interfaceObject_federated.graphql index 2dd8967c..55ad07ef 100644 --- a/graphql-java-support/src/test/resources/schemas/interfaceObject_federated.graphql +++ b/graphql-java-support/src/test/resources/schemas/interfaceObject_federated.graphql @@ -22,7 +22,7 @@ directive @interfaceObject on OBJECT directive @key(fields: federation__FieldSet!, resolvable: Boolean = true) repeatable on OBJECT | INTERFACE -directive @link(as: String, import: [link__Import], url: String!) repeatable on SCHEMA +directive @link(as: String, for: link__Purpose, import: [link__Import], url: String!) repeatable on SCHEMA directive @tag(name: String!) repeatable on SCALAR | OBJECT | FIELD_DEFINITION | ARGUMENT_DEFINITION | INTERFACE | UNION | ENUM | ENUM_VALUE | INPUT_OBJECT | INPUT_FIELD_DEFINITION @@ -43,6 +43,11 @@ type _Service { sdl: String! } +enum link__Purpose { + EXECUTION + SECURITY +} + scalar _Any scalar federation__FieldSet diff --git a/graphql-java-support/src/test/resources/schemas/nonResolvableKey_federated.graphql b/graphql-java-support/src/test/resources/schemas/nonResolvableKey_federated.graphql index 422d9c4b..4c76fa01 100644 --- a/graphql-java-support/src/test/resources/schemas/nonResolvableKey_federated.graphql +++ b/graphql-java-support/src/test/resources/schemas/nonResolvableKey_federated.graphql @@ -22,7 +22,7 @@ directive @inaccessible on SCALAR | OBJECT | FIELD_DEFINITION | ARGUMENT_DEFINIT directive @key(fields: federation__FieldSet!, resolvable: Boolean = true) repeatable on OBJECT | INTERFACE -directive @link(as: String, import: [link__Import], url: String!) repeatable on SCHEMA +directive @link(as: String, for: link__Purpose, import: [link__Import], url: String!) repeatable on SCHEMA directive @tag(name: String!) repeatable on SCALAR | OBJECT | FIELD_DEFINITION | ARGUMENT_DEFINITION | INTERFACE | UNION | ENUM | ENUM_VALUE | INPUT_OBJECT | INPUT_FIELD_DEFINITION @@ -48,6 +48,11 @@ type _Service { sdl: String! } +enum link__Purpose { + EXECUTION + SECURITY +} + scalar _Any scalar federation__FieldSet diff --git a/graphql-java-support/src/test/resources/schemas/renamedImports_federated.graphql b/graphql-java-support/src/test/resources/schemas/renamedImports_federated.graphql index cc6ecd5d..5c68c0ec 100644 --- a/graphql-java-support/src/test/resources/schemas/renamedImports_federated.graphql +++ b/graphql-java-support/src/test/resources/schemas/renamedImports_federated.graphql @@ -10,7 +10,7 @@ directive @federation__requires(fields: federation__FieldSet!) on FIELD_DEFINITI directive @inaccessible on SCALAR | OBJECT | FIELD_DEFINITION | ARGUMENT_DEFINITION | INTERFACE | UNION | ENUM | ENUM_VALUE | INPUT_OBJECT | INPUT_FIELD_DEFINITION -directive @link(as: String, import: [link__Import], url: String!) repeatable on SCHEMA +directive @link(as: String, for: link__Purpose, import: [link__Import], url: String!) repeatable on SCHEMA directive @myKey(fields: federation__FieldSet!, resolvable: Boolean = true) repeatable on OBJECT | INTERFACE @@ -57,6 +57,11 @@ type _Service { sdl: String! } +enum link__Purpose { + EXECUTION + SECURITY +} + scalar federation__FieldSet scalar link__Import diff --git a/graphql-java-support/src/test/resources/schemas/repeatableShareable_federated.graphql b/graphql-java-support/src/test/resources/schemas/repeatableShareable_federated.graphql index 88ddf522..e00a5f87 100644 --- a/graphql-java-support/src/test/resources/schemas/repeatableShareable_federated.graphql +++ b/graphql-java-support/src/test/resources/schemas/repeatableShareable_federated.graphql @@ -18,7 +18,7 @@ directive @inaccessible on SCALAR | OBJECT | FIELD_DEFINITION | ARGUMENT_DEFINIT directive @key(fields: federation__FieldSet!, resolvable: Boolean = true) repeatable on OBJECT | INTERFACE -directive @link(as: String, import: [link__Import], url: String!) repeatable on SCHEMA +directive @link(as: String, for: link__Purpose, import: [link__Import], url: String!) repeatable on SCHEMA directive @shareable repeatable on OBJECT | FIELD_DEFINITION @@ -48,6 +48,11 @@ type _Service { sdl: String! } +enum link__Purpose { + EXECUTION + SECURITY +} + scalar _Any scalar federation__FieldSet diff --git a/graphql-java-support/src/test/resources/schemas/schemaImport_federated.graphql b/graphql-java-support/src/test/resources/schemas/schemaImport_federated.graphql index a3fa9033..71efce42 100644 --- a/graphql-java-support/src/test/resources/schemas/schemaImport_federated.graphql +++ b/graphql-java-support/src/test/resources/schemas/schemaImport_federated.graphql @@ -18,7 +18,7 @@ directive @inaccessible on SCALAR | OBJECT | FIELD_DEFINITION | ARGUMENT_DEFINIT directive @key(fields: federation__FieldSet!, resolvable: Boolean = true) repeatable on OBJECT | INTERFACE -directive @link(as: String, import: [link__Import], url: String!) repeatable on SCHEMA +directive @link(as: String, for: link__Purpose, import: [link__Import], url: String!) repeatable on SCHEMA directive @tag(name: String!) repeatable on SCALAR | OBJECT | FIELD_DEFINITION | ARGUMENT_DEFINITION | INTERFACE | UNION | ENUM | ENUM_VALUE | INPUT_OBJECT | INPUT_FIELD_DEFINITION @@ -39,6 +39,11 @@ type _Service { sdl: String! } +enum link__Purpose { + EXECUTION + SECURITY +} + scalar _Any scalar federation__FieldSet