Ecosyste.ms: Awesome

An open API service indexing awesome lists of open source software.

Awesome Lists | Featured Topics | Projects

https://github.com/m19c/relay-context

A simple way to manage your relay environment(s)
https://github.com/m19c/relay-context

graphql react relay relay-modern

Last synced: 6 days ago
JSON representation

A simple way to manage your relay environment(s)

Awesome Lists containing this project

README

        

# relay-context
Relay's original `QueryRenderer` requires an environment to determine the graphql endpoint to talk with. Mostly you will do something like this:

- pass down through props
- store in the window to access it later on
- store it in a registry object to access it later on

This is where `relay-context` comes into play. It provides a high-order component to register your environment(s) at one place (see Example > Main entry point). It is also possible to specify a default environment for your `QueryRenderer`.

## Install
### yarn
```
yarn add relay-context
```

### npm
```
npm i --save relay-context
```

## Example
### Main entry point
```javascript
import { Context } from 'relay-context';
import { render } from 'react-dom';
import App from './components/App';

// create your relay environment(s)
const environmentA = new Environment();
const environmentB = new Environment();

render(



)
```

### Somewhere in your application (e.g. `Beer.js`)
```javascript
import React from 'react';
import { QueryRenderer } from 'relay-context'
import { graphql } from 'react-relay';

export default ({ slug }) => {
// TODO: render stuff
}}
/>;
```