|
7 | 7 |
|
8 | 8 | 'use strict';
|
9 | 9 |
|
10 |
| -const utils = require('./utils'); |
| 10 | +const { |
| 11 | + getGraphQLAST, |
| 12 | + getLoc, |
| 13 | + hasPrecedingEslintDisableComment |
| 14 | +} = require('./utils'); |
11 | 15 |
|
12 |
| -const getGraphQLAST = utils.getGraphQLAST; |
| 16 | +const ESLINT_DISABLE_COMMENT = ' eslint-disable-next-line relay/unused-fields'; |
13 | 17 |
|
14 | 18 | function getGraphQLFieldNames(graphQLAst) {
|
15 | 19 | const fieldNames = {};
|
16 | 20 |
|
17 | 21 | function walkAST(node, ignoreLevel) {
|
18 | 22 | if (node.kind === 'Field' && !ignoreLevel) {
|
| 23 | + if (hasPrecedingEslintDisableComment(node, ESLINT_DISABLE_COMMENT)) { |
| 24 | + return; |
| 25 | + } |
19 | 26 | const nameNode = node.alias || node.name;
|
20 | 27 | fieldNames[nameNode.value] = nameNode;
|
21 | 28 | }
|
22 | 29 | if (node.kind === 'OperationDefinition') {
|
23 |
| - if (node.operation === 'mutation' || node.operation === 'subscription') { |
| 30 | + if ( |
| 31 | + node.operation === 'mutation' || |
| 32 | + node.operation === 'subscription' || |
| 33 | + hasPrecedingEslintDisableComment(node, ESLINT_DISABLE_COMMENT) |
| 34 | + ) { |
24 | 35 | return;
|
25 | 36 | }
|
26 | 37 | // Ignore fields that are direct children of query as used in mutation
|
@@ -142,7 +153,7 @@ function rule(context) {
|
142 | 153 | ) {
|
143 | 154 | context.report({
|
144 | 155 | node: templateLiteral,
|
145 |
| - loc: utils.getLoc(context, templateLiteral, queriedFields[field]), |
| 156 | + loc: getLoc(context, templateLiteral, queriedFields[field]), |
146 | 157 | message:
|
147 | 158 | `This queries for the field \`${field}\` but this file does ` +
|
148 | 159 | 'not seem to use it directly. If a different file needs this ' +
|
|
0 commit comments