Skip to content

Commit

Permalink
fix error report for no-deprecated rule (#739)
Browse files Browse the repository at this point in the history
  • Loading branch information
Dimitri POSTOLOV committed Oct 31, 2021
1 parent 7aa8157 commit ced6789
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 9 deletions.
5 changes: 5 additions & 0 deletions .changeset/young-cups-shout.md
@@ -0,0 +1,5 @@
---
'@graphql-eslint/eslint-plugin': patch
---

fix error report for `no-deprecated` rule
12 changes: 7 additions & 5 deletions packages/plugin/src/rules/no-deprecated.ts
@@ -1,4 +1,4 @@
import { requireGraphQLSchemaFromContext } from '../utils';
import { getLocation, requireGraphQLSchemaFromContext } from '../utils';
import { GraphQLESLintRule } from '../types';

const NO_DEPRECATED = 'NO_DEPRECATED';
Expand Down Expand Up @@ -47,8 +47,8 @@ const rule: GraphQLESLintRule<[], true> = {
mutation {
changeSomething(
type: OLD # This is deprecated, so you'll get an error
) {
...
) {
...
}
}
`,
Expand Down Expand Up @@ -87,8 +87,9 @@ const rule: GraphQLESLintRule<[], true> = {

if (typeInfo && typeInfo.enumValue) {
if (typeInfo.enumValue.isDeprecated) {
const enumValueName = node.value;
context.report({
loc: node.loc,
loc: getLocation(node.loc, enumValueName),
messageId: NO_DEPRECATED,
data: {
type: 'enum value',
Expand All @@ -104,8 +105,9 @@ const rule: GraphQLESLintRule<[], true> = {

if (typeInfo && typeInfo.fieldDef) {
if (typeInfo.fieldDef.isDeprecated) {
const fieldName = node.name.value;
context.report({
loc: node.loc,
loc: getLocation(node.loc, fieldName),
messageId: NO_DEPRECATED,
data: {
type: 'field',
Expand Down
Expand Up @@ -2,20 +2,20 @@

exports[` 1`] = `
> 1 | mutation { something(t: OLD) }
| ^ This enum value is marked as deprecated in your GraphQL schema (reason: No longer supported)
| ^^^ This enum value is marked as deprecated in your GraphQL schema (reason: No longer supported)
`;

exports[` 2`] = `
> 1 | mutation { something(t: OLD_WITH_REASON) }
| ^ This enum value is marked as deprecated in your GraphQL schema (reason: test)
| ^^^^^^^^^^^^^^^ This enum value is marked as deprecated in your GraphQL schema (reason: test)
`;

exports[` 3`] = `
> 1 | query { oldField }
| ^ This field is marked as deprecated in your GraphQL schema (reason: No longer supported)
| ^^^^^^^^ This field is marked as deprecated in your GraphQL schema (reason: No longer supported)
`;

exports[` 4`] = `
> 1 | query { oldFieldWithReason }
| ^ This field is marked as deprecated in your GraphQL schema (reason: test)
| ^^^^^^^^^^^^^^^^^^ This field is marked as deprecated in your GraphQL schema (reason: test)
`;

0 comments on commit ced6789

Please sign in to comment.