Adding Relay

Relay is a framework for building data-driven React applications powered by GraphQL. The current release of Relay works with Create React App projects out of the box using Babel Macros. Simply set up your project as laid out in the Relay documentation, then make sure you have a version of the babel plugin providing the macro.

To add it, run:

  1. npm install --save babel-plugin-relay

Alternatively you may use yarn:

  1. yarn add babel-plugin-relay

Then, wherever you use the graphql template tag, import the macro:

  1. import graphql from 'babel-plugin-relay/macro';
  2. // instead of:
  3. // import { graphql } from "babel-plugin-relay"
  4. graphql`
  5. query UserQuery {
  6. viewer {
  7. id
  8. }
  9. }
  10. `;

To learn more about Relay, check out its documentation.