I'm using apollo federation + typescript to implement a graphql server with subgraphs. Currently I'm working on the gateway, and I want to apply middleware to it, which will perform a token exchange functionality. The problem is that I can't get my gateway running. Here is the test code.
async function startGateway(port: number) {
const app = express();
const httpServer = http.createServer(app);
app.use(cors({
origin: '*',
credentials: true,
exposedHeaders: ['token']
}));
app.use(jwtMiddleware)
const gateway = new ApolloGateway({
supergraphSdl: new IntrospectAndCompose({
subgraphs: [
{ name: 'subgraph', url: 'http://localhost:8081'}
]
})
});
const server = new ApolloServer({
gateway,
plugins: [ ApolloServerPluginDrainHttpServer({ httpServer })]
});
await server.start();
server.applyMiddleware({ app });
return new Promise((resolve, reject) => {
httpServer.listen(port)
.once('listening', resolve)
.once('error', reject);
})
}
when I run the code I get no errors or warnings, but I cannot connect to my gateway via graphql client. What is the problem and how can It be fixed? Thank you in advance.
If you want to share tokens between the gateway and the subgraph,
you can do it in the following way.
Document url