ApolloGateway and ApolloServer with Schema in one Instance


I have two external services with a GraphQL schema (containing a schema.graphql each with some endpoints), and one gateway service so far which combines both ext. services. Now I want to move some schema endpoints from one external service into the gateway service.

Therefore, I tried to create an instance of ApolloGateway and pass it to the ApolloServer instance. Within the ApolloServer I call the constructor using “gateway: …”, and “schema: …” together and got the following error message:
Cannot define both gateway and any of: modules, schema, typeDefs, or resolvers

So my question is:
How can I use ApolloGateway and ApolloServer with a schema in one instance together?

Everything is written in NodeJS / Typescript.

Hope someone can help. Thank you in advance and kind regards!

That’s not how it works. The Gateway is a first layer that makes a query plan of how to fulfill your operation by talking to subgraphs; you can’t also put direct resolvers in the same ApolloServer object.

If you’d like a single Node process to be both a Gateway and a subgraph you can create two ApolloServer objects in one process, though this isn’t the recommended architecture.

1 Like

Oh. Ok, Thank you!

I have just found a solution for my purpose: