-
Notifications
You must be signed in to change notification settings - Fork 7
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
Implement timeout for Apollo Client #429
Comments
Hey @lughino 👋 Thanks for the request! I'd like to poke at this a little bit to understand your thinking here.
setContext((_, previousContext) => ({
fetchOptions: {
signal: previousContext.fetchOptions?.signal || AbortSignal.timeout(5000)
}
}) You can override this per-query using useQuery(query, {
context: {
fetchOptions: { signal: AbortSignal.timeout(10_000) }
}
});
Given the above, I'd like to understand how you envision something more integrated and what shortcomings there might be of the solution I posted above. I personally don't feel like this is a lot of code, and I'm not sure if something more integrated would be much more elegant. If we can avoid the bundle size in the library by using existing functionality, that would be ideal. I may be shortsighted here, so please let me know what I'm missing! Thanks again for the request! |
Hi @jerelmiller , Yes, it is possible to use the context in this way. I did not think of this solution, as my solution was to create a custom link with the timeout logic. |
That's fair, but I'd consider solving this with documentation first 🙂. If the above solution were a ton of code, I could definitely see a compelling reason to include it. If you want to provide something more simple/out-of-the-box, would a third-party package be an option? If you're interested in publishing a package, we'd be happy to list it in our community links. |
Currently there is no timeout mechanism in Apollo Client. The only way to achieve that is to create a custom link with the logic to timeout and cancel the inflight request.
Considering that Apollo uses the
fetch
interface, I feel this should be made available directly from the framework, and not rely on custom logic.Implement this is straightforward as we can leverage the
AbortSignal.timeout
:We could then be able to set a global timeout and override it on query basis passing a
timeout
optionThe text was updated successfully, but these errors were encountered: