npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2026 – Pkg Stats / Ryan Hefner

@apollo/subgraph

v2.15.1

Published

Apollo Federation subgraph utilities built on graphql-js

Readme

Continuous Integration MIT License NPM Join the community forum

@apollo/subgraph

Apollo Federation subgraph utilities for the graphql-js ecosystem.

@apollo/subgraph is built on top of graphql-js and provides transformation logic to make your GraphQL schemas Federation compatible. buildSubgraphSchema adds common Federation type definition (e.g. Any scalar, _Entity union, Federation directives, etc) and allows you to easily specify your Federated entity resolvers.

Installation

Requires Node.js 22 or later.

npm install @apollo/subgraph graphql

Usage

import { ApolloServer } from '@apollo/server';
import { startStandaloneServer } from '@apollo/server/standalone';
import { buildSubgraphSchema } from '@apollo/subgraph';
import gql from 'graphql-tag';

const typeDefs = gql`
  extend schema
    @link(url: "https://specs.apollo.dev/federation/v2.9", import: ["@key"])

  type Query {
    product(id: ID!): Product
  }

  type Product @key(fields: "id") {
    id: ID!
    name: String
  }
`;

const resolvers = {
  Query: {
    product: (_source, { id }) => products.find((product) => product.id === id),
  },
  Product: {
    // Called for each entity representation the router sends to `_entities`.
    __resolveReference: (reference) =>
      products.find((product) => product.id === reference.id),
  },
};

const server = new ApolloServer({
  schema: buildSubgraphSchema([{ typeDefs, resolvers }]),
});

await startStandaloneServer(server, { listen: { port: 4001 } });

API

  • buildSubgraphSchema(modulesOrSDL) — builds the executable subgraph schema. Accepts a DocumentNode, or an array of documents or { typeDefs, resolvers } modules.
  • printSubgraphSchema(schema) — prints the complete subgraph schema, federation directives and types included.
  • addResolversToSchema(schema, resolvers) — attaches a resolver map to an existing schema, understanding __resolveReference alongside the usual __resolveType / __isTypeOf.
  • entitiesResolver({ representations, context, info }) — the _entities resolver, exported for libraries that assemble their own root fields.

Entity references are resolved through __resolveReference, either from a resolver map or from extensions.apollo.subgraph.resolveReference on the type.

Development

npm install
npm run build
npm test

The compatibility/ workspace runs the Apollo Federation subgraph compatibility suite against this library, using docker compose for the router and reference subgraphs. See its README.

npm run compatibility --workspace @apollo/subgraph-compatibility

Contact

If you have a specific question about the library or code, please start a discussion in the Apollo community forums.

Contributing

See CONTRIBUTING.md for details.

After you have your local branch set up, take a look at our open issues to see where you can contribute.

Security

For more info on how to contact the team for security issues, see our Security Policy.

License

This library is licensed under The MIT License (MIT).