graphql / express-graphql

Create a GraphQL HTTP server with Express.
MIT License
6.34k stars 538 forks source link

Why isn't the callback of app.listen() called when using express-graphql middleware? #783

Closed KerimG closed 2 years ago

KerimG commented 2 years ago

I have a very simple graphql setup that looks something like this:

const express = require("express");
const app = express();

//...

app.use(
  '/graphql',
  graphqlHTTP({
    schema: makeExecutableSchema({
      typeDefs,
      resolvers,
    }),
    graphiql: true,
  })
);

app.listen(8165, () => {
  'Running a GraphQL API server at :8165/graphql';
});

but for some reason the callback isn't being called. I figure this has something to do with the middleware.

harsh3977 commented 2 years ago

Try
app.listen(8165, () => { 'Running a GraphQL API server at :8165/graphql'; });

KerimG commented 2 years ago

@harsh3977 thanks for the info. That's the first thing I tired, since it's the default express way, but it looks like express-graphql seems to somehow supress it

harsh3977 commented 2 years ago

Sorry My bad. Try async before the function app.listen(8165,async () => { 'Running a GraphQL API server at :8165/graphql'; });

KerimG commented 2 years ago

@harsh3977

Thanks a ton. That seems to have worked. I don't know why the callback has to be async but that seems to have fixed it.