I am having trouble parsing the header retrieved from graphql’s context, what I would like to do is to basically forward the headers from the request into the response
My gateway:
GraphQLModule.forRootAsync<ApolloGatewayDriverConfig>({
driver: ApolloGatewayDriver,
inject: [ConfigService],
useFactory: async(configService: ConfigService) => ({
server: {
introspection: true,
playground: true,
cache: 'bounded'
},
gateway: {
buildService: (url) => new CustomDataSource(url),
supergraphSdl: ...
}
})
})
My CustomDataSource which should forward headers:
export class CustomDataSource extends RemoteGraphQLDataSource {
constructor(config: any) {
super(config);
this.fetcher = fetcher.defaults({
maxSockets: Infinity,
strictSSL: false,
retry: false,
})
}
willSendRequest({context, request }) {
console.log('context', context.req); // <---- here
request.http?.headers.set('authorization', context.req.authorization);
}
}
My issue now is that the context.req.headers do not exist when it should and logging it out gives me headers in a different name as kHeaders instead which I am unsure of how to parse this.
context.req:
{
...,
...,
[Symbol(kHeaders)]: {
authorization: 'abcdefg'
}
}
I tried something like context.req[‘Symbol(kHeaders)’] which returns me cannot read properties, would like to know why is my headers returned this way and how do I parse this
4
The headers should be in
context
object. Have you tried to logcontext.authorization
?Jan 20 at 7:55
yeee, it's weird the whole section for the normal header is gone, im only left with this symbol and rawheader, im using rawheader as a workaround now
Jan 20 at 8:51
Encountering the same problem after upgrading to node v16/v18. In node v14 the header was available in the context but with the update it isn't. Did you solve this?
Mar 16 at 9:03
i believed i used the rawHeaders as a work around and wrote a util to parse it into object format, then later app was refactored such that the stuff i needed are all in the authorization token which I got from context.authorization
Mar 16 at 9:22