T
TanStack2y ago
robust-apricot

Is it possible to call a mutation inside of a Next.js server component?

I want to mutate data on our GraphQL backend but the component I'm in is a server component inside of a server component and I can't change it to a client component because you can't have client stuff inside server stuff. Is it possible to run a mutation inside of a server component? For queries, I use queryClient.fetchQuery but there doesn't appear to be a similar method on queryClient.
3 Replies
sunny-green
sunny-green2y ago
Just call the mutationFn directly?
robust-apricot
robust-apricotOP2y ago
dont you have to call useWhateverMutation or useMutation to get the mutationFn though? If I do that, I get an error:
Error: (0 , _tanstack_react_query__WEBPACK_IMPORTED_MODULE_3__.useMutation) is not a function
Error: (0 , _tanstack_react_query__WEBPACK_IMPORTED_MODULE_3__.useMutation) is not a function
sunny-green
sunny-green2y ago
Yeah. Call your definition of mutationFn

Did you find this page helpful?