GitXplorerGitXplorer
m

relay-context

public
10 stars
2 forks
0 issues

Commits

List of commits on branch master.
Unverified
1d119fcaafcfab759ce3fa80b0a9609e1d9c7fac

Bump version to 2.0.0

mm19c committed 8 years ago
Unverified
9dd185efcebe03c9ed39dd0d4c1d6278598fc300

README: transform to a simple list

mm19c committed 8 years ago
Unverified
1852c8a2d8050e670be3d980d997dd36a23fa22f

Prepare 2.0.0

mm19c committed 8 years ago
Unverified
02ff5aca4da0bdbf1e6f87b71bcae178da96a9e9

Release 1.0.0

mm19c committed 8 years ago
Unverified
fc73ed87651893197b67b16e8d7c989432fa0408

Add prepublish

mm19c committed 8 years ago
Unverified
b1b39d55bce3708effaa9aa87e670f9b053a9a6b

Add tests

mm19c committed 8 years ago

README

The README file for this repository.

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

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(
  <Context environmentRegistry={{ a: environmentA, b: environmentB }} defaultEnvironment="a">
    <App />
  </Context>
)

Somewhere in your application (e.g. Beer.js)

import React from 'react';
import { QueryRenderer } from 'relay-context'
import { graphql } from 'react-relay';

export default ({ slug }) => <QueryRenderer
  variables={{ slug }}
  environment="b" // uses b
  query={graphql`
    query BeerQuery(
      $slug: String!
    ) {
      query {
        beer: beerBySlug(slug: $slug) {
          title
          slug
          rating
          related(limit: 10) {
            title
            slug
            rating
          }
        }
      }
    }
  `}
  render={({ error, props }) => {
    // TODO: render stuff
  }}
/>;