Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

@apollo/gateway

Package Overview
Dependencies
Maintainers
1
Versions
346
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@apollo/gateway

Apollo Gateway

  • 2.9.3
  • latest
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
150K
decreased by-12.6%
Maintainers
1
Weekly downloads
 
Created

What is @apollo/gateway?

@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.

What are @apollo/gateway's main functionalities?

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}`);
});

Other packages similar to @apollo/gateway

Keywords

FAQs

Package last updated on 16 Oct 2024

Did you know?

Socket

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.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc