
Security News
Django Joins curl in Pushing Back on AI Slop Security Reports
Django has updated its security policies to reject AI-generated vulnerability reports that include fabricated or unverifiable content.
@apollo/gateway
Advanced tools
@apollo/gateway is a package that allows you to build a federated data graph by composing multiple GraphQL services into a single unified API. It is part of Apollo's Federation architecture, which enables you to manage and scale your GraphQL services independently while providing a seamless experience for clients.
Creating a Gateway
This code sample demonstrates how to create an Apollo Gateway that composes multiple GraphQL services into a single unified API. The `serviceList` array contains the list of services to be federated.
const { ApolloGateway } = require('@apollo/gateway');
const { ApolloServer } = require('apollo-server');
const gateway = new ApolloGateway({
serviceList: [
{ name: 'accounts', url: 'http://localhost:4001' },
{ name: 'products', url: 'http://localhost:4002' },
{ name: 'reviews', url: 'http://localhost:4003' }
]
});
const server = new ApolloServer({ gateway, subscriptions: false });
server.listen().then(({ url }) => {
console.log(`🚀 Server ready at ${url}`);
});
Customizing Service Health Checks
This code sample shows how to enable service health checks in Apollo Gateway. The `serviceHealthCheck` option ensures that the gateway periodically checks the health of the federated services.
const { ApolloGateway } = require('@apollo/gateway');
const { ApolloServer } = require('apollo-server');
const gateway = new ApolloGateway({
serviceList: [
{ name: 'accounts', url: 'http://localhost:4001' },
{ name: 'products', url: 'http://localhost:4002' },
{ name: 'reviews', url: 'http://localhost:4003' }
],
serviceHealthCheck: true
});
const server = new ApolloServer({ gateway, subscriptions: false });
server.listen().then(({ url }) => {
console.log(`🚀 Server ready at ${url}`);
});
Using Managed Federation
This code sample demonstrates how to use managed federation with Apollo Gateway. The `experimental_pollInterval` option allows the gateway to periodically poll for updates to the federated services' schemas.
const { ApolloGateway } = require('@apollo/gateway');
const { ApolloServer } = require('apollo-server');
const gateway = new ApolloGateway({
serviceList: [
{ name: 'accounts', url: 'http://localhost:4001' },
{ name: 'products', url: 'http://localhost:4002' },
{ name: 'reviews', url: 'http://localhost:4003' }
],
experimental_pollInterval: 10000
});
const server = new ApolloServer({ gateway, subscriptions: false });
server.listen().then(({ url }) => {
console.log(`🚀 Server ready at ${url}`);
});
graphql-tools is a package that provides a set of utilities to build and manipulate GraphQL schemas in JavaScript. It allows you to create a unified schema from multiple GraphQL services, similar to Apollo Gateway. However, it does not provide the same level of built-in support for federated services and managed federation as Apollo Gateway.
graphql-mesh is a package that allows you to create a unified GraphQL schema from multiple sources, including REST APIs, gRPC services, and other GraphQL APIs. It provides a flexible and extensible way to integrate different data sources into a single GraphQL API. Compared to Apollo Gateway, graphql-mesh offers more versatility in terms of the types of data sources it can integrate, but it may require more configuration and setup.
This package provides utilities for combining multiple GraphQL microservices into a single GraphQL endpoint.
Each microservice should implement the federation schema specification. This can be done either through Apollo Federation or a variety of other open source products.
For complete documentation, see the Apollo Gateway API reference.
import { ApolloServer } from "@apollo/server";
import { startStandaloneServer } from '@apollo/server/standalone';
import { ApolloGateway, IntrospectAndCompose } from "@apollo/gateway";
const gateway = new ApolloGateway({
supergraphSdl: new IntrospectAndCompose({
subgraphs: [
{ name: "accounts", url: "http://localhost:4001/graphql" }
// List of federation-capable GraphQL endpoints...
],
}),
});
const server = new ApolloServer({ gateway });
// Note the top-level await!
const { url } = await startStandaloneServer(server);
console.log(`🚀 Server ready at ${url}`);
FAQs
Apollo Gateway
The npm package @apollo/gateway receives a total of 231,436 weekly downloads. As such, @apollo/gateway popularity was classified as popular.
We found that @apollo/gateway demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
Django has updated its security policies to reject AI-generated vulnerability reports that include fabricated or unverifiable content.
Security News
ECMAScript 2025 introduces Iterator Helpers, Set methods, JSON modules, and more in its latest spec update approved by Ecma in June 2025.
Security News
A new Node.js homepage button linking to paid support for EOL versions has sparked a heated discussion among contributors and the wider community.