Skip to content
GitLab
Projects Groups Snippets
  • /
  • Help
    • Help
    • Support
    • Community forum
    • Submit feedback
    • Contribute to GitLab
  • Sign in / Register
  • C create-react-app
  • Project information
    • Project information
    • Activity
    • Labels
    • Members
  • Repository
    • Repository
    • Files
    • Commits
    • Branches
    • Tags
    • Contributors
    • Graph
    • Compare
  • Issues 1,547
    • Issues 1,547
    • List
    • Boards
    • Service Desk
    • Milestones
  • Merge requests 417
    • Merge requests 417
  • CI/CD
    • CI/CD
    • Pipelines
    • Jobs
    • Schedules
  • Deployments
    • Deployments
    • Environments
    • Releases
  • Packages and registries
    • Packages and registries
    • Package Registry
    • Infrastructure Registry
  • Monitor
    • Monitor
    • Incidents
  • Analytics
    • Analytics
    • Value stream
    • CI/CD
    • Repository
  • Wiki
    • Wiki
  • Snippets
    • Snippets
  • Activity
  • Graph
  • Create a new issue
  • Jobs
  • Commits
  • Issue Boards
Collapse sidebar
  • Meta
  • create-react-app
  • Merge requests
  • !3909

Add loader for .graphql files

  • Review changes

  • Download
  • Email patches
  • Plain diff
Merged Administrator requested to merge github/fork/petetnt/graphql-loader into next Jan 23, 2018
  • Overview 24
  • Commits 17
  • Pipelines 0
  • Changes 11

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 with yarn start
  • ✅ works after building with yarn 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 with graphql-tag/loader
  • Updates the README.md and User 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

Assignee
Assign to
Reviewers
Request review from
Time tracking
Source branch: github/fork/petetnt/graphql-loader