Giter Club home page Giter Club logo

Comments (7)

phryneas avatar phryneas commented on June 16, 2024

It's hard to tell anything here without seeing what exactly you did - please show us some code :)

Also, how did you measure this speed increase? Is this in RSC, SSR or in the Browser? How big is your response?

I think we'll generally need a bit more context here :)

from apollo-client.

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

We're closing this issue now but feel free to ping the maintainers or open a new issue if you still need support. Thank you!

from apollo-client.

billnbell2 avatar billnbell2 commented on June 16, 2024

Here is some code.

It is pretty self explanatory though. Switch Apollo-CLient to use cross-fetch.

Here -

import fetch from 'cross-fetch';

export const client = (
  showError: (str?: string) => void = (_str?: string) => {}
) =>
  new ApolloClient({
    defaultOptions,
    link: from([
      authLink,
      retryLink,
      errorLink(showError),
        createHttpLink({
            uri: process.env.NEXT_PUBLIC_GRAPHQL_URL,
            fetch,
          }),
    ]),
    cache,
  });

from apollo-client.

jerelmiller avatar jerelmiller commented on June 16, 2024

@billnbell2 appreciate the code, but I'm not sure what you're looking for from us?

from apollo-client.

billnbell2 avatar billnbell2 commented on June 16, 2024

Why do I need to use cross-fetch ?

If I leave it the default it takes Apollo Client 1-2 seconds per calls, when I use cross-fetch we are consistently at 200ms. Same exact call.

from apollo-client.

billnbell2 avatar billnbell2 commented on June 16, 2024

Can you try it yourself and see if you get similar perf gains?

from apollo-client.

jerelmiller avatar jerelmiller commented on June 16, 2024

You are absolutely free to use whatever fetch implementation works for you. We're just using the built-in global fetch function available in your environment.

The only thing I can think might be happening here is that perhaps something is patching fetch in your environment and causing the perf issues on your end. Your code sample implies you're using Next.js which does fetch patching to add cache behavior to it. In fact, this was something that was recently reverted in React itself. Perhaps you're running into something here?

To be honest, even if this weren't it, we wouldn't make any current changes as using the global fetch function means we don't need additional dependencies which adds bundle size. Again, feel free to use cross-fetch if you'd like instead. I'd start however by taking a look at your global fetch function to see if there is something patching it first. You might be able to avoid the cross-fetch dependency yourself if need be. You can find out more about how Next.js patches it in their docs.

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.