Is it possible to configure a max execution on the server, for all GraphQl requests?

Let’s imagine that my GraphQl Apollo server is running on Heroku.

I would like to enforce that NO queries/mutations should take longer than 10 seconds.

Is that possible to configure somehow?

These might be useful for you.

I have seen articles online of enforcing a max query time, but I have never needed it; instead of setting a hard max, I typically limit the underlying values that would cause a query to exceed a certain time.

This keeps queries from being hellish, but also allows for queries that take 10.1 seconds. Rather than forcing a query to fail mid-execution, I try to detect and limit queries that would take too long.

That’s also a nice approach. But Heroku enforces it’s clients to deliver a byte before 30 seconds. Otherwise, it will throw an error.

This error is HTML, and because the appollo client assumes it’s JSON ==> we get a JSON.parse error without any help what so ever to give us any hint’s about the actual error (heroku returns some HTML when no byte was delivered).

If you’re using the express variant of apollo server, you should be able to use an express middleware to accomplish this.

Not sure how that would affect subscriptions, if at all.

1 Like

Yes - I ended up doing something like that (using sveltekit, but did it in the hooks file with a promise.race)