Closed paales closed 2 months ago
hi @paales, yes this should be already possible by doing the following:
const { data } = await getClient().query({
query,
context: {
fetchOptions: {
next: { revalidate: 5 },
},
},
});
Ohh, thanks! That makes sense. I was confused because of the lack of typings in in the context.
About the typings: unfortunately, those would need to be different for every link you are using - these are for HttpLink, but if you were using something else it could have very different config options. So we unfortunately can't type that here :/
I'm trying to make sense how to combine the fetchPolicy and the fetch cache option. I've written it out, what do you think about this conclusion?
Cache configuration on queries:
Request dedupe:
fetchPolicy | cache | Request chain |
---|---|---|
cache-first, standby | force-cache | Apollo Cache -> ~React.cache~ -> fetch cache -> fetch |
cache-first, standby | no-store | Apollo Cache -> ~React.cache~ -> fetch |
network-only, no-cache | force-cache | React.cache -> fetch cache -> fetch |
network-only, no-cache | no-store | React.cache -> fetch |
cache-only | ? | Apollo Cache |
The difference between cache-first
and network-only
is that we're leveraging the React.cache instead of the Apollo Cache. Since the Apollo Cache is superior to the React.cache, we should probably only use the Apollo Cache and thus only use cache-first
.
I can't think of a possible cache-only
use case in a RSC environment, ideas? This looks like the only-if-cached RequestCache property, but that isn't documented in the next.js docs, they probably didn't think it made sense.
My conclusion: Always have the fetchPolicy set to cache-first
and use Next.js cache property to handle any any caching between requests.
About the typings: unfortunately, those would need to be different for every link you are using - these are for HttpLink, but if you were using something else it could have very different config options. So we unfortunately can't type that here :/
We're creating a wrapper for the getClient().query() so we'll handle it there.
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.
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.
For a general fetch call next.js supports fetch options:
In the README
fetchOptions: { cache: "no-store" },
is suggested as a possible solution to disable nextjs' cache, which works, but this is on a global level and I think this will disable the cache for the complete route (not sure yet).We'd like to do something like:
Maybe this is already possible, but wasn't clear to me how this should work.