facebook / relay

Relay is a JavaScript framework for building data-driven React applications.
https://relay.dev
MIT License
18.36k stars 1.82k forks source link

Document Multi Actor Environment #3902

Open kejistan opened 2 years ago

kejistan commented 2 years ago

This is a neat part of relay that got built out last year, but it still hasn't been documented anywhere. Can we write some documentation about how and when to use this?

captbaritone commented 2 years ago

@kassens Do we have any internal docs we could share here?

kassens commented 2 years ago

This isn't documented yet, because it's still in an experimental phase internally.

What you can already do today is creating multiple Environments and use them on one page (using ReactContext rules, so the innermost EnvironmentProvider is used in a React tree.

The core that multi-actor supports is that a single GraphQL response could return data for multiple data "viewers". Example, on a feed when you admin/control multiple accounts, multi-actor might support fetching a single GraphQL query where posts from each account you control might be returned with the "viewer" permissions of that account.

This is pretty advanced, I suspect you might be looking for a different feature.

kassens commented 2 years ago

We sometimes experiment with new features where we're not sure they'll make it into a stable API. This is one such example that's been stalled development internally unfortunately.

kejistan commented 2 years ago

That is actually quite similar to the problem that led me to finding the multi-actor code. Specifically: issuing a request that resolves part of the response with a different set of permissions on the backend, and then wanting a mechanism to write those results to a different environment's store. The current scheme I'm using is as you describe, manually managing multiple environments, changing them in the context, and manually copying data to the other environment's store via commitLocalUpdate.

Unfortunate to hear that it has stalled, but totally understand that it is a niche feature.