Giter Club home page Giter Club logo

Comments (6)

phryneas avatar phryneas commented on June 4, 2024

Apollo Client with the HttpLink just calls fetch, which does not have a timeout option.
It will try to wait until the server closes the connection, so it's literally impossible to increase the timeout on client side any further than that.

You could shorten the waiting time by introducing your own link to the link chain that would time out requests after a while, but making requests last longer than they currently do is just not possible as they already wait the maximum possible amount of time.

from apollo-client.

lughino avatar lughino commented on June 4, 2024

@phryneas fetch allows to cancel an inflight requests through the AbortController signal.
Current browsers support a shortcut through AbortSignal.timeout, like:

async function loadPosts() {
  try {
    const response = await fetch('/posts', {
      signal: AbortSignal.timeout(5000)
    });
    const posts = await response.json();

    return posts;
  } catch (error) {
    // Timeouts if the request takes longer than 5 seconds
    console.log(error.name === 'AbortError');
    // handle error
  }
}

This use case is quite common to ensure the server, or the overall network latency is holding the response for a long period of time.
Considering Apollo Client uses a fetch interface, it would be appropriate to have this option available from Apollo Client directly. Right now the only way possible is to create a custom HttpLink with the custom logic. Not a hard task, but is a bit tedious for such a basic functionality.

from apollo-client.

phryneas avatar phryneas commented on June 4, 2024

@lughino I'm not sure if this is the right issue to ask for this.
This issue was not asking for a timeout option, but it was asking for a way to increase an assumed existing timeout (which doesn't exist).

Generally, I agree, that we could introduce timeout option, but that should probably be tracked in a separate issue over in https://github.com/apollographql/apollo-feature-requests.
Could you please open an issue over there?

from apollo-client.

lughino avatar lughino commented on June 4, 2024

Sure thing @phryneas I'll open a issue there

from apollo-client.

phryneas avatar phryneas commented on June 4, 2024

Thank you!

I believe I can close this issue here then, since @jeebeez never answered - I assume the explanation I gave in my first answer was probably enough.

from apollo-client.

github-actions avatar github-actions commented on June 4, 2024

Do you have any feedback for the maintainers? Please tell us by taking a one-minute survey. Your responses will help us understand Apollo Client usage and allow us to serve you better.

from apollo-client.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.