apollographql / apollo-client-nextjs

Apollo Client support for the Next.js App Router
https://www.npmjs.com/package/@apollo/experimental-nextjs-app-support
MIT License
358 stars 25 forks source link

Can I prefetch a query which is called at server side on hovering a link or so #140

Closed jinowac closed 2 months ago

jinowac commented 5 months ago

Can I prefetch a query which is called at server side on hovering a link or so
for example we had like this for client queries from apollo docs


 const    client  =  useApolloClient()

<Link
            to={{
              pathname: `/${data.breed}/${data.id}`,
              state: { id: data.id }
            }}
            onMouseOver={() =>
              client.query({
                query: GET_DOG,
                variables: { breed: data.breed }
              })
            }
            style={{ textDecoration: "none" }}
          >
            <Dog {...data} url={data.displayImage} />
         </Link>

@phryneas can u help me in with to prefetch the query called at server side on hovering a link when we are using this new "@apollo/experimental-nextjs-app-support/ssr" . Prefetching the query will help me to land to the page instantaneously

phryneas commented 5 months ago

You would do exactly that. After the first page load, there is no further SSR in Next.js, so nothing changed here.

jinowac commented 5 months ago

@phryneas what do you suggest . what cud be done?

phryneas commented 5 months ago

Ah, wait a second, you mean "server side", so we're talking RSC here, not SSR? Next.js already does this for RSC page navigations if you use their Link component, nothing for you to do.

jinowac commented 5 months ago

Does not seem to work in the case of graphql , I see ui from loading.js for milli secs . If link component is prefetching, then this shud not have happened @phryneas

phryneas commented 5 months ago

I am even more confused now.... React Server Components should give you static HTML. If you are indeed trying to do this in a RSC and prefetching doesn't work, you might have found a bug in the App Router and check that with the Next.js maintainers.

phryneas commented 2 months ago

I'm doing some housekeeping so I'm closing some older issues that haven't seen activity in a while. If this is still relevant, please feel free to reopen the issue.

github-actions[bot] commented 2 months ago

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.