Skip to content

Commit 0bd1276

Browse files
authored
feat: add support for federation v2.3 (#1674)
Backport of Federation v2.1, v2.2 and v2.3 changes from `master`.
1 parent 8748198 commit 0bd1276

File tree

18 files changed

+4424
-1508
lines changed

18 files changed

+4424
-1508
lines changed

examples/client/src/integration/wiremock/__files/schema.graphql

Lines changed: 17 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,13 @@
1-
schema @link(import : ["@extends", "@external", "@inaccessible", "@key", "@override", "@provides", "@requires", "@shareable", "@tag", "_FieldSet"], url : "https://specs.apollo.dev/federation/v2.0"){
1+
schema @link(import : ["@composeDirective", "@extends", "@external", "@inaccessible", "@interfaceObject", "@key", "@override", "@provides", "@requires", "@shareable", "@tag", "FieldSet"], url : "https://specs.apollo.dev/federation/v2.3"){
22
query: Query
33
mutation: Mutation
44
}
55

6+
"Marks underlying custom directive to be included in the Supergraph schema"
7+
directive @composeDirective(name: String!) repeatable on SCHEMA
8+
9+
directive @custom on SCHEMA | SCALAR | OBJECT | FIELD_DEFINITION | ARGUMENT_DEFINITION | INTERFACE | UNION | ENUM | ENUM_VALUE | INPUT_OBJECT | INPUT_FIELD_DEFINITION
10+
611
"Marks the field, argument, input field or enum value as deprecated"
712
directive @deprecated(
813
"The reason for the deprecation"
@@ -13,7 +18,7 @@ directive @deprecated(
1318
directive @extends on OBJECT | INTERFACE
1419

1520
"Marks target field as external meaning it will be resolved by federated schema"
16-
directive @external on FIELD_DEFINITION
21+
directive @external on OBJECT | FIELD_DEFINITION
1722

1823
"Marks location within schema as inaccessible from the GraphQL Gateway"
1924
directive @inaccessible on SCALAR | OBJECT | FIELD_DEFINITION | ARGUMENT_DEFINITION | INTERFACE | UNION | ENUM | ENUM_VALUE | INPUT_OBJECT | INPUT_FIELD_DEFINITION
@@ -24,23 +29,26 @@ directive @include(
2429
if: Boolean!
2530
) on FIELD | FRAGMENT_SPREAD | INLINE_FRAGMENT
2631

32+
"Provides meta information to the router that this entity type is an interface in the supergraph."
33+
directive @interfaceObject on OBJECT
34+
2735
"Space separated list of primary keys needed to access federated object"
28-
directive @key(fields: _FieldSet!, resolvable: Boolean) repeatable on OBJECT | INTERFACE
36+
directive @key(fields: FieldSet!, resolvable: Boolean = true) repeatable on OBJECT | INTERFACE
2937

3038
"Links definitions within the document to external schemas."
31-
directive @link(import: [String], url: String) repeatable on SCHEMA
39+
directive @link(import: [String], url: String!) repeatable on SCHEMA
3240

3341
"Overrides fields resolution logic from other subgraph. Used for migrating fields from one subgraph to another."
34-
directive @override(from: String!) repeatable on FIELD_DEFINITION
42+
directive @override(from: String!) on FIELD_DEFINITION
3543

3644
"Specifies the base type field set that will be selectable by the gateway"
37-
directive @provides(fields: _FieldSet!) on FIELD_DEFINITION
45+
directive @provides(fields: FieldSet!) on FIELD_DEFINITION
3846

3947
"Specifies required input field set from the base type for a resolver"
40-
directive @requires(fields: _FieldSet!) on FIELD_DEFINITION
48+
directive @requires(fields: FieldSet!) on FIELD_DEFINITION
4149

4250
"Indicates that given object and/or field can be resolved by multiple subgraphs"
43-
directive @shareable on OBJECT | FIELD_DEFINITION
51+
directive @shareable repeatable on OBJECT | FIELD_DEFINITION
4452

4553
"Directs the executor to skip this field or fragment when the `if` argument is true."
4654
directive @skip(
@@ -249,7 +257,7 @@ scalar UUID
249257
scalar _Any
250258

251259
"Federation type representing set of fields"
252-
scalar _FieldSet
260+
scalar FieldSet
253261

254262
"Some basic description"
255263
input BasicObjectInput {

examples/federation/gateway/.nvmrc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
12
1+
16

examples/federation/gateway/index.js

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2019 Expedia, Inc
2+
* Copyright 2023 Expedia, Inc
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -14,9 +14,10 @@
1414
* limitations under the License.
1515
*/
1616

17-
const { ApolloServer } = require("apollo-server");
18-
const { ApolloServerPluginLandingPageGraphQLPlayground } = require('apollo-server-core');
19-
const { ApolloGateway, IntrospectAndCompose } = require("@apollo/gateway");
17+
import { ApolloServer } from '@apollo/server';
18+
import { startStandaloneServer } from '@apollo/server/standalone';
19+
import { ApolloServerPluginLandingPageLocalDefault } from '@apollo/server/plugin/landingPage/default';
20+
import { ApolloGateway, IntrospectAndCompose } from '@apollo/gateway';
2021

2122
const server = new ApolloServer({
2223
gateway: new ApolloGateway({
@@ -29,11 +30,11 @@ const server = new ApolloServer({
2930
})
3031
}),
3132
plugins: [
32-
ApolloServerPluginLandingPageGraphQLPlayground()
33+
ApolloServerPluginLandingPageLocalDefault({ embed: false })
3334
],
3435
subscriptions: false,
3536
});
3637

37-
server.listen().then(({ url }) => {
38-
console.log(`🚀 Server ready at ${url}`);
39-
});
38+
startStandaloneServer(server, {
39+
listen: { port: 4000 },
40+
}).then(({ url }) => console.log(`🚀 Gateway ready at ${url}`));

0 commit comments

Comments
 (0)