Create React App

Create React App

  • Docs
  • Help
  • GitHub

›Styles and Assets

Welcome

  • About Docs

Getting Started

  • Getting Started
  • Folder Structure
  • Available Scripts
  • Supported Browsers and Features
  • Updating to New Releases

Development

  • Editor Setup
  • Developing Components in Isolation
  • Analyzing Bundle Size
  • HTTPS in Development

Styles and Assets

  • Adding Stylesheets
  • Adding CSS Modules
  • Adding Sass Stylesheets
  • Adding CSS Reset
  • Post-Processing CSS
  • Adding Images, Fonts, and Files
  • Loading .graphql Files
  • Using the Public Folder
  • Code Splitting

Building your App

  • Installing a Dependency
  • Importing a Component
  • Using Global Variables
  • Adding Bootstrap
  • Adding Flow
  • Adding TypeScript
  • Adding Relay
  • Adding a Router
  • Environment Variables
  • Making a Progressive Web App
  • Creating a Production Build

Testing

  • Running Tests
  • Debugging Tests

Back-End Integration

  • Proxying in Development
  • Fetching Data
  • Integrating with an API
  • Title & Meta Tags

Deployment

  • Deployment

Advanced Usage

  • Can I Use Decorators?
  • Pre-Rendering Static HTML
  • Advanced Configuration
  • Alternatives to Ejecting

Support

  • Troubleshooting
Edit

Loading .graphql Files

To load .gql and .graphql files, first install the graphql and graphql.macro packages by running:

npm install --save graphql graphql.macro

Alternatively you may use yarn:

yarn add graphql graphql.macro

Then, whenever you want to load .gql or .graphql files, import the loader from the macro package:

import { loader } from 'graphql.macro';

const query = loader('./foo.graphql');

And your results get automatically inlined! This means that if the file above, foo.graphql, contains the following:

query {
  hello {
    world
  }
}

The previous example turns into:

const query = {
  'kind': 'Document',
  'definitions': [{
    ...
  }],
  'loc': {
    ...
    'source': {
      'body': '\\\\n  query {\\\\n    hello {\\\\n      world\\\\n    }\\\\n  }\\\\n',
      'name': 'GraphQL request',
      ...
    }
  }
};

You can also use the gql template tag the same way you would use the non-macro version from graphql-tag package with the added benefit of inlined parsing results.

import { gql } from 'graphql.macro';
 
const query = gql`
  query User {
    user(id: 5) {
      lastName
      ...UserEntry1
    }
  }
`;
Last updated on 2019-4-30 by nagman
← Adding Images, Fonts, and FilesUsing the Public Folder →
Create React App
Docs
Get StartedLearn React
Community
Stack OverflowSpectrumTwitterContributor Covenant
More
GitHubStar
Facebook Open Source
Copyright © 2019 Facebook Inc.