apollographql / eslint-plugin-graphql

:vertical_traffic_light: Check your GraphQL query strings against a schema.
https://www.npmjs.com/package/eslint-plugin-graphql
1.21k stars 103 forks source link

Doesn't detect template literal tag in all contexts #12

Closed sgwilym closed 7 years ago

sgwilym commented 8 years ago

Started trying this out today, and it seems like the template literal tag isn't detected in certain context like decorators, meaning incorrect fields aren't flagged by eslint.

Here's a screenshot from the same project, one showing the plugin working with Relay.creatContainer, and the other using a custom relay decorator.

screen shot 2016-04-27 at 11 45 47
stubailo commented 8 years ago

Should be easy to add a test for this and see what's going wrong! I'll get to it today.

stubailo commented 8 years ago

Hmm, are you using the babel-eslint parser? The test I just added seems to pass: https://github.com/apollostack/eslint-plugin-graphql/commit/a040827c431b4a2aed6a12c893c0cf797b074ae9

Also, can you try running eslint from the command line in your repo? Curious if it's an issue with the editor integration, or the plugin itself.

sgwilym commented 8 years ago

Yeah, I'm using babel-eslint. Just ran eslint straight from the project's node_modules folder, and it didn't catch the intentional error in a decorator either. I'm not sure that it matters, but the decorator we're using is https://github.com/charlieschwabacher/relay-decorator.

I think I might have caught another bug though 😀

stubailo commented 8 years ago

Could you send me a complete code snippet I could paste into a test case, and your dependencies? Really want to track this one down.

sgwilym commented 8 years ago

Here's a fresh file in the project I'm working in, with both decorator and normal version:

import React, { Component, View } from 'react-native';
import Relay from 'react-relay';

@relay({
  fragments: {
    user: () => Relay.QL`
      fragment on PublicUser {
        fullName
        nonExistentField
      }
    `
  }
})
class Example extends Component {
  render() {
    return <View/>;
  }
}

class AnotherExample extends Component {
  render() {
    return <View/>;
  }
}

Relay.createContainer(
  AnotherExample,
  {
    fragments: {
      user: () => Relay.QL`
        fragment on PublicUser {
          fullName
          nonExistentField
        }
      `
    }
  }
);

As expected, a warning appears on the version that uses Relay.createContainer, but not for the non-existent field specified in the decorator.

Here's all the dependencies from our project’s package.json — I've left everything in there just in case:

"dependencies": {
    "appium": "1.4.16",
    "babel-core": "6.5.2",
    "babel-eslint": "^6.0.3",
    "babel-polyfill": "6.7.4",
    "babel-preset-react-native-stage-0": "1.0.1",
    "babel-preset-stage-0": "6.5.0",
    "babel-register": "6.5.2",
    "babel-relay-plugin": "0.7.3",
    "babel-relay-plugin-loader": "0.7.1",
    "chai": "3.5.0",
    "change-case": "2.3.1",
    "color": "0.11.1",
    "colors": "1.1.2",
    "commafy": "0.0.5",
    "debounce": "1.0.0",
    "digdug": "krimsonkla/digdug",
    "email-validator": "1.0.4",
    "eslint": "2.3.0",
    "eslint-plugin-babel": "3.1.0",
    "eslint-plugin-classes": "0.1.1",
    "eslint-plugin-import": "1.4.0",
    "eslint-plugin-no-console-log": "1.0.0",
    "eslint-plugin-react": "3.16.1",
    "fbemitter": "2.0.2",
    "flat": "2.0.0",
    "git-rev-sync": "1.4.0",
    "guacamole": "1.2.0-beta",
    "inflection": "1.8.0",
    "jsdom": "6.5.1",
    "minimist": "1.2.0",
    "mkdirp": "0.5.1",
    "mocha": "2.4.5",
    "mocha-eslint": "git+https://github.com/krimsonkla/mocha-eslint.git#master",
    "mocha-teamcity-reporter": "^1.0.0",
    "mockery": "1.4.0",
    "moment": "2.11.2",
    "path-exists": "2.1.0",
    "phoneformat.js": "1.0.3",
    "react": "0.14.6",
    "react-addons-test-utils": "0.14.6",
    "react-dom": "0.14.6",
    "react-element-to-jsx-string": "2.2.0",
    "react-motion": "^0.4.2",
    "react-native": "git+https://github.com/ultralame/react-native.git#cling",
    "react-native-addressbook": "github:sgwilym/react-native-addressbook",
    "react-native-clipboard": "0.0.5",
    "react-native-code-push": "1.10.2-beta",
    "react-native-cookies": "0.0.3",
    "react-native-env": "0.0.5",
    "react-native-fabric": "git+https://github.com/ultralame/react-native-fabric.git#cocoapods-header-search-path",
    "react-native-fbsdkcore": "0.0.8",
    "react-native-fbsdklogin": "0.0.8",
    "react-native-fbsdkshare": "0.0.8",
    "react-native-local-image-manager": "1.0.1",
    "react-native-mixpanel": "0.0.7",
    "react-native-safari-view": "^0.4.0",
    "react-native-swipeout": "^2.0.12",
    "react-relay": "0.7.3",
    "react-test-tree": "1.0.0",
    "relay-decorator": "1.0.3",
    "rowdy": "0.4.0",
    "s3": "4.4.0",
    "selenium-standalone": "5.0.0",
    "sinon": "1.17.3",
    "skin-deep": "0.14.0",
    "table-parser": "0.0.3",
    "truncate": "2.0.0",
    "wd": "0.4.0",
    "ws": "1.0.1"
  },

I'm also using atom 1.7.2 and linter-eslint 7.2.1 as a my editor’s linting plugin.

jnwng commented 7 years ago

closing this for now. @sgwilym please let us know if this is still an issue.