Expose sourceHash or id for operations
- Dominant language
- Rust
- Stars
- 19k
- Forks
- 1.9k
- PR merge metrics
- No merged PRs in 30d
Description
`fetchQuery`receives `operation.node.params` but it would be nice to have access to `operation.node.hash` to use it for local cache key and mainly for the following approach: first fetch to the server with hash and variables only, if the server contains the hash in its own cache, it directly responds, else a second round trip with query, variables and hash will be done.
https://github.com/facebook/relay/blob/b7832555f390e6acf965fe7fdc5eabab0ffcd4a8/packages/relay-runtime/store/RelayModernEnvironment.js#L274
https://github.com/facebook/relay/blob/4343e80b48ad21d7bc40b57abdcb9acb751c45b3/packages/relay-compiler/language/javascript/formatGeneratedModule.js#L45
Other possibility could be using something similar to "persist-output", but this removes the text of the operation, we need to keep the `text` and get also the `id` to use this one as hash.
@josephsavona Do you have some hint? is this doable? willing to work in a PR if it makes sense for you.
Contributor guide
Research direction
Start with RelayModernEnvironment.js at the linked fetchQuery entry point and formatGeneratedModule.js where generated operation metadata is formatted. Trace how params, text, and hashes are currently exposed; done means the operation can provide a cacheable hash or id while retaining the query text for the proposed request flow.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- javascript, react
- Domain
- api
- Issue type
- Feature
- Difficulty
- 5/5
- Estimated time
- Over a week
- Activity status
- Stale
- Clarity
- Needs clarification
- Newbie friendliness
- 25/100