Skip to content

Commit

Permalink
feat: add support for federation v2.3 (#1674)
Browse files Browse the repository at this point in the history
Backport of Federation v2.1, v2.2 and v2.3 changes from `master`.
  • Loading branch information
dariuszkuc authored Feb 16, 2023
1 parent 8748198 commit 0bd1276
Show file tree
Hide file tree
Showing 18 changed files with 4,424 additions and 1,508 deletions.
26 changes: 17 additions & 9 deletions examples/client/src/integration/wiremock/__files/schema.graphql
Original file line number Diff line number Diff line change
@@ -1,8 +1,13 @@
schema @link(import : ["@extends", "@external", "@inaccessible", "@key", "@override", "@provides", "@requires", "@shareable", "@tag", "_FieldSet"], url : "https://specs.apollo.dev/federation/v2.0"){
schema @link(import : ["@composeDirective", "@extends", "@external", "@inaccessible", "@interfaceObject", "@key", "@override", "@provides", "@requires", "@shareable", "@tag", "FieldSet"], url : "https://specs.apollo.dev/federation/v2.3"){
query: Query
mutation: Mutation
}

"Marks underlying custom directive to be included in the Supergraph schema"
directive @composeDirective(name: String!) repeatable on SCHEMA

directive @custom on SCHEMA | SCALAR | OBJECT | FIELD_DEFINITION | ARGUMENT_DEFINITION | INTERFACE | UNION | ENUM | ENUM_VALUE | INPUT_OBJECT | INPUT_FIELD_DEFINITION

"Marks the field, argument, input field or enum value as deprecated"
directive @deprecated(
"The reason for the deprecation"
Expand All @@ -13,7 +18,7 @@ directive @deprecated(
directive @extends on OBJECT | INTERFACE

"Marks target field as external meaning it will be resolved by federated schema"
directive @external on FIELD_DEFINITION
directive @external on OBJECT | FIELD_DEFINITION

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

"Provides meta information to the router that this entity type is an interface in the supergraph."
directive @interfaceObject on OBJECT

"Space separated list of primary keys needed to access federated object"
directive @key(fields: _FieldSet!, resolvable: Boolean) repeatable on OBJECT | INTERFACE
directive @key(fields: FieldSet!, resolvable: Boolean = true) repeatable on OBJECT | INTERFACE

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

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

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

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

"Indicates that given object and/or field can be resolved by multiple subgraphs"
directive @shareable on OBJECT | FIELD_DEFINITION
directive @shareable repeatable on OBJECT | FIELD_DEFINITION

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

"Federation type representing set of fields"
scalar _FieldSet
scalar FieldSet

"Some basic description"
input BasicObjectInput {
Expand Down
2 changes: 1 addition & 1 deletion examples/federation/gateway/.nvmrc
Original file line number Diff line number Diff line change
@@ -1 +1 @@
12
16
17 changes: 9 additions & 8 deletions examples/federation/gateway/index.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2019 Expedia, Inc
* Copyright 2023 Expedia, Inc
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand All @@ -14,9 +14,10 @@
* limitations under the License.
*/

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

const server = new ApolloServer({
gateway: new ApolloGateway({
Expand All @@ -29,11 +30,11 @@ const server = new ApolloServer({
})
}),
plugins: [
ApolloServerPluginLandingPageGraphQLPlayground()
ApolloServerPluginLandingPageLocalDefault({ embed: false })
],
subscriptions: false,
});

server.listen().then(({ url }) => {
console.log(`🚀 Server ready at ${url}`);
});
startStandaloneServer(server, {
listen: { port: 4000 },
}).then(({ url }) => console.log(`🚀 Gateway ready at ${url}`));
Loading

0 comments on commit 0bd1276

Please sign in to comment.