apollographql/eslint-plugin-graphql

No errors or warnings produced from an invalid mutation or query

fnune opened this issue · 4 comments

fnune commented

Hello there!

Here's my ./src/BadMutation.graphql file:

mutation BadMutation($input: Boolean!) {
  thisFieldDoesNotExist(input: $input)
}

Here's my .eslintrc.js file. I've reduced it to the relevant parts only:

const schema = require('./schema/schema.admin.json')

module.exports = {
  extends: [],
  parser: '@typescript-eslint/parser',
  parserOptions: {
    project: 'tsconfig.json',
    sourceType: 'module',
  },
  plugins: ['graphql'],
  rules: {
    'graphql/no-deprecated-fields': [
      'warn',
      {
        env: 'apollo',
        schemaJson: schema,
      },
      {
        env: 'literal',
        schemaJson: schema,
      },
    ],
    'graphql/template-strings': [
      'error',
      {
        env: 'apollo',
        validators: 'all',
        schemaJson: schema,
      },
      {
        env: 'literal',
        validators: 'all',
        schemaJson: schema,
      },
    ],
    'graphql/required-fields': [
      'error',
      {
        env: 'apollo',
        schemaJson: schema,
        requiredFields: ['id'],
      },
      {
        env: 'literal',
        schemaJson: schema,
        requiredFields: ['id'],
      },
    ],
  },
}

My schema file definitely doesn't contain a field Mutation.thisFieldDoesNotExist.

The command I'm running is npx eslint -c ./.eslintrc.js --ext .graphql ./src/BadQuery.graphql --debug

Expected behavior
Errors because I'm using a field that does not exist.

Actual behavior
No errors or warnings appear.

Debugging information
My eslint-plugin-graphql version was 3.1.0.
Here's a reduced version of the logs, keeping only the parts which I think are relevant:

  eslint:config-array-factory Loading JS config file: /home/fausto/Dev/store2be/project-planner/.eslintrc.js +0ms                                                                                                    
  eslint:config-array-factory Loading parser "@typescript-eslint/parser" from /home/fausto/Dev/store2be/project-planner/.eslintrc.js +37ms
  eslint:config-array-factory Loaded: @typescript-eslint/parser@2.4.0 (/home/fausto/Dev/store2be/project-planner/node_modules/@typescript-eslint/parser/dist/parser.js) +2ms
  eslint:config-array-factory Loading plugin "graphql" from /home/fausto/Dev/store2be/project-planner/.eslintrc.js +161ms
  eslint:config-array-factory Loaded: eslint-plugin-graphql@3.1.0 (/home/fausto/Dev/store2be/project-planner/node_modules/eslint-plugin-graphql/lib/index.js) +1ms

  // The correct configuration
  eslint:cascading-config-array-factory Configuration was determined

  // The part related to my BadQuery file
  eslint:ignored-paths   target   = "/home/fausto/Dev/store2be/project-planner/src/BadQuery.graphql" +1ms
  eslint:ignored-paths   base     = "/home/fausto/Dev/store2be/project-planner" +0ms
  eslint:ignored-paths   relative = "src/BadQuery.graphql" +0ms
  eslint:ignored-paths   result   = false +0ms
  eslint:cli-engine Lint /home/fausto/Dev/store2be/project-planner/src/BadQuery.graphql +0ms
  eslint:linter Linting code for /home/fausto/Dev/store2be/project-planner/src/BadQuery.graphql (pass 1) +0ms
  eslint:linter Verify +1ms
  eslint:linter With ConfigArray: /home/fausto/Dev/store2be/project-planner/src/BadQuery.graphql +1ms
  eslint:linter Apply the processor: 'graphql/.graphql' +1ms
  eslint:linter A code block was found: '(unnamed)' +1ms
  eslint:linter Generating fixed text for /home/fausto/Dev/store2be/project-planner/src/BadQuery.graphql (pass 1) +6s
  eslint:source-code-fixer Applying fixes +0ms
  eslint:source-code-fixer shouldFix parameter was false, not attempting fixes +0ms
  eslint:file-enumerator Complete iterating files: ["./src/BadQuery.graphql"] +6s

Similar issue here, @fnune did you manage to fix it?

Update: in my case it was because I specified both env and tagName. This is causing that rule to silently fail internally with out any errors:

// this works 
'graphql/template-strings': [
  'error', {
    // I'm using .graphqlconfig to import the schema
    env: 'literal',
}],
// this fails silently ->  eslint will say the file is valid, no error shown nor thrown
'graphql/template-strings': [
  'error', {
    // I'm using .graphqlconfig to import the schema
    env: 'literal',
    tagName: 'gql'  // <- don't do this
}],

I think this should not happen. I'm not aware was wrong with both using env and tagName but it should not fail silently and this should be considered a bug

fnune commented

That could be filed as a separate issue because in my config there's no mention of tagName.

I haven't had time to look into my initial issue further.

thanks @fnune, I've created a new issue