-
Notifications
You must be signed in to change notification settings - Fork 2.7k
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
Invariant Violation: An error occurred! For more details, see the full error text at https://go.apollo.dev/c/err#%7B%22version%22%3A%223.9.4%22%2C%22message%22%3A49%2C%22args%22%3A%5B%5D%7D #11596
Comments
It seems like you do not have an Generally, please note that you should not be using We have a separate package to integrate Apollo Client with the Next.js app router: |
Given the Client Components Setup with SSR Support using ApolloClient directly was causing the error because for SSR scenarios, NextSSRApolloClient should be used instead, as indicated by the error messages, I updated the following files and now it works:
Don't see the immediate benefits I was expecting from implementing GraphQL but its been quite something implementing this. I just hope it improves the fetching of my blog content as promised. |
I'm very sorry you have to go through all this - unfortunately, at this time it's no fun using Next.js with a third-party fetching library, since Next.js runs your code
and all of those need slightly different setup. Unfortunately, there is not much we can do about that added complexity :/
I get that it looks like it is working for you now, but this will execute the same queries once during the SSR run and then again in the browser - is there a reason why you are not using the I know that the setup is no fun since you have to set up for three environments, but there is really no way around it :/ |
I forgot to mention this, the main issue with respect to the NextSSRApolloClient issue was that it needed to be distinguished between the client and server side of the apolloClient when in the browser so I needed to ensure that when the ApolloClient got called from fetchContentful.ts it was checked first. The following code displays the separation of the apolloClient.ts into two components (apolloClient.ts and apolloServer.ts) that would run separately and Called when needed by Contentful.
|
One more comment here: export function makeClient() {
// Adjust to use NextSSRApolloClient for SSR with appropriate caching and link setup
return new NextSSRApolloClient({
link: typeof window === "undefined"
? ApolloLink.from([new SSRMultipartLink({ stripDefer: true }), httpLink])
: httpLink,
- cache: new InMemoryCache(),
+ cache: new NextSSRInMemoryCache()
});
} Apart from that, I think at this point you're set up correctly :) I think your questions here are solved, so I'm closing this issue. Generally, if you have usage questions like this, please consider asking in the Apollo GraphQL Discord first - the issue tracker here is meant more for bug reports. |
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. |
This issue has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs. |
I have the following set up in my Next.js x Typescript x React app and I cant figure out why I'm getting this error or how to get past it. Help please...
The text was updated successfully, but these errors were encountered: