Skip to content

Commit

Permalink
federation 2.8 support (#409)
Browse files Browse the repository at this point in the history
  • Loading branch information
clenfest authored and dariuszkuc committed Oct 11, 2024
1 parent 961fd33 commit ce01b73
Show file tree
Hide file tree
Showing 4 changed files with 126 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ public final class Federation {
public static final String FEDERATION_SPEC_V2_5 = "https://specs.apollo.dev/federation/v2.5";
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";

private static final SchemaGenerator.Options generatorOptions =
SchemaGenerator.Options.defaultOptions();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
import static com.apollographql.federation.graphqljava.Federation.FEDERATION_SPEC_V2_5;
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 graphql.introspection.Introspection.DirectiveLocation.FIELD_DEFINITION;
import static graphql.introspection.Introspection.DirectiveLocation.INTERFACE;
import static graphql.introspection.Introspection.DirectiveLocation.OBJECT;
Expand Down Expand Up @@ -229,6 +230,8 @@ public static List<SDLNamedDefinition> loadFederationSpecDefinitions(String fede
return loadFed2Definitions("definitions_fed2_6.graphqls");
case FEDERATION_SPEC_V2_7:
return loadFed2Definitions("definitions_fed2_7.graphqls");
case FEDERATION_SPEC_V2_8:
return loadFed2Definitions("definitions_fed2_8.graphqls");
default:
throw new UnsupportedFederationVersionException(federationSpec);
}
Expand Down
117 changes: 117 additions & 0 deletions graphql-java-support/src/main/resources/definitions_fed2_8.graphqls
Original file line number Diff line number Diff line change
@@ -0,0 +1,117 @@
#
# 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
Original file line number Diff line number Diff line change
Expand Up @@ -327,6 +327,11 @@ public void verifyFederationV2Transformation_policy() {
verifyFederationTransformation("schemas/policy/schema.graphql");
}

@Test
public void verifyFederationV2Transformation_context() {
verifyFederationTransformation("schemas/context/schema.graphql");
}

@Test
public void
verifyFederationV2Transformation_requiresScopesFromUnsupportedVersion_throwsException() {
Expand Down

0 comments on commit ce01b73

Please sign in to comment.