RevereCRE / relay-nextjs

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

Create server environment without a query #16

Closed hosmelq closed 2 years ago

hosmelq commented 3 years ago

Hello, first of all, thanks for this package.

I would like to know if there a way to create a server environment without passing the query. I do not want to do the query on the top-level page.

Thanks.

rrdelaney commented 3 years ago

Hey Hosmel, thanks for filing this. I think if you want to just have access to a Relay environment in your Next.js app without having the per-page query you can wrap your app with a RelayEnvironmentProvider in _app.ts, no relay-nextjs needed!

hosmelq commented 3 years ago

Hello @rrdelaney, thanks for the reply, if I use RelayEnvironmentProvider I think this is going to do two queries, one on the server and another on the client.

rrdelaney commented 3 years ago

I'm not sure this is possible then. Queries have to be attached to page-level components because only they can request server-side data in Next.js apps. You can also use useLazyLoadQuery exclusively on the client-side.

hosmelq commented 3 years ago

Yes, I am using useLazyLoadQuery in some parts of the pages, The thing that I would like is to have the shared store without making a query at the page level. I will try to find i way to do that.

Thank You very much.