From 709dd096726ae410e4ce6732bb7edcf35e5e0986 Mon Sep 17 00:00:00 2001 From: Guillaume Chau Date: Sun, 20 Oct 2019 00:46:57 +0200 Subject: [PATCH] fix: disable gql files linting by default --- docs/guide/configuration.md | 2 ++ index.js | 36 +++++++++++++++++++++++------------- 2 files changed, 25 insertions(+), 13 deletions(-) diff --git a/docs/guide/configuration.md b/docs/guide/configuration.md index ba1c817..6bd3d4b 100644 --- a/docs/guide/configuration.md +++ b/docs/guide/configuration.md @@ -58,6 +58,8 @@ module.exports = { enableMocks: true, // Enable Apollo Engine enableEngine: true, + // Enable ESLint for `.gql` files + lintGQL: false, /* Other options (with default values) */ diff --git a/index.js b/index.js index 8e6d0ac..9bd32fb 100644 --- a/index.js +++ b/index.js @@ -18,7 +18,12 @@ const SCHEMA_OPTIONS = { const DEFAULT_GENERATE_OUTPUT = './node_modules/.temp/graphql/schema' +function nullable (value) { + return value == null ? {} : value +} + module.exports = (api, options) => { + const apolloOptions = nullable(nullable(options.pluginOptions).apollo) const useThreads = process.env.NODE_ENV === 'production' && options.parallel const cacheDirectory = api.resolve('node_modules/.cache/cache-loader') const { generateCacheIdentifier } = require('./utils') @@ -44,19 +49,24 @@ module.exports = (api, options) => { .end() if (api.hasPlugin('eslint') && config.module.rules.has('eslint')) { - const id = generateCacheIdentifier(api.resolve('.')) - - config.module - .rule('eslint') - .test(/\.(vue|(j|t)sx?|gql|graphql)$/) - .use('eslint-loader') - .tap(options => { - options.extensions.push('.gql', '.graphql') - return { - ...options, - cacheIdentifier: options.cacheIdentifier + id, - } - }) + if (apolloOptions.lintGQL) { + const id = generateCacheIdentifier(api.resolve('.')) + + config.module + .rule('eslint') + .test(/\.(vue|(j|t)sx?|gql|graphql)$/) + .use('eslint-loader') + .tap(options => { + options.extensions.push('.gql', '.graphql') + return { + ...options, + cacheIdentifier: options.cacheIdentifier + id, + } + }) + } else if (apolloOptions.lintGQL !== false) { + console.log('To enable GQL files in ESLint, set the `pluginOptions.apollo.lintGQL` project option to `true` in `vue.config.js`. Put `false` to hide this message.') + console.log('You also need to install `eslint-plugin-graphql` and enable it in your ESLint configuration.') + } } config.resolve