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:
- Domain_1_API <--
- Domain_1_API2 <--
- Domain_2_API
- Domain_3_API
example:
- Domain_1_API Schema:
type Company {
id: ID
name: String
address: String
- Domain_1_API2 Schema:
type Company {
id: ID
name: String
address: String
- SuperGraph Result:
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.