Expose ReactRelayContext in ReactRelayPublic (#2547)
Expose ReactRelayContext in ReactRelayPublic (#2547)

Summary:
I'd like to start a discussion on whether the React Relay internal context should be exposed publicly. I currently have two use cases that require access to it.

1. **Server Side Rendering:**

Our pattern for rendering Relay on the server looks something like this:

```js
const data = await fetchQuery(environment, query, variables);

ReactDOMServer.renderToString(
    <RelayContextProvider environment={environment} variables={variables}>
        <MyApp data={data} />
    </RelayContextProvider>
);
```

[RelayContextProvider](https://github.com/relay-tools/relay-context-provider) is a package that I maintain which creates a React context in the shape Relay containers expect, allowing them the render prefetched data from the environment. This package uses the old context API but will no longer work with the new Relay Context API. `<ReactRelayContext.Provider>` would be a drop in replacement.

I think this use case may be solved in the future with React Suspense and the experimental `createQueryRenderer` but we will be blocked from updating Relay until both of those are stable.

2. **Manually unmasking data for use in shared functions:**

We have a lot of functions that use data that is fetched from GraphQL. These are usually for analytics tracking and are called from multiple components when certain events happen. Since these require a specific amount of data to be passed, we define a standalone fragment for this function, and include it in the component's fragments. We usually use `relay(mask: false)` on these fragments for simplicity, [but there are issues with this when the fragments contain variables](https://github.com/facebook/relay/pull/2359).

Ideally we could unmask the data from these fragments using the methods in `relay-runtime`, but this requires access to the variables that are stored in React context. We could do this before by setting `contextTypes` on the component but it will now require access to `<RelayContext.Consumer>`.

jstejada josephsavona kassens taion
Pull Request resolved: https://github.com/facebook/relay/pull/2547

Reviewed By: kassens

Differential Revision: D12989672

Pulled By: josephsavona

fbshipit-source-id: d07a4a8597cfa02fea24e76567dc6eca543adb13

atxwebs/relay,voideanvalue/relay,voideanvalue/relay,josephsavona/relay,facebook/relay,wincent/relay,facebook/relay,dbslone/relay,xuorig/relay,iamchenxin/relay,wincent/relay,kassens/relay,atxwebs/relay,zpao/relay,freiksenet/relay,wincent/relay,iamchenxin/relay,zpao/relay,wincent/relay,zpao/relay,facebook/relay,josephsavona/relay,kassens/relay,voideanvalue/relay,cpojer/relay,facebook/relay,wincent/relay,xuorig/relay,iamchenxin/relay,wincent/relay,yungsters/relay,freiksenet/relay,cpojer/relay,kassens/relay,cpojer/relay,atxwebs/relay,freiksenet/relay,voideanvalue/relay,kassens/relay,josephsavona/relay,kassens/relay,atxwebs/relay,cpojer/relay,yungsters/relay,yungsters/relay,voideanvalue/relay,facebook/relay,dbslone/relay,facebook/relay,xuorig/relay,kassens/relay,xuorig/relay,voideanvalue/relay,xuorig/relay,iamchenxin/relay,xuorig/relay