-
Notifications
You must be signed in to change notification settings - Fork 575
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
How to set the server timeout #644
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
In this case |
This issue is kinda' obsolete since Yoga v3 is server agnostic, there is no generic way of extending the timeout - it needs to be done on the server itself. ExamplesNodeimport { createSchema, createYoga } from 'graphql-yoga'
import { createServer } from 'node:http'
const yoga = createYoga({ ... })
const server = createServer(yoga)
server.setTimeout(5 * 60 * 1000) // 5 minute timeout
server.listen(4000, () => {
console.info('Server is running on http://localhost:4000/graphql')
}) Expressimport { createYoga } from 'graphql-yoga'
import express from 'express'
const app = express()
const yoga = createYoga({ ... })
app.use('/graphql', (req, res) => {
res.setTimeout(5 * 60 * 1000) // 5 minute timeout
yoga(req, res)
})
app.listen(4000, () => {
console.info('Server is running on http://localhost:4000/graphql')
}) Fastifyimport { createYoga } from 'graphql-yoga'
import fastify from 'fastify'
const app = fastify({
requestTimeout: 5 * 60 * 1000, // 5 minute timeout
})
const yoga = createYoga({ ... })
app.route({
url: '/graphql',
method: ['GET', 'POST', 'OPTIONS'],
handler: async (req, reply) => {
const res = await yoga.handleNodeRequest(req, { req, reply })
res.headers.forEach((value, key) => {
reply.header(key, value)
})
reply.status(res.status)
reply.send(res.body)
return reply
},
})
app.listen({ port: 4000 })
console.log(`Listening on http://localhost:4000/graphql`) Koaimport { createYoga } from 'graphql-yoga'
import Koa from 'koa'
const app = new Koa()
const yoga = createYoga({ ... })
app.use(async (ctx) => {
ctx.req.setTimeout(5 * 60 * 1000) // 5 minute timeout
const res = await yoga.handleNodeRequest(ctx.req, ctx)
ctx.status = res.status
res.headers.forEach((value, key) => {
ctx.append(key, value)
})
ctx.body = res.body
})
app.listen(4000, () => {
console.log(`Listening on http://localhost:4000/graphql`)
}) |
There appears to be undocumented behaviour with const response = await yoga.handleNodeRequest(request, {
foo: request,
request,
}); both inputs come out as different objects: context: async ({ request, foo }) => {
console.log('>>>', foo === request);
For whatever reason, the |
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.
The text was updated successfully, but these errors were encountered: