-
Notifications
You must be signed in to change notification settings - Fork 35
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
useSuspenseQuery: Server functions cannot be called on initial render. #355
Comments
Phew, this is a difficult one - unfortunately React seems to be more opinionated than practical here :/ This is made even more difficult by the fact that For the SSR part, you could use something like https://github.com/phryneas/ssr-only-secrets, but that doesn't solve the problem at hand. Passing your token down as a prop unencryped would expose it to the browser, which is generally a thing I'd try to avoid. That said, maybe that's the core of your problem - calling your Is there any way to establish that cookie directly between your browser and GraphQL server in the first place so you don't need that authentication header? That would be more secure and remove the need for the server action call. |
Thanks for your response. The path I've decided to take, based on your suggestion, is altering my API so that it can accept either cookie or header based authentication. The RSC client sends the header based auth, and the 'client' client sends credential based cookies. NextJS not making things easy but at least I have a workaround for the timebeing. I still seem to be getting an unauthorized response on my very first RSC request, but I'll just have to live with that - I'm no longer getting the error I mentioned above. Appreciate your help! |
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. |
I have this problem and I use Authorization with token in header can you send the code how you solve this issue please |
is there a approach to solve it ?? |
Please send some example |
@withintheruins14 that looks like TanStack Query code, not Apollo Client code. Are you sure you're in the right place? |
I've swapped out useQuery for useSuspenseQuery and I'm now getting the following error:
ApolloError: Server Functions cannot be called during initial render. This would create a fetch waterfall. Try to use a Server Component to pass data to Client Components instead.
This is happening (assumption noted) because I am calling a server function to retrieve my authorization token when creating my authLink for the client side apollo client:
This error does not get shown when using useQuery, only when using useSuspenseQuery. I've attempted other methods of retrieving my token but unfortunately cannot reliably do this.
I use PreloadQuery (as covered in the docs):
Parent component:
Child component:
Any assistance would be greatly appreciated.
The text was updated successfully, but these errors were encountered: