-
Notifications
You must be signed in to change notification settings - Fork 36
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
reset cache integration for nextjs 13.4 #101
Comments
I'm not exactly sure what you ask here.... where is this code running? In a server component? In a client component? |
Thank your response, I use this in the server component (I mean App API route) to get the new content of the app after I changed. I also call the same in the app page.tsx get the data contents (which set up the time to revalidate is 1 day). The case here I change the data content, So I force the app revalidate data and reflect it on the app. so I apply this method in the App API route export async function GET(request: NextRequest) {
try {
const token = request.nextUrl.searchParams.get("secret");
if (token === serverConfig.basic_token) {
await client.resetStore();
await client.query({
query: AppContentsDocument,
context: {
fetchOptions: {
next: { revalidate: 1 },
},
},
fetchPolicy: "no-cache",
});
return NextResponse.json({ message: "Revalidated", success: true });
}
} catch (err) {
return NextResponse.json({ message: err, success: false });
}
} |
Please make sure that in a request handler like this, you create a new instance of Apollo Client for every single incoming request - otherwise things like query deduplication could mix up queries of multiple users that are incoming at the same time. Calling You could have 20 requests in the same millisecond, and all of them call That said, if you're not using React SSR, (and this is just a response handler), you also don't need to use the |
I'm doing some housekeeping so I'm closing some older issues that haven't seen activity in a while. |
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. |
Recently, I have a landing page that get all the app contents in the server side of nextjs with one day revalidate config. and I would like an API in nextjs server that can reset the cache and fetch new data whenever I request and the app also reflect the new data. here my integration in the nextjs app. I wonder do I apply the best practices for the case
`
const client = new NextSSRApolloClient({
cache: new NextSSRInMemoryCache(),
link: formatAppContentsResponse.concat(httpLink),
});
await client.resetStore();
await client.query({
query: ExampleDocument,
context: {
fetchOptions: {
next: { revalidate: 1 },
},
},
fetchPolicy: 'no-cache',
});`
The text was updated successfully, but these errors were encountered: