Reputation: 646
I've got a problem in my NestJs app. Project was running perfect until yesterday.
Apparently my node.js upgraded from 14.16.1
to 14.17.0
. So I changed this version number in my engines
object, in package.json
. I executed yarn install
again, to make sure everything was there, and tried yarn start:dev
(which translates to nest start --watch
).
But my app isn't running =( It seems like there's something wrong regarding my apollo-server-fastify:
UnhandledPromiseRejectionWarning: Error: You must `await server.start()` before calling `server.createHandler()`
at ApolloServer.assertStarted (/app/node_modules/apollo-server-fastify/node_modules/apollo-server-core/dist/ApolloServer.js:213:19)
at ApolloServer.createHandler (/app/node_modules/apollo-server-fastify/dist/ApolloServer.js:22:14)
at GraphQLModule.<anonymous> (/app/node_modules/@nestjs/graphql/dist/graphql.module.js:150:45)
at Generator.next (<anonymous>)
at /app/node_modules/tslib/tslib.js:117:75
at new Promise (<anonymous>)
at Object.__awaiter (/app/node_modules/tslib/tslib.js:113:16)
at GraphQLModule.registerFastify (/app/node_modules/@nestjs/graphql/dist/graphql.module.js:143:24)
at GraphQLModule.<anonymous> (/app/node_modules/@nestjs/graphql/dist/graphql.module.js:118:28)
at Generator.next (<anonymous>)
(Use `node --trace-warnings ...` to show where the warning was created)
(node:323734) UnhandledPromiseRejectionWarning: Unhandled promise rejection. This error originated either by throwing inside of an async function without a catch block, or by rejecting a promise which was not handled with .catch(). To terminate the node process on unhandled promise rejection, use the CLI flag `--unhandled-rejections=strict` (see https://nodejs.org/api/cli.html#cli_unhandled_rejections_mode). (rejection id: 2)
(node:323734) [DEP0018] DeprecationWarning: Unhandled promise rejections are deprecated. In the future, promise rejections that are not handled will terminate the Node.js process with a non-zero exit code.
I know apollo and fastify aren't the best friends right now, I've faced an issue in the past where I needed to downgrade some package, I guess. Does anyone knows how to debug/fix this? I feel clueless. Current package versions:
"@nestjs/common": "^7.0.0",
"@nestjs/graphql": "^7.7.0",
"@nestjs/platform-fastify": "^7.6.4",
"apollo-server-fastify": "^3.0.0-alpha.3",
"graphql": "^15.5.0",
(I've also tried to upgrade apollo-server-fastify to alpha 4, but the problem persists).
Upvotes: 1
Views: 2584
Reputation: 46
A temporary fix, until this issue is addressed by maintainers, is to copy this patch file into your repository, then modify your package.json to use the following:
"@nestjs/graphql": "patch:@nestjs/[email protected]#[YOUR/LOCAL/PATH]/graphql.patch"
I ran into this same issue with my project. I'm not sure about the origin, but I did see that apollo-server-fastify
was updated to 3.0.0-lambda.0 about 5 days ago and to 3.0.0-preview.0 a few hours ago.
I tracked the possible fix down to the registerFastify
method in @nestjs/graphql
. The solution, I believe, is to call await apolloServer.start()
on line 228 in lib/graphql.module.ts
before the Apollo Server's createHandler()
method is called. I opened an issue on the repository with more details, which you can follow until resolved.
I implemented the fix in the template repository I'm working on with yarn patch @nestjs/graphql
. The repository is available on the dev-nx
branch at troncali/nest-vue. The patch is located in ./.yarn/patches/@nestjs/graphql.patch
.
Upvotes: 3