-
-
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
Merged
Merged
Changes from all commits
Commits
Show all changes
17 commits
Select commit
Hold shift + click to select a range
7b278c1
Add graphql loader to webpack config
petetnt 123e89e
Update README.md
petetnt c64c25c
Update react-scripts README.md
petetnt 53e215f
Add graphql jest transform
petetnt d1dd2a8
Add integration tests, pin versions in package.json
petetnt f32d3fd
Tests expect regexp matchers
petetnt 3a14cd1
Use strict equal test instead
petetnt 435ece0
Escaping is hard
petetnt 0860029
Add comment for signifying a different file
petetnt eeed28f
Update docs
iansu 683d818
Merge next into branch
iansu e68515d
Fix jest config
iansu 786ee4a
Remove node_modules exclusion
iansu 5198496
Update README.md
petetnt ce2e153
Inline graphql jest transform
petetnt 39d39bc
Update copyright header
petetnt b356d27
Use .graphql extension only
petetnt File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
// @remove-on-eject-begin | ||
/** | ||
* Copyright (c) 2018-present, Facebook, Inc. | ||
* Copyright (c) 2016 Remind | ||
* | ||
* 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 loader = require('graphql-tag/loader'); | ||
|
||
module.exports = { | ||
process(src) { | ||
return loader.call({ cacheable() {} }, src); | ||
}, | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
15 changes: 15 additions & 0 deletions
15
packages/react-scripts/fixtures/kitchensink/src/features/webpack/GraphQLInclusion.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
/** | ||
* 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. | ||
*/ | ||
|
||
import React from 'react'; | ||
import A from './assets/graphql.graphql'; | ||
|
||
export default () => ( | ||
<p id="graphql-inclusion"> | ||
<span>{JSON.stringify(A)}</span> | ||
</p> | ||
); |
17 changes: 17 additions & 0 deletions
17
packages/react-scripts/fixtures/kitchensink/src/features/webpack/GraphQLInclusion.test.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
/** | ||
* 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. | ||
*/ | ||
|
||
import React from 'react'; | ||
import ReactDOM from 'react-dom'; | ||
import GraphQLInclusion from './GraphQLInclusion'; | ||
|
||
describe('graphql files inclusion', () => { | ||
it('renders without crashing', () => { | ||
const div = document.createElement('div'); | ||
ReactDOM.render(<GraphQLInclusion />, div); | ||
}); | ||
}); |
5 changes: 5 additions & 0 deletions
5
packages/react-scripts/fixtures/kitchensink/src/features/webpack/assets/graphql.graphql
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
{ | ||
test(test: "test") { | ||
test | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) | ||
|
@@ -729,6 +730,34 @@ Please be advised that this is also a custom feature of Webpack. | |
**It is not required for React** but many people enjoy it (and React Native uses a similar mechanism for images).<br> | ||
An alternative way of handling static assets is described in the next section. | ||
|
||
## Adding GraphQL files | ||
|
||
> Note: this feature is available with [email protected] and higher. | ||
|
||
If you are using GraphQL, you can **`import` GraphQL files in a JavaScript module**. | ||
|
||
By importing GraphQL queries instead of using a [template tag](https://github.com/apollographql/graphql-tag), they are preprocessed at build time. This eliminates the need to process them on the client at run time. It also allows you to separate your GraphQL queries from your code. You can put a GraphQL query in a file with a `.graphql` extension. | ||
|
||
Here is an example: | ||
|
||
```js | ||
// query.graphql | ||
{ | ||
githubStats(repository: "facebook/react") { | ||
stars | ||
} | ||
} | ||
|
||
// foo.js | ||
|
||
import query from './query.graphql'; | ||
|
||
console.log(query); | ||
// { | ||
// "kind": "Document", | ||
// ... | ||
``` | ||
|
||
## Using the `public` Folder | ||
|
||
>Note: this feature is available with `[email protected]` and higher. | ||
|
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
This needs to have a note about it being supported only in 2.0.0+, like other similar features.
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.
Done ✅