Graphql-yoga: Is there a way to close server?

Created on 17 Jul 2018  路  6Comments  路  Source: dotansimha/graphql-yoga

I want to listen for file changes and automatically restart the service when changes occur. But I did not find a way to close the server.

statustale

Most helpful comment

There are a few problems with the start method usage as shown above:

  1. It's not documented in the README: the start method is said to return Promise<void>.
  2. The actual definition of the start method in the code gives the return type as Promise<HttpServer | HttpsServer>.

So, an undocumented, but workable way to obtain the HTTP server object would be:

const server = new GraphQLServer({ typeDefs, resolvers })
server.start()
  .then(httpServer => {
    // Do stuff
    httpServer.close()
  });

All 6 comments

Hej @PanJiaChen 馃檶馃徎I remember a discussion on this a while ago... https://github.com/prismagraphql/graphql-yoga/issues/100

Essentially...

const server = new GraphQLServer({ typeDefs, resolvers })
const httpServer = server.start()
httpServer.close()

I have read this issue before, but I found that it does not work.

There are a few problems with the start method usage as shown above:

  1. It's not documented in the README: the start method is said to return Promise<void>.
  2. The actual definition of the start method in the code gives the return type as Promise<HttpServer | HttpsServer>.

So, an undocumented, but workable way to obtain the HTTP server object would be:

const server = new GraphQLServer({ typeDefs, resolvers })
server.start()
  .then(httpServer => {
    // Do stuff
    httpServer.close()
  });

Due to inactivity of this issue we have marked it stale. It will be closed if no further activity occurs.

Due to inactivity of this issue we have marked it stale. It will be closed if no further activity occurs.

Hey :wave:, It seems like this issue has been inactive for some time. In need for maintaining clear overview of the issues concerning the latest version of graphql-yoga we'll close it.
Feel free to reopen it at any time if you believe we should futher discuss its content. :slightly_smiling_face:

Was this page helpful?
0 / 5 - 0 ratings