facebook / facebook/relay

[Modern] Easy way for store population from SSR

Open
#2,232 19 comments 7 reactions 0 assignees View on GitHub
wontfix
Dominant language
Rust
Stars
19k
Forks
1.9k
PR merge metrics
No merged PRs in 30d

Description

I pass from server to the client following data: `query`, `variables` and `payload` (response from graphql). Before rendering `App` I want to somehow put this data in the Relay store. How can it be done on the client?

Solved problems:
- For the server implemented [RelaySSRQueryRenderer](https://gist.github.com/nodkz/a0cfa6f8c57f8746c30d3fa7b598e5a6) which firstly lookup data in the store (before making request) without component observer subscriptions. It works perfectly for SSR.
- SSR works in such way:
- with first call of `renderToString` for run queries
- then awaiting network layer which completes all queries
- and after that second call of `renderToString` for render app with the already populated store. Tricky, but works.
- For the client I implemented own `QueryRenderer` which firstly lookup data in the store, before making a network request.

Main Restriction:
- Passing serialized data from `relayEnv.getStore().getSource().toJSON();` produced too much redundant data. Passing `query`, `variables` and `payload` much lighter.
- How I understand a text query can not be converted to AST in runtime.

Is there an easy way to populate Relay store from `query`, `variables` and `payload`?

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.