Have ideas to improve npm?Join in the discussion! »

    @apollo/federation
    TypeScript icon, indicating that this package has built-in type declarations

    0.25.1 • Public • Published

    Apollo Federation Utilities

    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 Federation API reference.

    Usage

    const { ApolloServer, gql } = require("apollo-server");
    const { buildFederatedSchema } = require("@apollo/federation");
    
    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: buildFederatedSchema([{ typeDefs, resolvers }])
    });

    Install

    npm i @apollo/federation

    DownloadsWeekly Downloads

    874,570

    Version

    0.25.1

    License

    MIT

    Unpacked Size

    782 kB

    Total Files

    301

    Last publish

    Collaborators

    • avatar