包详细信息

@apollo/subgraph

apollographql1.9mMIT2.11.1

Apollo Subgraph Utilities

graphql, federation, apollo, subgraph

自述文件

Apollo Subgraph

This package provides utilities for creating GraphQL microservices, which can be combined into a single endpoint through tools like Apollo Gateway.

For complete documentation, see the Apollo Subgraph API reference.

Usage

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

const typeDefs = gql`
  type Query {
    me: User
  }

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

const resolvers = {
  Query: {
    me() {
      return { id: "1", username: "@ava" }
    }
  },
  User: {
    __resolveReference(user, { fetchUserById }){
      return fetchUserById(user.id)
    }
  }
};

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

// Note the top-level await!
const { url } = await startStandaloneServer(server);
console.log(`🚀  Server ready at ${url}`);

更新日志

Changelog

This repository contains multiple JavaScript packages, each with multiple changelogs. Federation 1 is managed on the version-0.x branch, while Federation 2 is managed on the main branch. Please consult the table below to find the changelog you are looking for:

npm package v1 v2
@apollo/gateway changelog changelog
@apollo/query-planner changelog changelog
@apollo/subgraph changelog changelog
@apollo/federation changelog N/A
@apollo/federation-internals N/A changelog
@apollo/query-graphs N/A changelog
@apollo/composition N/A changelog