diegoolavarriau
diegoolavarriau

Reputation: 106

Can I force an Apollo Supergraph to point to specific Subgraph?

I'm building a GraphQL Federated project with Apollo Router and multiple endpoints via Supergraph arquitecture for a centralized API, based on the Apollo Docs, and using Rover for the composition: https://www.apollographql.com/docs/federation/quickstart/local-composition

The schema is build using GraphQLObjectType from graphql and buildSubgraphSchema from @apollo/subgraph

My current problem is that inside the project I have two instances of the same API, with the exact same code but with different environment variables due to internal necessities:

example:

type Company {
  id: ID
  name: String
  address: String
type Company {
  id: ID
  name: String
  address: String
type Company
  @join__type(graph: DOMAIN_1_API)
  @join__type(graph: DOMAIN_1_API2)
{
  id: ID
  name: String
  address: String

This generates a merged SuperGraph where all requests go directly to Domain_1_API.

Is it possible to build a Supergraph that recognizes two equal subgraph schemas as separate schemas, AND/OR intercept the requests sent to the Supergraph and, based on the request's headers, point specifically to Domain_1_API or Domain_1_API2?

I tries using a Rhai plugin based on the docs: https://www.apollographql.com/docs/router/customizations/rhai/, but I don't know Rhai.

Upvotes: 0

Views: 564

Answers (1)

diegoolavarriau
diegoolavarriau

Reputation: 106

Is not possible. What I ended up doing is setting up a second Federation that composes its Supergraph using Domain_1_API2 as a subgraph, while the first Federation uses Domain_1_API.

Upvotes: 0

Related Questions