From d68ffec848dc65566cb3cae00ac1e9ad5a7cf803 Mon Sep 17 00:00:00 2001 From: Patrick Arminio Date: Sat, 3 Mar 2018 22:16:05 +0000 Subject: [PATCH 1/3] Add loader for .graqhql files See: https://github.com/facebook/create-react-app/pull/3909 --- .../config/jest/graphqlTransform.js | 18 ++++ .../config/webpack.config.dev.js | 5 + .../kitchensink/integration/webpack.test.js | 10 ++ .../fixtures/kitchensink/src/App.js | 101 +++++++++++------- .../src/features/webpack/GraphQLInclusion.js | 15 +++ .../features/webpack/GraphQLInclusion.test.js | 17 +++ .../features/webpack/assets/graphql.graphql | 5 + packages/react-scripts/package.json | 2 + .../scripts/utils/createJestConfig.js | 3 +- packages/react-scripts/template/README.md | 33 +++++- 10 files changed, 167 insertions(+), 42 deletions(-) create mode 100644 packages/react-scripts/config/jest/graphqlTransform.js create mode 100644 packages/react-scripts/fixtures/kitchensink/src/features/webpack/GraphQLInclusion.js create mode 100644 packages/react-scripts/fixtures/kitchensink/src/features/webpack/GraphQLInclusion.test.js create mode 100644 packages/react-scripts/fixtures/kitchensink/src/features/webpack/assets/graphql.graphql diff --git a/packages/react-scripts/config/jest/graphqlTransform.js b/packages/react-scripts/config/jest/graphqlTransform.js new file mode 100644 index 000000000..95d4c5fd7 --- /dev/null +++ b/packages/react-scripts/config/jest/graphqlTransform.js @@ -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); + }, +}; \ No newline at end of file diff --git a/packages/react-scripts/config/webpack.config.dev.js b/packages/react-scripts/config/webpack.config.dev.js index 924e3e4f0..346c660e8 100644 --- a/packages/react-scripts/config/webpack.config.dev.js +++ b/packages/react-scripts/config/webpack.config.dev.js @@ -183,6 +183,11 @@ module.exports = { }, ], }, + // The GraphQL loader preprocesses GraphQL queries in .graphql files. + { + test: /\.(graphql)$/, + loader: 'graphql-tag/loader', + }, // "postcss" loader applies autoprefixer to our CSS. // "css" loader resolves paths in CSS and adds assets as dependencies. // "style" loader turns CSS into JS modules that inject