[ Web Proxy ]
URL:
Viewing: https://create-react-app.dev/docs/adding-relay [Back]  [Original]

Adding Relay | Create React App
Skip to main content

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. Set up your project as shown in the Relay documentation, then make sure you have a version of the babel plugin providing the macro.

To add it, run:

npm install --save babel-plugin-relay
Copy

Alternatively you may use yarn:

yarn add babel-plugin-relay
Copy

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

import graphql from 'babel-plugin-relay/macro';
// instead of:
// import { graphql } from "babel-plugin-relay"

graphql`
query UserQuery {
viewer {
id
}
}
`;
Copy

To learn more about Relay, check out its documentation.


Web Proxy Viewer  |  New URL  |  Original Page