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 9db1ffb0..de6a413e 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 @@ -35,6 +35,7 @@ public final class Federation { public static final String FEDERATION_SPEC_V2_6 = "https://specs.apollo.dev/federation/v2.6"; public static final String FEDERATION_SPEC_V2_7 = "https://specs.apollo.dev/federation/v2.7"; public static final String FEDERATION_SPEC_V2_8 = "https://specs.apollo.dev/federation/v2.8"; + public static final String FEDERATION_SPEC_V2_9 = "https://specs.apollo.dev/federation/v2.9"; private static final SchemaGenerator.Options generatorOptions = SchemaGenerator.Options.defaultOptions(); diff --git a/graphql-java-support/src/main/java/com/apollographql/federation/graphqljava/FederationDirectives.java b/graphql-java-support/src/main/java/com/apollographql/federation/graphqljava/FederationDirectives.java index 254ea2e3..8898c943 100644 --- a/graphql-java-support/src/main/java/com/apollographql/federation/graphqljava/FederationDirectives.java +++ b/graphql-java-support/src/main/java/com/apollographql/federation/graphqljava/FederationDirectives.java @@ -9,6 +9,7 @@ import static com.apollographql.federation.graphqljava.Federation.FEDERATION_SPEC_V2_6; import static com.apollographql.federation.graphqljava.Federation.FEDERATION_SPEC_V2_7; import static com.apollographql.federation.graphqljava.Federation.FEDERATION_SPEC_V2_8; +import static com.apollographql.federation.graphqljava.Federation.FEDERATION_SPEC_V2_9; import static graphql.introspection.Introspection.DirectiveLocation.FIELD_DEFINITION; import static graphql.introspection.Introspection.DirectiveLocation.INTERFACE; import static graphql.introspection.Introspection.DirectiveLocation.OBJECT; @@ -232,6 +233,8 @@ public static List loadFederationSpecDefinitions(String fede return loadFed2Definitions("definitions_fed2_7.graphqls"); case FEDERATION_SPEC_V2_8: return loadFed2Definitions("definitions_fed2_8.graphqls"); + case FEDERATION_SPEC_V2_9: + return loadFed2Definitions("definitions_fed2_9.graphqls"); default: throw new UnsupportedFederationVersionException(federationSpec); } diff --git a/graphql-java-support/src/main/java/com/apollographql/federation/graphqljava/directives/LinkDirectiveProcessor.java b/graphql-java-support/src/main/java/com/apollographql/federation/graphqljava/directives/LinkDirectiveProcessor.java index 6e7b9f6d..b7100867 100644 --- a/graphql-java-support/src/main/java/com/apollographql/federation/graphqljava/directives/LinkDirectiveProcessor.java +++ b/graphql-java-support/src/main/java/com/apollographql/federation/graphqljava/directives/LinkDirectiveProcessor.java @@ -32,7 +32,11 @@ public final class LinkDirectiveProcessor { "@interfaceObject", 23, "@authenticated", 25, "@requiresScopes", 25, - "@policy", 26); + "@policy", 26, + "@context", 28, + "@fromContext", 28, + "@cost", 29, + "@listSize", 29); private LinkDirectiveProcessor() {} diff --git a/graphql-java-support/src/main/resources/definitions_fed2_9.graphqls b/graphql-java-support/src/main/resources/definitions_fed2_9.graphqls new file mode 100644 index 00000000..356988c7 --- /dev/null +++ b/graphql-java-support/src/main/resources/definitions_fed2_9.graphqls @@ -0,0 +1,136 @@ +# +# https://specs.apollo.dev/federation/v2.0/federation-v2.0.graphql +# + +directive @key(fields: FieldSet!, resolvable: Boolean = true) repeatable on OBJECT | INTERFACE +directive @requires(fields: FieldSet!) on FIELD_DEFINITION +directive @provides(fields: FieldSet!) on FIELD_DEFINITION +directive @external on OBJECT | FIELD_DEFINITION +directive @extends on OBJECT | INTERFACE +directive @inaccessible on + | FIELD_DEFINITION + | OBJECT + | INTERFACE + | UNION + | ENUM + | ENUM_VALUE + | SCALAR + | INPUT_OBJECT + | INPUT_FIELD_DEFINITION + | ARGUMENT_DEFINITION +directive @tag(name: String!) repeatable on + | FIELD_DEFINITION + | INTERFACE + | OBJECT + | UNION + | ARGUMENT_DEFINITION + | SCALAR + | ENUM + | ENUM_VALUE + | INPUT_OBJECT + | INPUT_FIELD_DEFINITION +scalar FieldSet + +# +# https://specs.apollo.dev/link/v1.0/link-v1.0.graphql +# + +directive @link( + url: String!, + as: String, + 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 +# + +directive @shareable repeatable on FIELD_DEFINITION | OBJECT + +# +# federation-v2.3 +# + +directive @interfaceObject on OBJECT + +# +# federation-v2.5 +# + +directive @authenticated on + ENUM + | FIELD_DEFINITION + | INTERFACE + | OBJECT + | SCALAR + +directive @requiresScopes(scopes: [[Scope!]!]!) on + ENUM + | FIELD_DEFINITION + | INTERFACE + | OBJECT + | SCALAR + +scalar Scope + +# +# federation-v2.6 +# + +directive @policy(policies: [[Policy!]!]!) on + ENUM + | FIELD_DEFINITION + | INTERFACE + | OBJECT + | SCALAR + +scalar Policy + +# +# federation-v2.7 +# + +directive @override(from: String!, label: String) on FIELD_DEFINITION + +# +# federation-v2.8 +# + +scalar ContextFieldValue + +directive @context(name: String!) repeatable on INTERFACE | OBJECT | UNION + +directive @fromContext(field: ContextFieldValue) on ARGUMENT_DEFINITION + +# +# federation-v2.9 +# + +directive @cost(weight: Int!) on + ARGUMENT_DEFINITION + | ENUM + | FIELD_DEFINITION + | INPUT_FIELD_DEFINITION + | OBJECT + | SCALAR + +directive @listSize( + assumedSize: Int, + slicingArguments: [String!], + sizedFields: [String!], + requireOneSlicingArgument: Boolean = true +) on FIELD_DEFINITION \ No newline at end of file diff --git a/graphql-java-support/src/test/java/com/apollographql/federation/graphqljava/FederationTest.java b/graphql-java-support/src/test/java/com/apollographql/federation/graphqljava/FederationTest.java index e88bc834..9b7cb75c 100644 --- a/graphql-java-support/src/test/java/com/apollographql/federation/graphqljava/FederationTest.java +++ b/graphql-java-support/src/test/java/com/apollographql/federation/graphqljava/FederationTest.java @@ -332,6 +332,14 @@ public void verifyFederationV2Transformation_context() { verifyFederationTransformation("schemas/context/schema.graphql"); } + @Test + public void verifyFederationV2Transformation_contextFromUnsupportedVersion_throwsException() { + final String schemaSDL = FileUtils.readResource("schemas/invalidSpecVersionContext.graphql"); + assertThrows( + UnsupportedLinkImportException.class, + () -> Federation.transform(schemaSDL).fetchEntities(env -> null).build()); + } + @Test public void verifyFederationV2Transformation_requiresScopesFromUnsupportedVersion_throwsException() { @@ -370,6 +378,19 @@ public void verifyFederationV2Transformation_scalarsDefinedInSchemaButNotWired() verifyFederationTransformation("schemas/scalars/schema.graphql"); } + @Test + public void verifyFederationV2Transformation_cost() { + verifyFederationTransformation("schemas/cost/schema.graphql"); + } + + @Test + public void verifyFederationV2Transformation_costFromUnsupportedVersion_throwsException() { + final String schemaSDL = FileUtils.readResource("schemas/invalidSpecVersionCost.graphql"); + assertThrows( + UnsupportedLinkImportException.class, + () -> Federation.transform(schemaSDL).fetchEntities(env -> null).build()); + } + private void verifyFederationTransformation(String schemaFileName) { final RuntimeWiring runtimeWiring = RuntimeWiring.newRuntimeWiring().build(); verifyFederationTransformation(schemaFileName, runtimeWiring);