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

add parameter type support to getClient #196

Closed rezof closed 2 months ago

rezof commented 2 months ago

I kept getting getClient Expected 0 arguments, but got ... because makeClient has no parameters

phryneas commented 2 months ago

That is kinda intentional - if I may ask, what are you passing in there?

rezof commented 2 months ago

@phryneas i pass fetchOptions:{ cache: ...} for next as well as fetch headers.

I just remembered that i can use context for setting such things. the only difference is they have to be provided to every query/mutation on page while getClient passes them directly to the HttpLink

If you want to keep it without parameters you can close the PR.

Thanks 🙌

phryneas commented 2 months ago

Yeah, you definitely should avoid doing it this way.

If you pass different arguments into getClient for two calls, you will get two different client instances.

The purpose of getClient is to create a new Apollo Client instance for every new request, but to always return the same instance within that request.

As soon as you call it with potentially different arguments, that functionality stops working.

=> Yeah, please use the per-request context for this :)

I'm going to close this issue. Have a great day!