graphql icon indicating copy to clipboard operation
graphql copied to clipboard

UnhandledPromiseRejection Error by using nestjs/graphql with fastify

Open Yehonal opened this issue 5 years ago • 2 comments

I'm submitting a...


[ ] 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

I'm using the following libraries:

  • @nestjs/graphql 7.10.6
  • "@nestjs/platform-fastify": "^7.6.15"
  • "fastify": "^3.15.1"
  • "@apollo/federation": "^0.25.0",
  • "apollo-server-fastify": "^3.0.0-lambda.0" -> this version is required because the stable 2.x doesn't support fastify 3 (required by nestjs) as stated in the documentation

However, this combination causes the following error:

(node:11763) UnhandledPromiseRejectionWarning: Error: You must `await server.start()` before calling `server.createHandler()`
    at ApolloServer.assertStarted (/opt/application/node_modules/apollo-server-fastify/node_modules/apollo-server-core/src/ApolloServer.ts:486:13)
    at ApolloServer.createHandler (/opt/application/node_modules/apollo-server-fastify/src/ApolloServer.ts:45:10)
    at GraphQLFederationModule.<anonymous> (/opt/application/node_modules/@nestjs/graphql/dist/federation/graphql-federation.module.js:154:39)
    at Generator.next (<anonymous>)
    at /opt/application/node_modules/@nestjs/graphql/node_modules/tslib/tslib.js:117:75
    at new Promise (<anonymous>)
    at Object.__awaiter (/opt/application/node_modules/@nestjs/graphql/node_modules/tslib/tslib.js:113:16)
    at GraphQLFederationModule.registerFastify (/opt/application/node_modules/@nestjs/graphql/dist/federation/graphql-federation.module.js:144:20)
    at GraphQLFederationModule.<anonymous> (/opt/application/node_modules/@nestjs/graphql/dist/federation/graphql-federation.module.js:117:20)

The issue is related to this line:

https://github.com/nestjs/graphql/blob/b2651ca92d4236965a0d869517319c46056ed5da/lib/federation/graphql-federation.module.ts#L256

and could be fixed by adding await apolloServer.start()

May I open a PR for it or is this not the way to go?

Expected behavior

Should not throw that error

Minimal reproduction of the problem with instructions

I cannot provide it at the moment

What is the motivation / use case for changing the behavior?

Environment

  • @nestjs/graphql 7.10.6
  • "@nestjs/platform-fastify": "^7.6.15"
  • "fastify": "^3.15.1"
  • "@apollo/federation": "^0.25.0",
  • "apollo-server-fastify": "^3.0.0-lambda.0" -> this version is required because the stable 2.x doesn't support fastify 3 (required by nestjs) as stated in the documentation

Others:

Yehonal avatar May 15 '21 07:05 Yehonal

I'm facing the same issue on a new mono repo I setup with nest js I think the change needs to be made at another file too I tested that change locally and it works I'll add a PR for that file fix shortly

maazkabir avatar May 20 '21 13:05 maazkabir

Let's track this here https://github.com/nestjs/graphql/pull/1544

kamilmysliwiec avatar Jun 18 '21 11:06 kamilmysliwiec