• Stars
    star
    131
  • Rank 265,830 (Top 6 %)
  • Language
    Shell
  • License
    MIT License
  • Created about 3 years ago
  • Updated 2 months ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

๐Ÿฟ Compose subgraphs into a Federation v1 supergraph at build-time with static composition to power a federated graph router at runtime.

Supergraph Demo

smoke test Renovate

๐Ÿ“ฃ Apollo Federation 2 is generally available! View the Federation 2 demo!

Moving from dynamic composition to static composition with supergraphs.

Contents:

See also:

Welcome

Apollo Federation and Managed Federation have delivered significant improvements over schema stitching and alternate approaches. Static composition introduces another big step forward as we move composition out of the Gateway and into the CI pipeline where federated graph changes can be validated sooner and built into static artifacts that define how a Gateway should route requests across the subgraphs in a federation.

Most contemporary federated GraphQL implementations dynamically compose a list of implementing services (subgraphs) into a GraphQL Gateway at runtime. There is no static artifact that can be versioned, validated, or reasoned about across a fleet of Gateway instances that are common in scale-out federated graph deployments. Gateways often rely on hard-coded behavior for directives like join or accept additional non-GraphQL configuration.

With static composition, you can compose subgraphs into a supergraph at build-time resulting in a static artifact (supergraph schema) that describes the machinery to power a graph router at runtime. The supergraph schema includes directives like join that instruct a graph router how federate multiple subgraphs into a single graph for consumers to use.

Apollo Federation with Supergraphs

See also: New Federation UX - Docs

Prerequisites

You'll need:

To install rover:

curl -sSL https://rover.apollo.dev/nix/latest | sh

Local Development

Local Supergraph Composition

See also: Apollo Federation docs

You can federate multiple subgraphs into a supergraph using:

make demo

which does the following:

# build a supergraph from 3 subgraphs: products, users, inventory
make supergraph

which runs:

rover supergraph compose --config ./supergraph.yaml > supergraph.graphql

and then runs:

docker-compose up -d

Creating apollo-gateway ... done
Creating inventory ... done
Creating users     ... done
Creating products  ... done

Starting Apollo Gateway in local mode ...
Using local: supergraph.graphql
๐Ÿš€ Graph Router ready at http://localhost:4000/

make demo then issues a curl request to the graph router via:

make query

which issues the following query that fetches across 3 subgraphs:

query Query {
  allProducts {
    id
    sku
    createdBy {
      email
      totalProductsCreated
    }
  }
}

with results like:

{
  data: {
    allProducts: [
      {
        id: "apollo-federation",
        sku: "federation",
        createdBy: {
          email: "[email protected]",
          totalProductsCreated: 1337
        }
      },{
        id: "apollo-studio",
        sku: "studio",
        createdBy:{
          email: "[email protected]",
          totalProductsCreated: 1337
        }
      }
    ]
  }
}

make demo then shuts down the graph router:

docker-compose down

Apollo Sandbox for Local Development

Deploy Graph

make docker-up

Query using Apollo Sandbox

  1. Open http://localhost:4000/
  2. Click Query your server
  3. Run a query:
query Query {
  allProducts {
    id
    sku
    createdBy {
      email
      totalProductsCreated
    }
  }
}

View results:

Apollo Sandbox Screenshot

Cleanup

make docker-down

Tracing with Open Telemetry

Deploy Graph with Open Telemetry Collector

make docker-up-otel-collector

Run Queries

make smoke

View Open Telemetry Traces

browse to http://localhost:9411/

opentelemetry

Cleanup

make docker-down-otel-collector

Send Open Telemetry Traces to Honeycomb

You can send Open Telemetry from the Gateway to Honeycomb with the following collector-config.yml:

receivers:
  otlp:
    protocols:
      grpc:
      http:
        cors_allowed_origins:
          - http://*
          - https://*

exporters:
  otlp:
    endpoint: "api.honeycomb.io:443"
    headers:
      "x-honeycomb-team": "your-api-key"
      "x-honeycomb-dataset": "your-dataset-name"

service:
  pipelines:
    traces:
      receivers: [otlp]
      exporters: [otlp]

honeycomb

Learn More

Apollo Studio

Composition in Apollo Studio

See also: Apollo Studio docs

Managed Federation in Apollo Studio enables teams to independently publish subgraphs to the Apollo Registry, so they can be automatically composed into a supergraph for apps to use.

Create a Federated Graph in Apollo Studio

To get started with Managed Federation, create your Apollo account:

