Skip to content

Commit a787bdc

Browse files
authored
federation 2.8 support (#409)
1 parent 292d74d commit a787bdc

File tree

7 files changed

+323
-0
lines changed

7 files changed

+323
-0
lines changed

graphql-java-support/src/main/java/com/apollographql/federation/graphqljava/Federation.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@ public final class Federation {
3434
public static final String FEDERATION_SPEC_V2_5 = "https://specs.apollo.dev/federation/v2.5";
3535
public static final String FEDERATION_SPEC_V2_6 = "https://specs.apollo.dev/federation/v2.6";
3636
public static final String FEDERATION_SPEC_V2_7 = "https://specs.apollo.dev/federation/v2.7";
37+
public static final String FEDERATION_SPEC_V2_8 = "https://specs.apollo.dev/federation/v2.8";
3738

3839
private static final SchemaGenerator.Options defaultGeneratorOptions =
3940
SchemaGenerator.Options.defaultOptions();

graphql-java-support/src/main/java/com/apollographql/federation/graphqljava/FederationDirectives.java

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
import static com.apollographql.federation.graphqljava.Federation.FEDERATION_SPEC_V2_5;
99
import static com.apollographql.federation.graphqljava.Federation.FEDERATION_SPEC_V2_6;
1010
import static com.apollographql.federation.graphqljava.Federation.FEDERATION_SPEC_V2_7;
11+
import static com.apollographql.federation.graphqljava.Federation.FEDERATION_SPEC_V2_8;
1112
import static graphql.introspection.Introspection.DirectiveLocation.FIELD_DEFINITION;
1213
import static graphql.introspection.Introspection.DirectiveLocation.INTERFACE;
1314
import static graphql.introspection.Introspection.DirectiveLocation.OBJECT;
@@ -229,6 +230,8 @@ public static List<SDLNamedDefinition> loadFederationSpecDefinitions(String fede
229230
return loadFed2Definitions("definitions_fed2_6.graphqls");
230231
case FEDERATION_SPEC_V2_7:
231232
return loadFed2Definitions("definitions_fed2_7.graphqls");
233+
case FEDERATION_SPEC_V2_8:
234+
return loadFed2Definitions("definitions_fed2_8.graphqls");
232235
default:
233236
throw new UnsupportedFederationVersionException(federationSpec);
234237
}
Lines changed: 117 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,117 @@
1+
#
2+
# https://specs.apollo.dev/federation/v2.0/federation-v2.0.graphql
3+
#
4+
5+
directive @key(fields: FieldSet!, resolvable: Boolean = true) repeatable on OBJECT | INTERFACE
6+
directive @requires(fields: FieldSet!) on FIELD_DEFINITION
7+
directive @provides(fields: FieldSet!) on FIELD_DEFINITION
8+
directive @external on OBJECT | FIELD_DEFINITION
9+
directive @extends on OBJECT | INTERFACE
10+
directive @inaccessible on
11+
| FIELD_DEFINITION
12+
| OBJECT
13+
| INTERFACE
14+
| UNION
15+
| ENUM
16+
| ENUM_VALUE
17+
| SCALAR
18+
| INPUT_OBJECT
19+
| INPUT_FIELD_DEFINITION
20+
| ARGUMENT_DEFINITION
21+
directive @tag(name: String!) repeatable on
22+
| FIELD_DEFINITION
23+
| INTERFACE
24+
| OBJECT
25+
| UNION
26+
| ARGUMENT_DEFINITION
27+
| SCALAR
28+
| ENUM
29+
| ENUM_VALUE
30+
| INPUT_OBJECT
31+
| INPUT_FIELD_DEFINITION
32+
scalar FieldSet
33+
34+
#
35+
# https://specs.apollo.dev/link/v1.0/link-v1.0.graphql
36+
#
37+
38+
directive @link(
39+
url: String!,
40+
as: String,
41+
import: [Import],
42+
for: Purpose)
43+
repeatable on SCHEMA
44+
45+
scalar Import
46+
47+
enum Purpose {
48+
SECURITY
49+
EXECUTION
50+
}
51+
52+
#
53+
# federation-v2.1
54+
#
55+
56+
directive @composeDirective(name: String!) repeatable on SCHEMA
57+
58+
#
59+
# federation-v2.2
60+
#
61+
62+
directive @shareable repeatable on FIELD_DEFINITION | OBJECT
63+
64+
#
65+
# federation-v2.3
66+
#
67+
68+
directive @interfaceObject on OBJECT
69+
70+
#
71+
# federation-v2.5
72+
#
73+
74+
directive @authenticated on
75+
ENUM
76+
| FIELD_DEFINITION
77+
| INTERFACE
78+
| OBJECT
79+
| SCALAR
80+
81+
directive @requiresScopes(scopes: [[Scope!]!]!) on
82+
ENUM
83+
| FIELD_DEFINITION
84+
| INTERFACE
85+
| OBJECT
86+
| SCALAR
87+
88+
scalar Scope
89+
90+
#
91+
# federation-v2.6
92+
#
93+
94+
directive @policy(policies: [[Policy!]!]!) on
95+
ENUM
96+
| FIELD_DEFINITION
97+
| INTERFACE
98+
| OBJECT
99+
| SCALAR
100+
101+
scalar Policy
102+
103+
#
104+
# federation-v2.7
105+
#
106+
107+
directive @override(from: String!, label: String) on FIELD_DEFINITION
108+
109+
#
110+
# federation-v2.8
111+
#
112+
113+
scalar ContextFieldValue
114+
115+
directive @context(name: String!) repeatable on INTERFACE | OBJECT | UNION
116+
117+
directive @fromContext(field: ContextFieldValue) on ARGUMENT_DEFINITION

graphql-java-support/src/test/java/com/apollographql/federation/graphqljava/FederationTest.java

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -327,6 +327,11 @@ public void verifyFederationV2Transformation_policy() {
327327
verifyFederationTransformation("schemas/policy/schema.graphql");
328328
}
329329

330+
@Test
331+
public void verifyFederationV2Transformation_context() {
332+
verifyFederationTransformation("schemas/context/schema.graphql");
333+
}
334+
330335
@Test
331336
public void
332337
verifyFederationV2Transformation_requiresScopesFromUnsupportedVersion_throwsException() {
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
extend schema @link(url: "https://specs.apollo.dev/federation/v2.8", import: ["@key", "@context", "@fromContext"])
2+
3+
type Product @key(fields: "id") @context(name: "product") {
4+
id: ID!
5+
name: String!
6+
child: Child!
7+
}
8+
9+
type Child @key(fields: "id") {
10+
id: ID!
11+
details(productName: String @fromContext(field: "$product { name }")): String!
12+
}
13+
14+
type Query {
15+
product(id: ID!): Product
16+
}
Lines changed: 77 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,77 @@
1+
schema @link(import : ["@key", "@context", "@fromContext"], url : "https://specs.apollo.dev/federation/v2.8"){
2+
query: Query
3+
}
4+
5+
directive @context(name: String!) repeatable on OBJECT | INTERFACE | UNION
6+
7+
directive @federation__authenticated on SCALAR | OBJECT | FIELD_DEFINITION | INTERFACE | ENUM
8+
9+
directive @federation__composeDirective(name: String!) repeatable on SCHEMA
10+
11+
directive @federation__extends on OBJECT | INTERFACE
12+
13+
directive @federation__external on OBJECT | FIELD_DEFINITION
14+
15+
directive @federation__interfaceObject on OBJECT
16+
17+
directive @federation__override(from: String!, label: String) on FIELD_DEFINITION
18+
19+
directive @federation__policy(policies: [[federation__Policy!]!]!) on SCALAR | OBJECT | FIELD_DEFINITION | INTERFACE | ENUM
20+
21+
directive @federation__provides(fields: federation__FieldSet!) on FIELD_DEFINITION
22+
23+
directive @federation__requires(fields: federation__FieldSet!) on FIELD_DEFINITION
24+
25+
directive @federation__requiresScopes(scopes: [[federation__Scope!]!]!) on SCALAR | OBJECT | FIELD_DEFINITION | INTERFACE | ENUM
26+
27+
directive @federation__shareable repeatable on OBJECT | FIELD_DEFINITION
28+
29+
directive @fromContext(field: federation__ContextFieldValue) on ARGUMENT_DEFINITION
30+
31+
directive @inaccessible on SCALAR | OBJECT | FIELD_DEFINITION | ARGUMENT_DEFINITION | INTERFACE | UNION | ENUM | ENUM_VALUE | INPUT_OBJECT | INPUT_FIELD_DEFINITION
32+
33+
directive @key(fields: federation__FieldSet!, resolvable: Boolean = true) repeatable on OBJECT | INTERFACE
34+
35+
directive @link(as: String, for: link__Purpose, import: [link__Import], url: String!) repeatable on SCHEMA
36+
37+
directive @tag(name: String!) repeatable on SCALAR | OBJECT | FIELD_DEFINITION | ARGUMENT_DEFINITION | INTERFACE | UNION | ENUM | ENUM_VALUE | INPUT_OBJECT | INPUT_FIELD_DEFINITION
38+
39+
union _Entity = Child | Product
40+
41+
type Child @key(fields : "id", resolvable : true) {
42+
details(productName: String @fromContext(field : "$product { name }")): String!
43+
id: ID!
44+
}
45+
46+
type Product @context(name : "product") @key(fields : "id", resolvable : true) {
47+
child: Child!
48+
id: ID!
49+
name: String!
50+
}
51+
52+
type Query {
53+
_entities(representations: [_Any!]!): [_Entity]!
54+
_service: _Service!
55+
product(id: ID!): Product
56+
}
57+
58+
type _Service {
59+
sdl: String!
60+
}
61+
62+
enum link__Purpose {
63+
EXECUTION
64+
SECURITY
65+
}
66+
67+
scalar _Any
68+
69+
scalar federation__ContextFieldValue
70+
71+
scalar federation__FieldSet
72+
73+
scalar federation__Policy
74+
75+
scalar federation__Scope
76+
77+
scalar link__Import
Lines changed: 104 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,104 @@
1+
schema @link(import : ["@key", "@context", "@fromContext"], url : "https://specs.apollo.dev/federation/v2.8"){
2+
query: Query
3+
}
4+
5+
directive @context(name: String!) repeatable on OBJECT | INTERFACE | UNION
6+
7+
"Marks the field, argument, input field or enum value as deprecated"
8+
directive @deprecated(
9+
"The reason for the deprecation"
10+
reason: String = "No longer supported"
11+
) on FIELD_DEFINITION | ARGUMENT_DEFINITION | ENUM_VALUE | INPUT_FIELD_DEFINITION
12+
13+
directive @federation__authenticated on SCALAR | OBJECT | FIELD_DEFINITION | INTERFACE | ENUM
14+
15+
directive @federation__composeDirective(name: String!) repeatable on SCHEMA
16+
17+
directive @federation__extends on OBJECT | INTERFACE
18+
19+
directive @federation__external on OBJECT | FIELD_DEFINITION
20+
21+
directive @federation__interfaceObject on OBJECT
22+
23+
directive @federation__override(from: String!, label: String) on FIELD_DEFINITION
24+
25+
directive @federation__policy(policies: [[federation__Policy!]!]!) on SCALAR | OBJECT | FIELD_DEFINITION | INTERFACE | ENUM
26+
27+
directive @federation__provides(fields: federation__FieldSet!) on FIELD_DEFINITION
28+
29+
directive @federation__requires(fields: federation__FieldSet!) on FIELD_DEFINITION
30+
31+
directive @federation__requiresScopes(scopes: [[federation__Scope!]!]!) on SCALAR | OBJECT | FIELD_DEFINITION | INTERFACE | ENUM
32+
33+
directive @federation__shareable repeatable on OBJECT | FIELD_DEFINITION
34+
35+
directive @fromContext(field: federation__ContextFieldValue) on ARGUMENT_DEFINITION
36+
37+
directive @inaccessible on SCALAR | OBJECT | FIELD_DEFINITION | ARGUMENT_DEFINITION | INTERFACE | UNION | ENUM | ENUM_VALUE | INPUT_OBJECT | INPUT_FIELD_DEFINITION
38+
39+
"Directs the executor to include this field or fragment only when the `if` argument is true"
40+
directive @include(
41+
"Included when true."
42+
if: Boolean!
43+
) on FIELD | FRAGMENT_SPREAD | INLINE_FRAGMENT
44+
45+
directive @key(fields: federation__FieldSet!, resolvable: Boolean = true) repeatable on OBJECT | INTERFACE
46+
47+
directive @link(as: String, for: link__Purpose, import: [link__Import], url: String!) repeatable on SCHEMA
48+
49+
"Indicates an Input Object is a OneOf Input Object."
50+
directive @oneOf on INPUT_OBJECT
51+
52+
"Directs the executor to skip this field or fragment when the `if` argument is true."
53+
directive @skip(
54+
"Skipped when true."
55+
if: Boolean!
56+
) on FIELD | FRAGMENT_SPREAD | INLINE_FRAGMENT
57+
58+
"Exposes a URL that specifies the behaviour of this scalar."
59+
directive @specifiedBy(
60+
"The URL that specifies the behaviour of this scalar."
61+
url: String!
62+
) on SCALAR
63+
64+
directive @tag(name: String!) repeatable on SCALAR | OBJECT | FIELD_DEFINITION | ARGUMENT_DEFINITION | INTERFACE | UNION | ENUM | ENUM_VALUE | INPUT_OBJECT | INPUT_FIELD_DEFINITION
65+
66+
union _Entity = Child | Product
67+
68+
type Child @key(fields : "id", resolvable : true) {
69+
details(productName: String @fromContext(field : "$product { name }")): String!
70+
id: ID!
71+
}
72+
73+
type Product @context(name : "product") @key(fields : "id", resolvable : true) {
74+
child: Child!
75+
id: ID!
76+
name: String!
77+
}
78+
79+
type Query {
80+
_entities(representations: [_Any!]!): [_Entity]!
81+
_service: _Service!
82+
product(id: ID!): Product
83+
}
84+
85+
type _Service {
86+
sdl: String!
87+
}
88+
89+
enum link__Purpose {
90+
EXECUTION
91+
SECURITY
92+
}
93+
94+
scalar _Any
95+
96+
scalar federation__ContextFieldValue
97+
98+
scalar federation__FieldSet
99+
100+
scalar federation__Policy
101+
102+
scalar federation__Scope
103+
104+
scalar link__Import

0 commit comments

Comments
 (0)