I have a series of microservices on GCP Cloud Run that are each hosting a federated Apollo GraphQL service. I then have one last container which is acting as a federated GraphQL gateway for the rest of the services.
This works fine when public access is enabled on the containers but I cannot get the gateway server to authenticate against the other two services.
I have tried using the Apollo RemoteGraphQLDataSource and implementing the willSendRequest method to set the neccessary headers.
I have also tried adding the cloud run invoker role to the service role that the gateway runs as.
const servicex = new RemoteGraphQLDataSource({
url: serviceurl,
willSendRequest({ request, context }) {
request.http.headers.set(
"Authorization",
"Bearer ${TOKEN}"
);
}
});
const gateway = new ApolloGateway({
serviceList: [
servicex
]
});
const { schema, executor } = await gateway.load();
const server = new ApolloServer({ schema, executor })
I expect the gateway server to be able to authenticate against the other microservices.