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

Query with field that is missing subfields selection causes rule crash #151

Open CraigCav opened 6 years ago

CraigCav commented 6 years ago

ESLint crashes when there's a query with an Object Type field without a selection.

Schema:

type MyObjectType {
  id: ID!
  someField: String
}
type Query {
  fieldName: MyObjectType
}

Query:

{
  fieldName
}

Intended Outcome

Ideally:

[eslint] Field "fieldName" must have a selection since type "MyObjectType" is a GraphQL Object Type.

Actual Outcome

Cannot read property 'selections' of undefined
TypeError: Cannot read property 'selections' of undefined
    at getFieldWasRequestedOnNode (/[...]/node_modules/eslint-plugin-graphql/lib/rules.js:26:28)
    at /[...]/node_modules/eslint-plugin-graphql/lib/rules.js:60:35
    at Array.forEach (<anonymous>)
[...]

Version of eslint-plugin-graphql used: 2.1.1.

Issue Labels

mlnor27 commented 3 years ago

Hey! Any updates on this issue or with the referenced PR?