I have found a workaround to avoid this bug:
consumer.apply(middleware).forRoutes worked properly when I specified exclude option in app.setGlobalPrefix and add "graphql".
// main.ts
async function bootstrap() {
const app = await NestFactory.create(AppModule);
app.setGlobalPrefix('prefix', {
// works properly with the following option
exclude: ['graphql']
});
await app.listen(3000);
}
(I have also noticed it in my minimal repro as a comment.)
Is there an existing issue for this?
Current behavior
Using
app.setGlobalPrefix
andGraphQLModule.forRoot
, I cannot specify/graphql
endpoint in the argument ofconsumer.apply(middleware).forRoutes
.Minimum reproduction code
https://codesandbox.io/p/devbox/nestjs-graphql-middleware-issue-8d6qfr
Steps to reproduce
npm start:dev
/graphql
endpointExpected behavior
The middleware should be called when I access
/graphql
endpoint. In my minimum example,apply
should be shown in terminal outputs.Package version
12.1.1
Graphql version
graphql
: 16.8.1@apollo/server
: 4.10.1@nestjs/apollo
: 12.1.0NestJS version
10.3.3
Node.js version
20.11.0
In which operating systems have you tested?
Other
I have found a workaround to avoid this bug:
consumer.apply(middleware).forRoutes
worked properly when I specifiedexclude
option inapp.setGlobalPrefix
and add "graphql".(I have also noticed it in my minimal repro as a comment.)