Fastify registration omits apolloServer.start(), which throws an error at apolloServer.createHandler()
See original GitHub issueI’m submitting a…
[X] Regression
[X] Bug report
[ ] Feature request
[ ] Documentation issue or request
[ ] Support request => Please do not submit support request here, instead post your question on Stack Overflow.
Current behavior
When attempting to start an application that uses @nestjs/platform-fastify@7.6.17
and @nestjs/graphql@7.10.6
, the Apollo Server throws the following error that prevents the application from starting:
[Path]/node_modules/apollo-server-core/src/ApolloServer.ts:486
throw new Error(
^
Error: You must `await server.start()` before calling `server.createHandler()`
at ApolloServer.assertStarted ([Path]/node_modules/apollo-server-core/src/ApolloServer.ts:486:13)
at ApolloServer.createHandler ([Path]/node_modules/apollo-server-fastify/src/ApolloServer.ts:45:10)
at GraphQLModule.<anonymous> ([Path]/node_modules/@nestjs/graphql/dist/graphql.module.js:150:45)
at Generator.next (<anonymous>)
at [Path]/node_modules/tslib/tslib.js:117:75
at new Promise (<anonymous>)
at Object.__awaiter ([Path]/node_modules/tslib/tslib.js:113:16)
at GraphQLModule.registerFastify ([Path]/node_modules/@nestjs/graphql/dist/graphql.module.js:143:24)
at GraphQLModule.<anonymous> ([Path]/node_modules/@nestjs/graphql/dist/graphql.module.js:118:28)
at Generator.next (<anonymous>)
Expected behavior
The application should start without an error and was previously working.
Minimal reproduction of the problem with instructions
Adding await apolloServer.start()
to line 228 of lib/graphql.module.ts
seems like it will fix the issue, but I’m not sure if that’s the appropriate place to put it from an architecture perspective. I did this via yarn patch
and the application starts successfully. My repo and patch are available on the dev-nx
branch at troncali/nest-vue.
git clone --depth=1 -b dev-nx https://github.com/troncali/nest-vue
cd nest-vue
yarn install
- Patch is located at ./.yarn/patches/@nestjs/graphql.patch
- Working on a template repository, so some minimal setup is needed
–
cp .env-template .env
–echo "username" > ./src/docker/secrets/DB_USERNAME
–echo "password" > ./src/docker/secrets/DB_PASSWORD
yarn nx serve
- to test that it’s working with the patch; no error in consolehttp://localhost:3001/v1
shows “Hello World!”- Stop the application
yarn add @nestjs/graphql
to revert to the unpatched versionyarn nx serve
- to show the unpatched error
Environment
Nest version: 7.6.17
For Tooling issues:
- Node version: 16.1.0
- Platform: Mac
Others:
- Package Manager: Yarn 2, with PnP enabled
- Build Tools: @nrwl/nx
Issue Analytics
- State:
- Created 2 years ago
- Reactions:2
- Comments:7 (1 by maintainers)
Top Results From Across the Web
API Reference: ApolloServer - Apollo GraphQL Docs
This article documents the ApolloServer class from the @apollo/server package. ... The signal handler is installed after start() returns successfully.
Read more >apollo-server-fastify - file upload error · Issue #3139 - GitHub
js:146 throw new Error('This implementation of ApolloServer does not support file uploads because the environment cannot accept multi-part forms ...
Read more >apollo-server-fastify | Yarn - Package Manager
This is the Fastify integration of GraphQL Server. Apollo Server is a community-maintained open-source GraphQL server that works with many Node.js HTTP server ......
Read more >javascript - Error: You must `await server.start()` before calling ...
This works for me, copied from the guys at prisma. import Cors from "micro-cors"; import schema from "graphql/schema"; import { ApolloServer } ...
Read more >Errors - Fastify
Fastify tries to catch as many uncaught errors as it can without hindering performance. This includes: synchronous routes, e.g. app.get('/', () => {...
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
This should be fixed in v7.11.0
It happened to me as well due to
apollo-server-fastify@^3.0.0-preview.0
a temporary fix was for us to add those lignes topackage.json
forcing the resolution of apollo-server packages to the working aplha.3 version instead of the recently published preview.0 one.