RevereCRE / relay-nextjs

⚡️ Relay integration for Next.js apps
https://reverecre.github.io/relay-nextjs/
MIT License
250 stars 30 forks source link

How set headers from server request? #36

Closed stug111 closed 2 years ago

stug111 commented 2 years ago

Hello, tell me how to set the headers received from the server on the client?

In apollo, this is done via setContext is there anything good here.

I am trying to implement adding to cart for unauthorized users. For this to work, I need to always update the user session, since it comes from the server.

I also noticed that when the page is redirected, usePreloadedQuery is triggered twice, is this normal?

It is also interesting how to implement work with the jwt token, in particular, tracking the error and performing a re-request.

rrdelaney commented 2 years ago

Hi! relay-nextjs doesn't send GraphQL requests for you or really have much of an opinion about how network requests are sent. It relies on the Relay Network Layer to handle all of that, which must be provided when creating an Environment.

usePreloadedQuery is intended to be called twice when rendering on the client-side because that's how the page suspends 🙂