Then create a Graph of type Deployed with the Federation option.

Once you have created your graph in Apollo Studio, run the following:

make demo-managed

Connect to your Graph in Apollo Studio

which will prompt for your graph key and graph ref and save them to ./graph-api.env:

  • graph key - the graph API key used to authenticate with Apollo Studio.
  • graph ref - a reference to the graph in Apollo's registry the graph router should pull from.
    • in the form <graph-id>@<variant>
    • @<variant> is optional and will default to @current
    • examples: my-graph@dev, my-graph@stage, my-graph@prod
  • see configuration reference for details.

Note: The generated ./graph-api.env holds your APOLLO_KEY and APOLLO_GRAPH_REF.

Publish Subgraph Schemas to the Apollo Registry

make demo-managed will publish the subgraphs/**.graphql schemas to your new Federated graph in the Apollo Registry, which performs managed composition and schema checks, to prevent breaking changes:

make publish

Temporary composition errors may surface as each subgraph is published:

+ rover subgraph publish supergraph-router@dev --routing-url http://products:4000/graphql --schema subgraphs/products/products.graphql --name products

Publishing SDL to supergraph-router:dev (subgraph: products) using credentials from the default profile.

A new subgraph called 'products' for the 'supergraph-router' graph was created.

The gateway for the 'supergraph-router' graph was NOT updated with a new schema

WARN: The following composition errors occurred:
Unknown type "User".
[products] Query -> `Query` is an extension type, but `Query` is not defined in any service

Success! Once all subgraphs are published the supergraph will be updated, for example:

+ rover subgraph publish supergraph-router@dev --routing-url https://users:4000/graphql --schema subgraphs/users/users.graphql --name users

Publishing SDL to supergraph-router:dev (subgraph: users) using credentials from the default profile.

A new subgraph called 'users' for the 'supergraph-router' graph was created

The gateway for the 'supergraph-router' graph was updated with a new schema, composed from the updated 'users' subgraph

Viewing the Federated graph in Apollo Studio we can see the supergraph and the subgraphs it's composed from: Federated Graph in Apollo Studio

Run the Graph Router and Subgraph Containers

The graph router and subgraph services will be started by make demo-managed next.

using docker-compose.managed.yml:

version: '3'
services:
  apollo-gateway:
    container_name: apollo-gateway
    build: ./gateway
    environment:
      - APOLLO_SCHEMA_CONFIG_DELIVERY_ENDPOINT=https://uplink.api.apollographql.com/
    env_file: # created with: make graph-api-env
      - graph-api.env
    ports:
      - "4000:4000"
  products:
    container_name: products
    build: ./subgraphs/products
  inventory:
    container_name: inventory
    build: ./subgraphs/inventory
  users:
    container_name: users
    build: ./subgraphs/users
make docker-up-managed

which shows:

docker-compose -f docker-compose.managed.yml up -d
Creating network "supergraph-demo_default" with the default driver
Creating apollo-gateway ... done

Starting Apollo Gateway in managed mode ...
Apollo usage reporting starting! See your graph at https://studio.apollographql.com/graph/supergraph-router@dev/
๐Ÿš€ Server ready at http://localhost:4000/

Make a Federated Query

make demo-managed then issues a curl request to the graph router:

make query

which has the same query and response as above.

Clean Up

make demo-managed then shuts down the graph router:

make docker-down

Ship Faster Without Breaking Changes

See also: working with subgraphs docs

Apollo Schema Checks help ensure subgraph changes don't break the federated graph, reducing downtime and enabling teams to ship faster.

The Graph Router will Update In Place

With Managed Federation you can leave the graph router running and it will update automatically when subgraph changes are published and they successfully compose and pass all schema checks in Apollo Studio:

make docker-up-managed
Starting Apollo Gateway in managed mode ...
Apollo usage reporting starting! See your graph at https://studio.apollographql.com/graph/supergraph-router@dev/
๐Ÿš€ Server ready at http://localhost:4000/

Simulating a Change to the Product Subgraph

To simulate a change to the products subgraph, add a Color enum to .subgraphs/products.graphql:

enum Color {
  BLUE
  GREEN
}

Then publish the changes to the registry:

make publish

Then remove the Color enum from .subgraphs/products.graphql:

enum Color {
  BLUE
  GREEN
}

Run a Schema Check

Run a schema check against the published version in the registry:

make check-products

This detects the schema changes and compares them against the known graph operations to determine that even though there are schema changes, there is no impact to actual operations so changes can be safely published:

Checked the proposed subgraph against supergraph-demo@current
Compared 3 schema changes against 2 operations
โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ฌโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ฌโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”
โ”‚ Change โ”‚          Code           โ”‚               Description                โ”‚
โ”œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ผโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ผโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ค
โ”‚ PASS   โ”‚ TYPE_REMOVED            โ”‚ type `Color`: removed                    โ”‚
โ”œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ผโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ผโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ค
โ”‚ PASS   โ”‚ VALUE_REMOVED_FROM_ENUM โ”‚ enum type `Color`: value `BLUE` removed  โ”‚
โ”œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ผโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ผโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ค
โ”‚ PASS   โ”‚ VALUE_REMOVED_FROM_ENUM โ”‚ enum type `Color`: value `GREEN` removed โ”‚
โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ดโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ดโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜

Publish Validated Subgraph Schemas to Apollo Registry

Then publish the changes and check again:

make publish

make check-products

which shows:

Checked the proposed subgraph against supergraph-demo@current
There were no changes detected in the composed schema.

Recap

Using rover in a local dev environment helps catch potentially breaking changes sooner. The next section covers how rover can be integrated into your CI/CD environments, and how Managed Federation catches breaking changes before they are delivered to the graph router.

Standard CI/CD

This example repo is a monorepo, but this same basic CI/CD workflow applies for single-repo-per-package scenarios.

Subgraph CI

With this approach, failed schema checks (example) are caught as close to the source of the change as possible, but only fully validated supergraph schemas are published for use.

schema-check-breaking-change

Breaking changes are sometimes intentional, and to accommodate this, Apollo Studio has the option to mark certain changes as safe in the UI, that provides a check report URL in your CI, so you can easily navigate to Apollo Studio to: review the check, mark things safe and then re-run your pipeline.

schema-check-mark-safe

Subgraph Deployment

  • Run a deployment workflow like this simple example subgraph-deploy-publish.yml
    • Before subgraph deployment
      • Do a reality check with rover subgraph check
    • Deploy subgraph service
      • Should have the service deployed before publishing the subgraph schema
    • After subgraph deployment
      • Publish the subgraph schema to the registry with rover subgraph publish
      • Managed Federation will run central schema checks and operation check and publish a new supergraph schema for the Gateways in the fleet for each environment

Publishing subgraph schema changes with rover subgraph publish always stores a new subgraph schema version to the Apollo Registry, even if schema checks donโ€™t pass.

Managed Federation ultimately catches all breaking changes prior before a new supergraph schema is published:

  • Runs schema checks after each rover subgraph publish
  • Composes a supergraph schema if all checks pass
  • Makes the supergraph schema available in the:
    • Apollo Uplink - that the Gateway can poll for live updates (default).
    • Apollo Registry - for retrieval via rover supergraph fetch.
    • Apollo Supergraph Build Webhook - for custom integrations

Key benefits to Managed Federation:

  • CI for multiple concurrent rover subgraph publish from multiple service repos
  • Central point of control & governance
  • Globally consistent schema checks and composition
  • Catches breaking changes at supergraph build time before a new supergraph is published, before they're published for Gateways to use.

Gateway CI

The Gateway image and configuration can be managed using standard CI practices.

For example, if using Docker images:

Gateway Deployment

The default configuration for the Gateway is to update in place by pulling new supergraph schema versions as they're published to the Apollo Uplink. Gateways in the fleet poll the Uplink every 10 seconds by default, so there will be a fast rolling upgrade as Gateways check the Uplink, without the need to restart the Gateway.

Update in place is useful for any long-lived Gateway instance where an immediate update of the Gateway instance's supergraph schema is desired.

Update-in-place with Managed Federation is useful for:

  • long-lived VMs
  • Kubernetes Deployments
  • Serverless functions that may be cached outside of operator control.

Configure the Gateways in each fleet dev, staging, prod to:

Custom Gateway Deployments

You can do custom CD with the following hooks and the rover CLI:

See Kubernetes-native GraphOps to learn more about using custom CD with Kubernetes and GitOps.

Deployment Examples

Kubernetes with Supergraph ConfigMap

You'll need the latest versions of:

  • kubectl - with expanded kustomize support for resources
  • kind

then run:

make demo-k8s

which generates a graph router Deployment and supergraph ConfigMap using:

kubectl kustomize k8s/router/base

and then creates:

  • local k8s cluster with the NGINX Ingress Controller
  • graph-router Deployment configured to use a supergraph ConfigMap
  • graph-router Service and Ingress

Gateway Deployment with Supergraph ConfigMap

using k8s/router/base/router.yaml via:

kubectl apply -k k8s/router/base
apiVersion: apps/v1
kind: Deployment
metadata:
  labels:
    app: router
  name: router-deployment
spec:
  replicas: 1
  selector:
    matchLabels:
      app: router
  template:
    metadata:
      labels:
        app: router
    spec:
      containers:
      - env:
        - name: APOLLO_SCHEMA_CONFIG_EMBEDDED
          value: "true"
        image: prasek/supergraph-router:latest
        name: router
        ports:
        - containerPort: 4000
        volumeMounts:
        - mountPath: /etc/config
          name: supergraph-volume
      volumes:
      - configMap:
          name: supergraph-c22698b7b9
        name: supergraph-volume
---
apiVersion: v1
kind: ConfigMap
metadata:
  name: supergraph-c22698b7b9
data:
  supergraph.graphql: |
    schema
      @core(feature: "https://specs.apollo.dev/core/v0.1"),
      @core(feature: "https://specs.apollo.dev/join/v0.1")
    {
      query: Query
    }

    ...

    enum join__Graph {
      INVENTORY @join__graph(name: "inventory" url: "http://inventory:4000/graphql")
      PRODUCTS @join__graph(name: "products" url: "http://products:4000/graphql")
      USERS @join__graph(name: "users" url: "https://users:4000/graphql")
    }

    type Product
      @join__owner(graph: PRODUCTS)
      @join__type(graph: PRODUCTS, key: "id")
      @join__type(graph: PRODUCTS, key: "sku package")
      @join__type(graph: PRODUCTS, key: "sku variation{id}")
      @join__type(graph: INVENTORY, key: "id")
    {
      id: ID! @join__field(graph: PRODUCTS)
      sku: String @join__field(graph: PRODUCTS)
      package: String @join__field(graph: PRODUCTS)
      variation: ProductVariation @join__field(graph: PRODUCTS)
      dimensions: ProductDimension @join__field(graph: PRODUCTS)
      createdBy: User @join__field(graph: PRODUCTS, provides: "totalProductsCreated")
      delivery(zip: String): DeliveryEstimates @join__field(graph: INVENTORY, requires: "dimensions{size weight}")
    }

    type ProductDimension {
      size: String
      weight: Float
    }

    type ProductVariation {
      id: ID!
    }

    type Query {
      allProducts: [Product] @join__field(graph: PRODUCTS)
      product(id: ID!): Product @join__field(graph: PRODUCTS)
    }

    type User
      @join__owner(graph: USERS)
      @join__type(graph: USERS, key: "email")
      @join__type(graph: PRODUCTS, key: "email")
    {
      email: ID! @join__field(graph: USERS)
      name: String @join__field(graph: USERS)
      totalProductsCreated: Int @join__field(graph: USERS)
    }
---
apiVersion: v1
kind: Service
metadata:
  name: router-service
spec:
  ports:
  - port: 4000
    protocol: TCP
    targetPort: 4000
  selector:
    app: router
---
apiVersion: networking.k8s.io/v1
kind: Ingress
metadata:
  annotations:
    kubernetes.io/ingress.class: nginx
  name: router-ingress
spec:
  rules:
  - http:
      paths:
      - backend:
          service:
            name: router-service
            port:
              number: 4000
        path: /
        pathType: Prefix

and 3 subgraph services k8s/subgraphs/base/subgraphs.yaml via:

kubectl kustomize k8s/subgraphs/base

Make a GraphQL Query

make demo-k8s then runs the following in a loop until the query succeeds or 2 min timeout:

kubectl get all
make k8s-query

which shows the following:

NAME                                     READY   STATUS    RESTARTS   AGE
pod/inventory-65494cbf8f-bhtft           1/1     Running   0          59s
pod/products-6d75ff449c-9sdnd            1/1     Running   0          59s
pod/router-deployment-84cbc9f689-8fcnf   1/1     Running   0          20s
pod/users-d85ccf5d9-cgn4k                1/1     Running   0          59s

NAME                     TYPE        CLUSTER-IP      EXTERNAL-IP   PORT(S)    AGE
service/inventory        ClusterIP   10.96.108.120   <none>        4000/TCP   59s
service/kubernetes       ClusterIP   10.96.0.1       <none>        443/TCP    96s
service/products         ClusterIP   10.96.65.206    <none>        4000/TCP   59s
service/router-service   ClusterIP   10.96.178.206   <none>        4000/TCP   20s
service/users            ClusterIP   10.96.98.53     <none>        4000/TCP   59s

NAME                                READY   UP-TO-DATE   AVAILABLE   AGE
deployment.apps/inventory           1/1     1            1           59s
deployment.apps/products            1/1     1            1           59s
deployment.apps/router-deployment   1/1     1            1           20s
deployment.apps/users               1/1     1            1           59s

NAME                                           DESIRED   CURRENT   READY   AGE
replicaset.apps/inventory-65494cbf8f           1         1         1       59s
replicaset.apps/products-6d75ff449c            1         1         1       59s
replicaset.apps/router-deployment-84cbc9f689   1         1         1       20s
replicaset.apps/users-d85ccf5d9                1         1         1       59s
Smoke test
-------------------------------------------------------------------------------------------
++ curl -X POST -H 'Content-Type: application/json' --data '{ "query": "{ allProducts { id, sku, createdBy { email, totalProductsCreated } } }" }' http://localhost:80/
  % Total    % Received % Xferd  Average Speed   Time    Time     Time  Current
                                 Dload  Upload   Total   Spent    Left  Speed
100   352  100   267  100    85   3000    955 --:--:-- --:--:-- --:--:--  3911
{"data":{"allProducts":[{"id":"apollo-federation","sku":"federation","createdBy":{"email":"[email protected]","totalProductsCreated":1337}},{"id":"apollo-studio","sku":"studio","createdBy":{"email":"[email protected]","totalProductsCreated":1337}}]}}
Success!
-------------------------------------------------------------------------------------------

Cleanup

make demo-k8s then cleans up:

deployment.apps "graph-router" deleted
service "graphql-service" deleted
ingress.networking.k8s.io "graphql-ingress" deleted
Deleting cluster "kind" ...

Serverless

See serverless.yml

make demo-serverless

which does the following:

rover supergraph compose --config serverless/supergraph.yaml > serverless/supergraph.graphql
docker-compose -f docker-compose.serverless.yml up -d
Creating network "supergraph-demo_default" with the default driver
Creating serverless ... done
docker-compose -f docker-compose.serverless.yml logs
Attaching to serverless
serverless    | Serverless: Running "serverless" installed locally (in service node_modules)
serverless    | offline: Starting Offline: dev/us-east-1.
serverless    | offline: Offline [http for lambda] listening on http://0.0.0.0:3002
serverless    | offline: Function names exposed for local invocation by aws-sdk:
serverless    |            * router: supergraph-serverless-dev-router
serverless    |            * inventory: supergraph-serverless-dev-inventory
serverless    |            * products: supergraph-serverless-dev-products
serverless    |            * users: supergraph-serverless-dev-users
serverless    |
serverless    |  โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”
serverless    |  โ”‚                                                                           โ”‚
serverless    |  โ”‚   ANY | http://0.0.0.0:4000/                                              โ”‚
serverless    |  โ”‚   POST | http://0.0.0.0:4000/2015-03-31/functions/router/invocations      โ”‚
serverless    |  โ”‚   ANY | http://0.0.0.0:4000/inventory                                     โ”‚
serverless    |  โ”‚   POST | http://0.0.0.0:4000/2015-03-31/functions/inventory/invocations   โ”‚
serverless    |  โ”‚   ANY | http://0.0.0.0:4000/products                                      โ”‚
serverless    |  โ”‚   POST | http://0.0.0.0:4000/2015-03-31/functions/products/invocations    โ”‚
serverless    |  โ”‚   ANY | http://0.0.0.0:4000/users                                         โ”‚
serverless    |  โ”‚   POST | http://0.0.0.0:4000/2015-03-31/functions/users/invocations       โ”‚
serverless    |  โ”‚                                                                           โ”‚
serverless    |  โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜
serverless    |
serverless    | offline: [HTTP] server ready: http://0.0.0.0:4000 ๐Ÿš€
serverless    | offline:
serverless    | offline: Enter "rp" to replay the last request
-------------------------------------------------------------------------------------------
++ curl -X POST -H 'Content-Type: application/json' --data '{ "query": "{allProducts{id,sku,createdBy{email,totalProductsCreated}}}" }' http://localhost:4000/
  % Total    % Received % Xferd  Average Speed   Time    Time     Time  Current
                                 Dload  Upload   Total   Spent    Left  Speed
100   341  100   267  100    74    331     91 --:--:-- --:--:-- --:--:--   423

Result:
{"data":{"allProducts":[{"id":"apollo-federation","sku":"federation","createdBy":{"email":"[email protected]","totalProductsCreated":1337}},{"id":"apollo-studio","sku":"studio","createdBy":{"email":"[email protected]","totalProductsCreated":1337}}]}}
-------------------------------------------------------------------------------------------
docker-compose -f docker-compose.serverless.yml down
Stopping serverless ... done
Removing serverless ... done
Removing network supergraph-demo_default

Apollo Router

The Apollo Router is our next-generation GraphQL Federation runtime written in Rust, and it is fast.

As a Graph Router, the Apollo Router plays the same role as the Apollo Gateway. The same subgraph schemas and composed supergraph schema can be used in both the Router and the Gateway.

This demo shows using the Apollo Router with a Federation 1 supergraph schema, composed using the Fed 1 rover supergraph compose command. To see the Router working with Federation 2 composition, checkout the Apollo Router section of apollographql/supergraph-demo-fed2.

Early benchmarks show that the Router adds less than 10ms of latency to each operation, and it can process 8x the load of the JavaScript Apollo Gateway.

To get started with the Router:

make demo-local-router

this uses a simple docker-compose.router.yml file:

version: '3'
services:
  apollo-router:
    container_name: apollo-router
    build: ./router
    volumes:
      - ./supergraph.graphql:/etc/config/supergraph.graphql
      - ./router/configuration.yaml:/etc/config/configuration.yaml
    ports:
      - "4000:4000"
  products:
    container_name: products
    build: ./subgraphs/products
  inventory:
    container_name: inventory
    build: ./subgraphs/inventory
  users:
    container_name: users
    build: ./subgraphs/users

which uses the following Dockerfile

from ubuntu

WORKDIR /usr/src/app
RUN apt-get update && apt-get install -y \
    libssl-dev \
    curl \
    jq

COPY install.sh .
COPY run.sh .
RUN ./install.sh

CMD [ "/usr/src/app/run.sh" ]

see ./router for more details.

Learn More

Apollo tools and services help you develop, maintain, operate, and scale your data graph.

More Repositories

1

apollo-client

๐Ÿš€ ย A fully-featured, production ready caching GraphQL client for every UI framework and GraphQL server.
TypeScript
18,905
star
2

apollo-server

๐ŸŒ ย Spec-compliant and production ready JavaScript GraphQL server that lets you develop in a schema-first way. Built for Express, Connect, Hapi, Koa, and more.
TypeScript
13,522
star
3

react-apollo

โ™ป๏ธ React integration for Apollo Client
JavaScript
6,887
star
4

apollo-ios

๐Ÿ“ฑ ย A strongly-typed, caching GraphQL client for iOS, written in Swift.
Swift
3,737
star
5

apollo-kotlin

๐Ÿค– ย A strongly-typed, caching GraphQL client for the JVM, Android, and Kotlin multiplatform.
Kotlin
3,382
star
6

apollo-tooling

โœ๏ธ Apollo CLI for client tooling (Mostly replaced by Rover)
TypeScript
3,042
star
7

apollo

๐Ÿš€ Open source tools for GraphQL. Central repo for discussion.
JavaScript
2,626
star
8

graphql-tag

A JavaScript template literal tag that parses GraphQL queries
TypeScript
2,275
star
9

graphql-subscriptions

๐Ÿ“ฐ A small module that implements GraphQL subscriptions for Node.js
TypeScript
1,567
star
10

subscriptions-transport-ws

๐Ÿ”ƒ A WebSocket client + server for GraphQL subscriptions
TypeScript
1,524
star
11

apollo-client-devtools

Apollo Client browser developer tools.
TypeScript
1,471
star
12

apollo-link

๐Ÿ”— Interface for fetching and modifying control flow of GraphQL requests
TypeScript
1,438
star
13

apollo-link-state

โœจ Manage your application's state with Apollo!
TypeScript
1,405
star
14

apollo-cache-persist

๐ŸŽ Simple persistence for all Apollo Cache implementations
TypeScript
1,363
star
15

fullstack-tutorial

๐Ÿš€ The Apollo platform tutorial app
TypeScript
1,241
star
16

eslint-plugin-graphql

๐Ÿšฆ Check your GraphQL query strings against a schema.
JavaScript
1,194
star
17

apollo-link-rest

Use existing REST endpoints with GraphQL
TypeScript
783
star
18

router

A configurable, high-performance routing runtime for Apollo Federation ๐Ÿš€
Rust
737
star
19

federation

๐ŸŒ ย Build and scale a single data graph across multiple services with Apollo's federation gateway.
TypeScript
638
star
20

apollo-fetch

๐Ÿถ Lightweight GraphQL client that supports middleware and afterware
TypeScript
576
star
21

apollo-rs

Spec compliant GraphQL Tools in Rust.
Rust
556
star
22

reason-apollo

Reason binding for Apollo Client and React Apollo
Reason
555
star
23

federation-demo

Federation 2 supersedes this demo and this example is no longer the newest. See https://www.apollographql.com/docs/federation/ for migration steps!
JavaScript
504
star
24

ac3-state-management-examples

โœจ Learn Apollo Client 3's state management best practices
TypeScript
491
star
25

apollo-tracing

A GraphQL extension for performance tracing
475
star
26

persistgraphql

A build tool for GraphQL projects.
TypeScript
424
star
27

rover

โœจ๐Ÿค– ๐Ÿถ The CLI for Apollo GraphOS
Rust
389
star
28

gatsby-theme-apollo

๐Ÿ’œ Themes that we use to build Gatsby sites at Apollo
JavaScript
371
star
29

apollo-client-nextjs

Apollo Client support for the Next.js App Router
TypeScript
337
star
30

apollo-link-persisted-queries

Persisted Query support with Apollo Link
TypeScript
307
star
31

xcode-graphql

๐Ÿ›  Xcode add-ons that add syntax highlighting for GraphQL query document files
Shell
276
star
32

apollo-studio-community

๐ŸŽก ย GraphQL developer portal featuring an IDE (Apollo Explorer), auto-documentation, metrics reporting, and more. This repo is for issues, feature requests, and preview docs. ๐Ÿ“ฌ
246
star
33

federation-jvm

JVM support for Apollo Federation
Java
233
star
34

supergraph-demo-fed2

๐Ÿฟ Supergraph demo for Federation 2 and Apollo Router
Shell
155
star
35

apollo-cache-control

A GraphQL extension for cache control
146
star
36

principled-graphql

๐Ÿ“ˆ Best practices for implementing and scaling a data graph
JavaScript
145
star
37

apollo-feature-requests

๐Ÿง‘โ€๐Ÿš€ Apollo Client Feature Requests | (no ๐Ÿ› please).
128
star
38

spotify-showcase

A Spotify clone that showcases the Apollo GraphQL platform.
TypeScript
109
star
39

meteor-integration

๐Ÿš€ meteor add apollo
JavaScript
108
star
40

frontpage-ios-app

๐Ÿ“„ Apollo "hello world" app, for iOS
Swift
101
star
41

space-kit

๐Ÿ‘ฉโ€๐Ÿš€ Home base for Apollo's design system: https://space-kit.netlify.com
TypeScript
89
star
42

apollo-scalajs

Use Apollo GraphQL from Scala.js apps!
Scala
88
star
43

invariant-packages

Packages for working with invariant(condition, message) assertions
TypeScript
86
star
44

apollo-federation-subgraph-compatibility

A repo to test subgraph libraries compatibility with the Apollo Federation Specification
TypeScript
73
star
45

starwars-server

JavaScript
72
star
46

blog

๐Ÿ“ Blog website built with Wordpress and Gatsby
JavaScript
68
star
47

iOSTutorial

The tutorial application for the Apollo iOS SDK
Swift
65
star
48

odyssey-lift-off-part1

JavaScript
61
star
49

federation-jvm-spring-example

Apollo Federation JVM example implementation using Spring for GraphQL
Java
56
star
50

vscode-graphql

Apollo GraphQL VS Code extension
TypeScript
49
star
51

apollo-kotlin-tutorial

The code for the Apollo Kotlin Tutorial
Kotlin
49
star
52

docs-examples

Example code supporting the Apollo docs
TypeScript
46
star
53

apollo-kotlin-2-tutorial

The code for the Apollo Android Tutorial
Kotlin
38
star
54

iOSCodegenTemplate

A template for the code you need to set up to get Swift Scripting up and running.
Swift
38
star
55

docs

๐Ÿ“š Apollo's docs framework
MDX
36
star
56

apollo-workbench-vscode

Apollo Workbench is a design tool that facilitates planning changes to your supergraph. It enables you to understand the overall composition and execution of any given query at design time.
TypeScript
36
star
57

react-apollo-error-template

Apollo Client issue reproduction.
JavaScript
33
star
58

apollo-utils

Monorepo of common utilities related to Apollo and GraphQL
TypeScript
32
star
59

federation-rs

Contains source code for Apollo Federation's Rust<--> JavaScript interop
Rust
32
star
60

federation-migration-example

๐Ÿš€Example app migrated from schema stitching to Apollo federation
JavaScript
32
star
61

odyssey-lift-off-part5-server

Odyssey Lift-off V - Server - Course Companion App
JavaScript
31
star
62

embeddable-explorer

TypeScript
31
star
63

odyssey-lift-off-part5-client

Odyssey Lift-off V - Client - Course Companion App
JavaScript
28
star
64

datasource-rest

A caching data source for REST APIs
TypeScript
28
star
65

GraphiQL-Subscriptions-Fetcher

GraphiQL's fetcher that supports GraphQL-Subscriptions with the `subscriptions-transport-ws` package
TypeScript
28
star
66

supergraph-demo-k8s-graph-ops

Archived: GitOps config repo for an Apollo GraphQL federated graph with a supergraph router and subgraph services deployed to Kubernetes.
Shell
27
star
67

odyssey-lift-off-part2

Odyssey Lift-off Part 2 Course Companion App
JavaScript
25
star
68

apollo-graphql-stream-scenes

This is used for hosting streaming scenes for OBS - for Apollo GraphQL stream
JavaScript
20
star
69

spacex

A re-creation of https://github.com/SpaceXLand/api
TypeScript
18
star
70

odyssey-voyage-I

JavaScript
14
star
71

federation-hotchocolate

HotChocolate support for Apollo Federation
C#
14
star
72

typescript-repo-template

A template for TypeScript projects with pre-configured tooling
TypeScript
14
star
73

odyssey-lift-off-part3

Odyssey Lift-off Part 3 Course Companion App
JavaScript
14
star
74

federation-next

Home of the rust rewrite of federation core (composition & query planning)
Rust
14
star
75

apollo-ios-dev

Apollo iOS Development Repo
Swift
14
star
76

odyssey-lift-off-part4

Odyssey Lift-off Part 4 Course Companion App
JavaScript
13
star
77

subgraph-template-typescript-apollo-server

A Typescript template for Apollo Server as a subgraph using Apollo Federation
TypeScript
13
star
78

community

Apollo community guidelines
JavaScript
13
star
79

design-principles

Where we are defining and collaborating on our Apollo internal design principles (individually and collaboratively). This is a public repo, but intended only for use by Apollo employees.
13
star
80

core-schema-js

Typescript library for processing core schemas
TypeScript
12
star
81

apollo-client-swift-playground

Swift
11
star
82

test-span

Rust
11
star
83

subgraph-template-typescript-apollo-server-boilerplate

A template for a minimal setup Apollo Server 4.x using TypeScript
TypeScript
11
star
84

apollo-ios-pagination

Swift
10
star
85

specs

Apollo Library of Technical Specifications
CSS
10
star
86

apollo-midnight

A VS Code color theme based on Apollo Studio Explorer color palette.
9
star
87

devhub

๐Ÿ”ญ Explore all the latest resources for building apps with Apollo
JavaScript
8
star
88

serde_json_bytes

a JSON Value object with strings backed by Bytes, parsed by serde_json
Rust
8
star
89

hack-the-supergraph

JavaScript
8
star
90

next-apollo-example

Template for creating Apollo Client + Next.js reproductions
JavaScript
8
star
91

router-biscuit-plugin

โš ๏ธexperimentalโš ๏ธ plugin for the router using Biscuit tokens for authorization
Rust
7
star
92

apollo-ios-codegen

Apollo iOS Code Generation
Swift
7
star
93

odyssey-lift-off-lab

Odyssey Lift-off Lab starter repo
JavaScript
7
star
94

zen-observable-ts

Thin wrapper around zen-observable and @types/zen-observable, to support ESM exports
JavaScript
7
star
95

router-template

A general purpose self-hosted Apollo Router template connected to GraphOS
Dockerfile
7
star
96

introspector-gadget

GraphQL introspection utilities
Rust
6
star
97

client-router-e2e-tests

Apollo Client โ†”๏ธ Router E2E Test Suite
JavaScript
6
star
98

subgraph-template-rust-async-graphql

A boilerplate template project for building a subgraph with async-graphql
Rust
6
star
99

odyssey-voyage-II-server

The course companion app to Odyssey's Federation series.
JavaScript
5
star
100

apollo-server-starter

A starter/demonstration repo of Apollo Server
JavaScript
5
star