UNPKG

@apollo/subgraph

Version:
47 lines (37 loc) 1.15 kB
# `Apollo Subgraph` This package provides utilities for creating GraphQL microservices, which can be combined into a single endpoint through tools like [Apollo Gateway](https://github.com/apollographql/federation/tree/main/gateway-js). For complete documentation, see the [Apollo Subgraph API reference](https://www.apollographql.com/docs/federation/subgraphs/). ## Usage ```js 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}`); ```