-
-
Notifications
You must be signed in to change notification settings - Fork 26.9k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add loader for .graphql files #3909
Changes from 4 commits
7b278c1
123e89e
c64c25c
53e215f
d1dd2a8
f32d3fd
3a14cd1
435ece0
0860029
eeed28f
683d818
e68515d
786ee4a
5198496
ce2e153
39d39bc
b356d27
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
// @remove-on-eject-begin | ||
/** | ||
* Copyright (c) 2018-present, Facebook, Inc. | ||
* | ||
* This source code is licensed under the MIT license found in the | ||
* LICENSE file in the root directory of this source tree. | ||
*/ | ||
// @remove-on-eject-end | ||
'use strict'; | ||
|
||
const graphqlTransform = require('jest-transform-graphql'); | ||
|
||
module.exports = graphqlTransform; |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -289,6 +289,13 @@ module.exports = { | |
}, | ||
], | ||
}, | ||
// The graphql loader saves GraphQL ASTs processing time on client-side | ||
// and enables queries to be separated from script over .graphql and .gql files. | ||
{ | ||
test: /\.(graphql|gql)$/, | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I prefer us to be opinionated here and pick There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Not sure if I agree there as both extensions have been adopted by the userland at large from my observations. For example the Apollo references both even while usually using I do agree that There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I see from graphql/graphql-spec#203 that There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Removed in d239f56 |
||
exclude: /node_modules/, | ||
loader: 'graphql-tag/loader', | ||
}, | ||
// "file" loader makes sure those assets get served by WebpackDevServer. | ||
// When you `import` an asset, you get its (virtual) filename. | ||
// In production, they would get copied to the `build` folder. | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -44,9 +44,12 @@ | |
"extract-text-webpack-plugin": "3.0.2", | ||
"file-loader": "1.1.6", | ||
"fs-extra": "5.0.0", | ||
"graphql": "^0.12.3", | ||
"graphql-tag": "^2.6.1", | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. we need to pin these new dependencies There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Pinned in d1dd2a8 |
||
"html-webpack-plugin": "2.30.1", | ||
"identity-obj-proxy": "3.0.0", | ||
"jest": "22.1.2", | ||
"jest-transform-graphql": "^2.1.0", | ||
"object-assign": "4.1.1", | ||
"postcss-flexbugs-fixes": "3.2.0", | ||
"postcss-loader": "2.0.10", | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -35,7 +35,10 @@ module.exports = (resolve, rootDir, isEjecting) => { | |
? '<rootDir>/node_modules/babel-jest' | ||
: resolve('config/jest/babelTransform.js'), | ||
'^.+\\.css$': resolve('config/jest/cssTransform.js'), | ||
'^(?!.*\\.(js|jsx|mjs|css|json)$)': resolve( | ||
'^.+\\.(gql|graphql)$': isEjecting | ||
? '<rootDir>/node_modules/jest-transform-graphql' | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Can't this line just be There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I'm not sure about that. This is just copying the pattern used above for There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Hmm. Okay. Let's keep it for now. |
||
: resolve('config/jest/graphqlTransform.js'), | ||
'^(?!.*\\.(js|jsx|mjs|css|json|graphql|gql)$)': resolve( | ||
'config/jest/fileTransform.js' | ||
), | ||
}, | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -27,6 +27,7 @@ You can find the most recent version of this guide [here](https://github.com/fac | |
- [Post-Processing CSS](#post-processing-css) | ||
- [Adding a CSS Preprocessor (Sass, Less etc.)](#adding-a-css-preprocessor-sass-less-etc) | ||
- [Adding Images, Fonts, and Files](#adding-images-fonts-and-files) | ||
- [Adding GraphQL files](#adding-graphql-files) | ||
- [Using the `public` Folder](#using-the-public-folder) | ||
- [Changing the HTML](#changing-the-html) | ||
- [Adding Assets Outside of the Module System](#adding-assets-outside-of-the-module-system) | ||
|
@@ -687,6 +688,30 @@ Now running `npm start` and `npm run build` also builds Sass files. | |
|
||
`node-sass-chokidar` is used here as it addresses these issues. | ||
|
||
## Adding GraphQL files | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This section should be after "Adding Images, ..." |
||
|
||
If you are using GraphQL, you can **import a your GraphQL queries directly in a JavaScript module**. | ||
|
||
By preprocessing the GraphQL queries by importing them instead of using (for example) a [template tag](https://github.com/apollographql/graphql-tag), you save GraphQL ASTs processing time on client-side and enable queries to be separated from script over `.graphql` or `.gql` files. | ||
|
||
Here is an example: | ||
|
||
```js | ||
// query.graphql | ||
{ | ||
githubStats(repository: "facebook/react") { | ||
stars | ||
} | ||
} | ||
|
||
import query from './query.graphql'; | ||
|
||
console.log(query); | ||
// { | ||
// "kind": "Document", | ||
// ... | ||
``` | ||
|
||
## Adding Images, Fonts, and Files | ||
|
||
With Webpack, using static assets like images and fonts works similarly to CSS. | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please add
Copyright (c) 2016 Remind
to the license header of this file, perhttps://unpkg.com/[email protected]/LICENSE
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Does 39d39bc look correct? Not 100% sure how derivative works should be marked.