facebook / facebook/relay

Recommended patterns when using resolvers

Open
#4,987 4 comments 1 reaction 0 assignees View on GitHub
shared with relay team
Dominant language
Rust
Stars
19k
Forks
1.9k
PR merge metrics
No merged PRs in 30d

Description

From our discussion related to #4967, my understanding is that while Relay resolvers can be used in many different ways, some of them are more idiomatic and have a lower risk of gaps or weird corner cases. I'd like to ask a few questions related to that, and I'd be happy to contribute to the docs afterwards so that this knowledge is captured somewhere 🙂

1. Should all client-defined types be implemented either as "strong" or "weak" types, and "output" types (i.e., types declared in client schema extensions) should be avoided?
2. When creating a resolver for a field that corresponds to a one-to-many edge to a strong type (i.e., `SomeType.myField: [MyStrongType]`), should the resolver return a list of `{ id: DataID }` objects? And if the resolver is live, does it require the strong type resolver to also be live?
3. When creating a live resolver that does some expensive work (e.g., doing a REST API call), should this expensive work be done in the body of the resolver or in the `subscribe` function?

Contributor guide

Open the contributing guide

Research direction

Start by reviewing the discussion in #4967 and the three resolver questions in this issue. The issue names no documentation file or test; done means resolving the questions and capturing the agreed recommended patterns in the project documentation.

Written by the indexing model from the issue text.

Assessment

Tech stack
javascript, react
Domain
documentation
Issue type
Documentation
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
25/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.