├── .gitignore ├── LICENSE ├── index.js ├── package-lock.json ├── package.json └── readme.md /.gitignore: -------------------------------------------------------------------------------- 1 | node_modules 2 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2018 Luis Fernando Alvarez D. 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 | -------------------------------------------------------------------------------- /index.js: -------------------------------------------------------------------------------- 1 | module.exports = (nextConfig = {}) => { 2 | return Object.assign({}, nextConfig, { 3 | webpack(config, options) { 4 | if (!options.defaultLoaders) { 5 | throw new Error( 6 | 'This plugin is not compatible with Next.js versions below 5.0.0 https://err.sh/next-plugins/upgrade' 7 | ) 8 | } 9 | 10 | const { dir } = options 11 | 12 | config.module.rules.push({ 13 | test: /\.(graphql|gql)$/, 14 | include: [dir], 15 | exclude: /node_modules/, 16 | use: [ 17 | { 18 | loader: 'graphql-tag/loader' 19 | } 20 | ] 21 | }) 22 | 23 | if (typeof nextConfig.webpack === 'function') { 24 | return nextConfig.webpack(config, options) 25 | } 26 | 27 | return config 28 | } 29 | }) 30 | } 31 | -------------------------------------------------------------------------------- /package-lock.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "next-plugin-graphql", 3 | "version": "0.0.2", 4 | "lockfileVersion": 1, 5 | "requires": true, 6 | "dependencies": { 7 | "graphql-tag": { 8 | "version": "2.10.0", 9 | "resolved": "https://registry.npmjs.org/graphql-tag/-/graphql-tag-2.10.0.tgz", 10 | "integrity": "sha512-9FD6cw976TLLf9WYIUPCaaTpniawIjHWZSwIRZSjrfufJamcXbVVYfN2TWvJYbw0Xf2JjYbl1/f2+wDnBVw3/w==" 11 | } 12 | } 13 | } 14 | -------------------------------------------------------------------------------- /package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "next-plugin-graphql", 3 | "version": "0.0.2", 4 | "description": "Next plugin for .graphql and .gql files using graphql-tag", 5 | "main": "index.js", 6 | "license": "MIT", 7 | "repository": "https://github.com/lfades/next-plugin-graphql", 8 | "dependencies": { 9 | "graphql-tag": "^2.10.0" 10 | } 11 | } 12 | -------------------------------------------------------------------------------- /readme.md: -------------------------------------------------------------------------------- 1 | # Next.js + Graphql 2 | 3 | Use [Graphql](http://graphql.org/) files with [Next.js](https://github.com/zeit/next.js) 4 | 5 | ## Installation 6 | 7 | ```sh 8 | npm install next-plugin-graphql 9 | ``` 10 | 11 | or 12 | 13 | ```sh 14 | yarn add next-plugin-graphql 15 | ``` 16 | 17 | ## Usage 18 | 19 | Create a `next.config.js` in your project 20 | 21 | ```js 22 | // next.config.js 23 | const withGraphql = require('next-plugin-graphql') 24 | module.exports = withGraphql() 25 | ``` 26 | 27 | Optionally you can add your custom Next.js configuration as parameter 28 | 29 | ```js 30 | // next.config.js 31 | const withGraphql = require('next-plugin-graphql') 32 | module.exports = withGraphql({ 33 | webpack(config, options) { 34 | return config 35 | } 36 | }) 37 | ``` 38 | --------------------------------------------------------------------------------