Skip to content
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

Add timeouts to resolvers #1068

Merged
merged 7 commits into from May 31, 2018
Merged

Add timeouts to resolvers #1068

merged 7 commits into from May 31, 2018

Conversation

alloy
Copy link
Contributor

@alloy alloy commented May 30, 2018

Closes https://artsyproduct.atlassian.net/browse/PLATFORM-425

After going back and forth a few times on how to approach this (e.g. have a fixed overall timeout, but that’s weird because some queries legitimately take longer than others) I finally settled on the simplest solution, which is to have a timeout per resolver.

I’ve hardcoded a default of 5 seconds, but am open to changing that if people have opinions.

If resolvers need to deviate and take longer, they can technically do so by using a directive, except that will require generating a bit of AST because we don’t use the SDL to define out schema (dear future reader, ping me if you are in need of this).

⚠️ We should only deploy this to production while keeping a close eye out for these errors, otherwise we risk timing out queries that succeed today.

@@ -96,12 +97,14 @@
"uuid": "^3.1.0"
},
"resolutions": {
"babel-core": "^7.0.0-bridge.0"
"babel-core": "^7.0.0-bridge.0",
"@types/graphql": "^0.13.1"
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For some weird reason a few of our deps pull in this types package as a runtime dependency, which leads to there being multiple versions… It’s really a bug upstream, but whatevs, can’t fight every battle 🤷‍♂️

}

type Query {
artwork: Artwork @timeout(ms: ${artworkTimeout})
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Here’s an example of explicit timeout for a resolver.

@alloy
Copy link
Contributor Author

alloy commented May 30, 2018

Note that this will not cancel side-effects of in process resolvers, it will only stop the resolver and return null meaning that nested queries will no longer be executed.

@@ -0,0 +1,49 @@
import { IMiddleware } from "graphql-middleware"
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👋 hi middleware. IMatt

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah this is a very ugly (IMO) TS convention that indicates this is an interface. 🤷‍♂️

@mzikherman
Copy link
Contributor

This looks great to me, nice tests! Interesting use of directive to enable the override on a per field basis as well.

Let's hold this prior to merging since we want to test and deploy the new Datadog integration, currently on staging.

@alloy
Copy link
Contributor Author

alloy commented May 31, 2018

Speaking of DataDog integration, is there some way to surface in DD that a query has timed out? Otherwise it may skew aggregates incorrectly? /cc @saolsen

@alloy
Copy link
Contributor Author

alloy commented May 31, 2018

Here we go!

@alloy alloy merged commit a196b0a into master May 31, 2018
@alloy alloy deleted the timeouts branch May 31, 2018 19:05
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants