Created by: petetnt
Important notice
The implicit loader was removed in favor of the macro approach, which gives much more flexibility (for example using different graphql-js version instead of the one shipped with CRA) with little to no code changes.
You can load .gql and .graphql files by installing the graphql-tag.macro from npm and using it like this:
import { loader } from 'graphql.macro';
const A = loader('./assets/graphql.graphql');
The loader statement gets replaced with the actual graphql-tag object on build time and the precomputed object also lowers performance overhead by bit, so it behaves like the loader in this PR did!
OLD PR
This PR adds the .graphql
file loading feature discussed in https://github.com/facebook/create-react-app/issues/3873.
A POC of the concept can be found in https://github.com/petetnt/cra-pr-3909-poc/ (might need to link to react-scripts
after installing). Tested the following things:
-
✅ works while developing withyarn start
-
✅ works after building withyarn build
Also looked at the output after ejecting and it looks correct, couldn't test it yet though after yarn eject
due to some version issues
The PR adds following things:
- Ability to load and preprocess
.graphql
and.gql
files withgraphql-tag/loader
- Updates the
README.md
andUser guide
with descriptions and usage - Adds a
jest
transform so the.graphql
files work with tests too
Tested it out with react-apollo
and it worked beautifully. Should work with Relay Modern
too, but prerequisite for it is https://github.com/facebook/create-react-app/pull/2343