-
With the new version of react and nextJS having server components how do you guys recommend querying the yoga instance in a server component since you can't use apollo client or any other client-side tools In a server component? I don't know if this isn't a big deal and I am just not used to querying data via the server side or if this is a big change. I know there are a lot of tools scrambling to update with the new server components as it is a big change. |
Beta Was this translation helpful? Give feedback.
Replies: 2 comments 3 replies
-
if you are already using Apollo client it shod imo work same for SSR. It will just populate Apollo cache which when the app hydrates on client side populate the client side Apollo store. This way when the page loads it loads the data from Apollo store instead of making a fetch call |
Beta Was this translation helpful? Give feedback.
-
There are multiple options available here: Use
|
Beta Was this translation helpful? Give feedback.
There are multiple options available here:
Use
fetch
for loading data from the GraphQL API via HTTPThis is straightforward - you don't need a GraphQL client, it always depends on what you want to achieve. Executing a GraphQL operation can be as simple as doing an HTTP request with
fetch
.This is best if your GraphQL Yoga HTTP server lives outside or alongside your Next.js Application as a separate service.
@notrab also made a video about Server Components and graphql-request, that would also be applicable here: https://graphql.wtf/episodes/66-graphql-with-nextjs-13-server-components
Use
yoga.fetch
for loading data without HTTPYou can actually use the following API for doing a GraphQL Yo…