Skip to content

Commit

Permalink
fix: disable gql files linting by default
Browse files Browse the repository at this point in the history
  • Loading branch information
Guillaume Chau committed Oct 19, 2019
1 parent c1d7214 commit 709dd09
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 13 deletions.
2 changes: 2 additions & 0 deletions docs/guide/configuration.md
Original file line number Diff line number Diff line change
Expand Up @@ -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) */

Expand Down
36 changes: 23 additions & 13 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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')
Expand All @@ -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
Expand Down

0 comments on commit 709dd09

Please sign in to comment.