diff --git a/apps/gateway/src/app/app.module.ts b/apps/gateway/src/app/app.module.ts index 5e3f967..4eb32f7 100644 --- a/apps/gateway/src/app/app.module.ts +++ b/apps/gateway/src/app/app.module.ts @@ -1,4 +1,4 @@ -import { IntrospectAndCompose } from '@apollo/gateway'; +import { IntrospectAndCompose, RemoteGraphQLDataSource } from '@apollo/gateway'; import { gatewayConfig, userAppConfig } from '@shared/config'; import { ApolloGatewayDriver, ApolloGatewayDriverConfig } from '@nestjs/apollo'; import { Module } from '@nestjs/common'; @@ -31,6 +31,20 @@ import { AppService } from './app.service'; }, ], }), + buildService: ({ url = '' }) => { + return new RemoteGraphQLDataSource({ + url, + willSendRequest({ request, context }) { + // rebuild header + if (Object.keys(context).length > 0 && request.http) { + request.http.headers.set( + 'Authorization', + context['req']['headers']['authorization'], + ); + } + }, + }); + }, }, }; }, diff --git a/apps/users/src/app/app.module.ts b/apps/users/src/app/app.module.ts index 76ec9ed..fde11ff 100644 --- a/apps/users/src/app/app.module.ts +++ b/apps/users/src/app/app.module.ts @@ -37,7 +37,9 @@ import { AppService } from './app.service'; playground: process.env['NODE_ENV'] !== 'production', sortSchema: true, plugins: [ApolloServerPluginInlineTrace()], - context: ({ req }: { req: Request }) => ({ req }), // Make sure request is passed to the context + context: ({ req }: { req: Request }) => { + return { headers: req?.headers }; + }, }), UsersModule, AuthModule,