facebook / facebook/relay

Support Client Edge to Server for observeFragment

Open
#5,012 0 comments 1 reaction 1 assignee Claimed by @itsjoeoui View on GitHub
shared with relay team
Dominant language
Rust
Stars
19k
Forks
1.9k
PR merge metrics
No merged PRs in 30d

Description

### Motivation

We have a feature called Relay Resolvers which lets you define additional GraphQL fields which get evaluated on the client. We even allow you to define a field which points back to a type on the server. In that case we generate a query for each place the edge is read, and when you try to read that edge, we fetch the query. This logic is currently implemented for `useFragment` and other hook APIs but is not yet implemented for our new `observeFragment` API which powers some non-React APIs.

This is the only gap that is currently preventing `observeFragment` and `waitForFragmentData` from being promoted from experimental to stable.

### Docs links

- [[**](https://relay.dev/docs/next/guides/relay-resolvers/return-types/#server-types)https://relay.dev/docs/next/guides/relay-resolvers/return-types/#server-types**](https://relay.dev/docs/next/guides/relay-resolvers/return-types/#server-types)
- [[**](https://relay.dev/docs/next/api-reference/relay-runtime/api-reference/observe-fragment/)https://relay.dev/docs/next/api-reference/relay-runtime/api-reference/observe-fragment/**](https://relay.dev/docs/next/api-reference/relay-runtime/api-reference/observe-fragment/)

## Code Pointers

- Would need to be handled [[here](https://github.com/facebook/relay/blob/ba09a88925c05bfc40ba6eaa4fb0d9ff37a5d4f4/packages/relay-runtime/store/observeFragmentExperimental.js#L232)](https://github.com/facebook/relay/blob/ba09a88925c05bfc40ba6eaa4fb0d9ff37a5d4f4/packages/relay-runtime/store/observeFragmentExperimental.js#L232) in `observeFragment`.
- Will need to remove [[this invariant](https://github.com/facebook/relay/blob/ba09a88925c05bfc40ba6eaa4fb0d9ff37a5d4f4/packages/relay-runtime/store/observeFragmentExperimental.js#L122)](https://github.com/facebook/relay/blob/ba09a88925c05bfc40ba6eaa4fb0d9ff37a5d4f4/packages/relay-runtime/store/observeFragmentExperimental.js#L122).
- The equivalent logic in `useFragment` is implemented [[here](https://github.com/facebook/relay/blob/ba09a88925c05bfc40ba6eaa4fb0d9ff37a5d4f4/packages/react-relay/relay-hooks/useFragmentInternal_EXPERIMENTAL.js#L225)](https://github.com/facebook/relay/blob/ba09a88925c05bfc40ba6eaa4fb0d9ff37a5d4f4/packages/react-relay/relay-hooks/useFragmentInternal_EXPERIMENTAL.js#L225).
- Tests should be added [[here](https://github.com/facebook/relay/blob/ba09a88925c05bfc40ba6eaa4fb0d9ff37a5d4f4/packages/relay-runtime/store/__tests__/observeFragment-test.js)](https://github.com/facebook/relay/blob/ba09a88925c05bfc40ba6eaa4fb0d9ff37a5d4f4/packages/relay-runtime/store/__tests__/observeFragment-test.js).

Tips for contributing can be found [[here](https://github.com/facebook/relay/blob/ba09a88925c05bfc40ba6eaa4fb0d9ff37a5d4f4/.github/CONTRIBUTING.md#L4)](https://github.com/facebook/relay/blob/ba09a88925c05bfc40ba6eaa4fb0d9ff37a5d4f4/.github/CONTRIBUTING.md#L4).

### Broad goals:

1. If missing data is discovered that needs to be fetched by a client edge query, it should be fetched and the observable be in a loading state while it’s fetching.
2. Once the query response is received, we should
3. While the observable is subscribed, the query should be retained (it should not be garbage collected by Relay’s GC.). When the observable is unsubscribed, it should be freed an eligible for GC. See [[this doc](https://relay.dev/docs/next/guided-tour/accessing-data-without-react/retaining-queries/)](https://relay.dev/docs/next/guided-tour/accessing-data-without-react/retaining-queries/) for more information.
4. All cases should be covered with unit tests.

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.