Graphql-yoga: How to set the server timeout

Created on 24 Jun 2020  路  3Comments  路  Source: dotansimha/graphql-yoga

Hello,

I am using graphql-yoga to run my graphql service.
What is the default timeout to graphql-yoga server?
How can I set the maximum timeout on the server level?

Can someone help me here? Following is the code I am using.

`
const { GraphQLServer } = require('graphql-yoga');

const server = new GraphQLServer({
schema,
context: request => ({ ...request }),
middleware: [loggingMiddleware]
})

const options = {
port: 8050,
endpoint: xyzService
}

server.start(options, ({ port, endpoint }) =>
console.log(
Server started, listening on port ${port}${endpoint} for incoming requests.,
),
)
`

Most helpful comment

You can increase the express timeout in graphql-yoga like so:

const server = new GraphQLServer({ typeDefs, resolvers });
server.start(() => console.log('Server is running on localhost:4000'))
  .then(s => s.setTimeout(5 * 60 * 1000)); // 5 minutes

In this case s is the instance of a regular node HTTP Server or HTTPS Server.

All 3 comments

Do we have any resolution on it, I see graphql-yoga uses express-js internally, but how can I update the timeout of the server call.

We have a call to the view table which takes up to 5 mins runnings on the Dbeaver itself because of 5 million+ data rows. GraphQL-yoga query takes 2m as the default timeout. Is there any way we can update it?

I also had issues with the 2 minute timeout so I forked the repo and added a timeout option. It doesn't look like graphql-yoga is actively maintained anymore so I shouldn't lose much by using a forked version and maintaining it myself.

If it wasn't for me using Prisma 1 with prisma-binding, I'd just switch to apollo-server-express, where it's easy to add a timeout

const server = new ApolloServer({ typeDefs, resolvers });

const app = express();
server.applyMiddleware({ app });

app.listen({ port: 4000 }, () =>
  console.log(`馃殌 Server ready at http://localhost:4000${server.graphqlPath}`)
).setTimeout(1000*60*10)

This, however, breaks all my field aliases on my prisma resolvers and would force me to rewrite all of my middleware functions for my resolvers.

You can increase the express timeout in graphql-yoga like so:

const server = new GraphQLServer({ typeDefs, resolvers });
server.start(() => console.log('Server is running on localhost:4000'))
  .then(s => s.setTimeout(5 * 60 * 1000)); // 5 minutes

In this case s is the instance of a regular node HTTP Server or HTTPS Server.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

bmcilw1 picture bmcilw1  路  5Comments

AhmadEl-Banna picture AhmadEl-Banna  路  5Comments

CaptainChemist picture CaptainChemist  路  4Comments

joshhopkins picture joshhopkins  路  3Comments

ramonmulia picture ramonmulia  路  3Comments