question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Fastify registration omits apolloServer.start(), which throws an error at apolloServer.createHandler()

See original GitHub issue

I’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 neededcp .env-template .envecho "username" > ./src/docker/secrets/DB_USERNAMEecho "password" > ./src/docker/secrets/DB_PASSWORD
  • yarn nx serve - to test that it’s working with the patch; no error in console
  • http://localhost:3001/v1 shows “Hello World!”
  • Stop the application
  • yarn add @nestjs/graphql to revert to the unpatched version
  • yarn 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:closed
  • Created 2 years ago
  • Reactions:2
  • Comments:7 (1 by maintainers)

github_iconTop GitHub Comments

3reactions
kamilmysliwieccommented, Jun 18, 2021

This should be fixed in v7.11.0

2reactions
p-jcommented, Jun 1, 2021

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 to package.json

"resolutions": {
    "apollo-server-env": "^2 || 3.0.0-alpha.3",
    "apollo-server-fastify": "^2 || 3.0.0-alpha.3",
    "apollo-server-core": "^2 || 3.0.0-alpha.3"
  },

forcing the resolution of apollo-server packages to the working aplha.3 version instead of the recently published preview.0 one.

Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found