An ApolloServer
instance automatically runs in federation mode when passed the gateway
option during instantiation. The gateway
option points to an object containing the gateway's configuration, which is created by instantiating a new ApolloGateway()
(from the @apollo/gateway
library).
Note that the option you pass in to your ApolloServer
constructor must be named gateway
. If your configuration object is not named gateway
, you will need to pass in your configuration like so:
// gateway object.
const gatewayConfig = new ApolloGateway();
const server = new ApolloServer({
// gateway needs needs to be declared explicitly due to the name of the config object.
gateway: gatewayConfig,
/// ... other options
});
Full example and documentation.
const { ApolloServer } = require("apollo-server");
const { ApolloGateway } = require("@apollo/gateway");
const gateway = new ApolloGateway();
const server = new ApolloServer({
gateway,
// Subscriptions are not currently supported in Apollo Federation
subscriptions: false,
});
server
.listen()
.then(({ url }) => {
console.log(`🚀 Gateway ready at ${url}`);
})
.catch((err) => {
console.error(err);
});
Comments
0 commentsPlease sign in to leave a comment.