├── .gitignore ├── LICENSE ├── README.md ├── index.js ├── package.json └── yarn.lock /.gitignore: -------------------------------------------------------------------------------- 1 | # Logs 2 | logs 3 | *.log 4 | npm-debug.log* 5 | 6 | # Runtime data 7 | pids 8 | *.pid 9 | *.seed 10 | 11 | # Directory for instrumented libs generated by jscoverage/JSCover 12 | lib-cov 13 | 14 | # Coverage directory used by tools like istanbul 15 | coverage 16 | 17 | # nyc test coverage 18 | .nyc_output 19 | 20 | # Grunt intermediate storage (http://gruntjs.com/creating-plugins#storing-task-files) 21 | .grunt 22 | 23 | # node-waf configuration 24 | .lock-wscript 25 | 26 | # Compiled binary addons (http://nodejs.org/api/addons.html) 27 | build/Release 28 | 29 | # Dependency directories 30 | node_modules 31 | jspm_packages 32 | 33 | # Optional npm cache directory 34 | .npm 35 | 36 | # Optional REPL history 37 | .node_repl_history 38 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2016 Remind 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # jest-transform-graphql 2 | 3 | [`graphql-tag` loader for Webpack](http://dev.apollodata.com/react/webpack.html) lets you keep GraphQL queries in separate files. 4 | 5 | This lib makes those work in Jest. 6 | 7 | ## Usage 8 | 9 | In your package.json, 10 | ``` 11 | "jest": { 12 | "transform": { 13 | "\\.(gql|graphql)$": "jest-transform-graphql", 14 | ".*": "babel-jest" 15 | } 16 | } 17 | ``` 18 | 19 | 20 | You have to include the `.*` matcher because once you define the `transform` property, it overrides that default. 21 | 22 | For more on configuring Jest mappers, see Jest's [Webpack tutorial](https://facebook.github.io/jest/docs/tutorial-webpack.html). 23 | -------------------------------------------------------------------------------- /index.js: -------------------------------------------------------------------------------- 1 | const loader = require('graphql-tag/loader'); 2 | 3 | module.exports = { 4 | process(src) { 5 | // call directly the webpack loader with a mocked context 6 | // as graphql-tag/loader leverages `this.cacheable()` 7 | return loader.call({ cacheable() {} }, src); 8 | }, 9 | }; 10 | -------------------------------------------------------------------------------- /package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "jest-transform-graphql", 3 | "version": "2.1.0", 4 | "description": "Jest transformer for .gql imports", 5 | "main": "index.js", 6 | "scripts": { 7 | "test": "echo \"Error: no test specified\" && exit 1" 8 | }, 9 | "repository": { 10 | "type": "git", 11 | "url": "git+https://github.com/remind101/jest-transform-graphql.git" 12 | }, 13 | "keywords": [ 14 | "jest", 15 | "graphql" 16 | ], 17 | "author": "Turadg Aleahmad", 18 | "license": "ISC", 19 | "bugs": { 20 | "url": "https://github.com/remind101/jest-transform-graphql/issues" 21 | }, 22 | "homepage": "https://github.com/remind101/jest-transform-graphql#readme", 23 | "peerDependencies": { 24 | "graphql-tag": "^2.0.0" 25 | } 26 | } 27 | -------------------------------------------------------------------------------- /yarn.lock: -------------------------------------------------------------------------------- 1 | # THIS IS AN AUTOGENERATED FILE. DO NOT EDIT THIS FILE DIRECTLY. 2 | # yarn lockfile v1 3 | 4 | 5 | graphql-tag@^1.1.2: 6 | version "1.1.2" 7 | resolved "https://registry.yarnpkg.com/graphql-tag/-/graphql-tag-1.1.2.tgz#3e9951d5664e73c1aceee0329f0152bf3020fbb7" 8 | --------------------------------------------------------------------------------