Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

UnhandledPromiseRejectionWarning: Error: You must `await server.start()` before calling `server.applyMiddleware()` at ApolloServer

I am trying to start my nestJs server and It keeps giving me this error:

UnhandledPromiseRejectionWarning: Error: You must await server.start() before calling server.applyMiddleware() at ApolloServer

I'm not even sure where to debug from as I am still very new at NestJs and GraphQL.

like image 660
Boladek Avatar asked Jul 12 '21 22:07

Boladek


2 Answers

This is a known bug with an open issue and a merged PR to fix it. For now, you can downgrade to apollo-server-express@^2

like image 146
Jay McDoniel Avatar answered Oct 14 '22 08:10

Jay McDoniel


I faced this issue when upgrading Ben Awad's Graphql-Next-Typeorm[...] stack, simply adding an await to server start fixed the warnings

const apolloServer = new ApolloServer({     introspection: true,     schema: await buildSchema({       resolvers: [__dirname + '/resolvers/**/*.js'],       validate: false     }),     context: ({ req, res }) => ({       req,       res,       redis: redisClient     }),     formatError   });   // added this line   await apolloServer.start();    apolloServer.applyMiddleware({     app,     cors: false   }); 
like image 36
eliastouil Avatar answered Oct 14 '22 08:10

eliastouil