Why create a new Client on the fly for every request in getServerSideProps #1521
-
This is probably a very silly question. I'm very new to both the React and Next.js worlds. I'm building out an application with Next.js and querying a GraphQL endpoint for data, for now only on the server side (client-side in the future). I intend to make use of In the next-urql documentation, the suggestion for
Why is this necessary? Is there no value in re-using a previously created Client? If every time a Client is created on the fly, is there any value in adding in exchanges like ssrExchange, or dedupExchange? For the latter, if I understand correctly, a newly created Client would not be aware of previous GraphQL requests made by the server, and not able to dedupe. If the above is true, is it ideal to keep the server-side Client creation in Edit: As a follow on question, there's also this example of utilizing Thanks in advance! |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 7 replies
-
The phrasing might be a bit off but we create a separate client just for the initial server-side render. This makes it so that we can do a bunch of requests on that client and it will only live in the closure of that initial data request. We should always utilize the |
Beta Was this translation helpful? Give feedback.
The phrasing might be a bit off but we create a separate client just for the initial server-side render. This makes it so that we can do a bunch of requests on that client and it will only live in the closure of that initial data request. We should always utilize the
ssrCache.extractData()
method. This PR will shed more light on the different methods as next-urql has two ways of using it #1502