Closed KMoscIszko closed 1 year ago
This is probably a better question for https://github.com/apollographql/federation
as this is not related to the apollo-federation-ruby gem.
Apollo also has a support article detailing how it should work - https://support.apollographql.com/hc/en-us/articles/6135650062355-How-do-I-forward-headers-from-gateway-to-subgraph-.
You can try something like this perhaps.
class AuthenticatedDataSource extends RemoteGraphQLDataSource {
willSendRequest({ request, context }) { // this context is whatever you returned in constructing the ApolloServer
request.http.headers.set("Authorization", context.authorizationHeader);
}
}
const gateway = new ApolloGateway({
supergraphSdl,
buildService({ name, url }) {
return new AuthenticatedDataSource({ url });
},
});
const server = new ApolloServer({
gateway,
plugins,
context: ({ req }) => {
return {
serverRequest: req,
authorizationHeader: req.headers.authorization
};
}
});
@sethc2 Yeah, I got it, that's line req.headers.authorization I needed, I came to this conclusion a moment before you posted, yet thanks :D
Hi. That's my blocker while developing backend. Passing headers from supergraph to subgraphs. Through logger I can observe that the node gateway is receiving headers but once I debug Rails graphql controller, It's not getting anything. graphql_controller.rb
gateway.ts
The headers are passed in "rawHeaders":["Authorization","T9J5mDf9ddZIYQVpao/2vbPXFxyK26EliA2G4gp1BEbL9xY5UE/7ElTMjeg9xNEdJFx82cy--lEBj3HbqBbPR77D0--qyIdK/N3rIN2w8SzBQwEMg="