Hi Community
I’m facing an issue and I read all the resources . I want to pass token which i’m receiving in context. to http://host.docker.internal:3001/user-management subgraph. but while adding console log i’m getting empty object. console.log("willSendRequest:context: ", context)
, while doing test i have found that AuthenticatedDataSource
invoke before
context: async ({ event }) => { return { user } }
Can someone help me how I can pass token value from context to AuthenticatedDataSource
willSendRequest
class AuthenticatedDataSource extends RemoteGraphQLDataSource {
async willSendRequest({request, context, kind }) {
console.log('willSendRequest:Context:', kind); // Ensure context is logged for debugging
console.log("willSendRequest:context: ", context)
console.log("willSendRequest:request: ", request)
// console.log(request.http.headers.set("Authorization", "Bearer eyJ0eXAiOiJKV1QiLCJhbGciOiJSUzI1NiJ9.eyJzdWIiOiIxMjM0NTY3ODkwIiwibmFtZSI6IkpvaGFuIjoiMjMwfQ.SflKxwRJSMeKKF2QT4fwpMeJf36POk6yJV_adQssw5c"))
console.log("willSendRequest:end")
}
}
const gateway = new ApolloGateway({
supergraphSdl: new IntrospectAndCompose({
subgraphs: [
{ name: "users", url: `http://host.docker.internal:3001/user-management` },
],
}),
buildService: ({name, url}) => {
return new AuthenticatedDataSource({ url });
}
})
const server = new ApolloServer({
gateway,
subscriptions: false,
introspection: true,
});
export const handler = startServerAndCreateLambdaHandler(
server,
handlers.createAPIGatewayProxyEventV2RequestHandler(), {
context: async ({ event }) => {
return { user }
}
}`