apollo graphql generating schema from subgraph and running the instance locallly

As supergraph consist of subgraphs, we need to generate a schema so router would know what query/mutation requests should be directed to which subgraph. Once you have the schema out, you run a different command to host this supergraph.

1. Generate Schema

You can use the following command to generate supergraph schema

The yaml file below called supergraph.yaml contains information about your subgraph and they have to be running before you can do this schema discovery. 

Then it outputs supergraph.graphql. 

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

federation_version: =2.5.0

subgraphs:
  review-service:
    routing_url: http://localhost:4002
    schema:
      subgraph_url: http://localhost:4002
  location-service:
    routing_url: http://localhost:4001
    schema:
      subgraph_url: http://localhost:4001

And the supergraph.graphql looks something like this: 


2. Hosting the router instance 

router --config router.yaml --supergraph supergraph.graphql

Now, you will have the router up and running and able to serve incoming request. 




Comments

Popular posts from this blog

The specified initialization vector (IV) does not match the block size for this algorithm