Skip to main content

Local Composition

You may want to generate a federated schema for local development without making any changes to your Configured Schema in the Inigo cloud. Inigo offers two ways to do this:

  1. Use inigo compose with a local Gateway configuration
  2. Use inigo compose with a LocalCompose configuration

In either case, the entire federated schema definition will be printed out, and if there are errors, the errors will be printed out instead of a federated schema.

Local Gateway Approach

By using a Gateway configuration that you only use for local development, you can easily reference all of your local supergraph schema files and compose them together into a federated graph as shown in example 2.

kind: Gateway
name: apollo-gateway-fed-2-demo
label: dev
spec:
composition: ApolloFederation_v2
services:
- name: accounts
url: "http://localhost:4001/graphql"
schema_files:
- ../services/accounts/schema.graphql
- name: reviews
url: "http://localhost:4002/graphql"
schema_files:
- ../services/reviews/schema.graphql
- name: products
url: "http://localhost:4003/graphql"
schema_files:
- ../services/products/schema.graphql
- name: inventory
url: "http://localhost:4004/graphql"
schema_files:
- ../services/inventory/schema.graphql

Example 1. A Local Gateway configuration referencing local subgraph schema files.

Creating a composed schema from a local Gateway configuration file is done using the inigo compose command as such:

inigo compose local-gateway.yaml > supergraph.graphql

LocalCompose Approach

If you need more flexibility on how you locally compose your subgraphs, LocalCompose makes this possible. For example, you may not have a copy on your local machine of all of the peer subgraphs that you would need to compose using a Gateway configuration.

Inside the LocalCompose configuration, you can supply the federated graph to use as a base and the subgraphs to override. For each subgraph override, you can specify where to get the schema for that subgraph. Schema source can come from a local schema file, fetched via a URL endpoint, or fetched from the Inigo cloud.

IMPORTANT: In order to run inigo compose with the LocalCompose, a composed schema must be available in your Schema Repository.

Note: LocalCompose does not have side effects in the Inigo cloud when inigo compose is run

In Example 2, each subgraph fetches his or her schema using a different source. New subgraphs can also be added by providing a new subgraph name that is not currently part of the federated schema.

kind: LocalCompose
name: federated_service_name (1)
spec:
services:
- name: service_one (2)
url: http://service_one:8000/query
source:
schema_files:
- ../graphql/service_one.graphql

- name: service_two (3)
url: http://service_two:8000/query
source:
ref: service_two:dev

- name: service_three (4)
url: http://service_three:8000/query
source:
sdl_url: http://service_three:8000/query
sdl_headers:
- name: Authorization
value: Bearer <token>

- name: service_new (5)
url: http://service_new:8000/query
source:
schema_files:
- ../graphql/new.graphql

Example 2. LocalCompose configuration overriding subgraph configurations.

The following list references the numbered labels in Example 2 and provides further explanation:

  1. The federated_service_name Gateway name that is used for the federated schema, and the federated schema should already be published using inigo publish
  2. Override the service_one subgraph with a local schema file.
  3. Override the service_two subgraph with a service_two:dev Subgraph
  4. Override the service_three subgraph with a URL referencing an SDL
  5. Add a new service_new to be locally composed with the others

Creating a composed schema from a LocalCompose configuration file is done using the inigo compose command as such:

inigo compose local-compose.yaml > supergraph.graphql