Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix error report for no-deprecated rule #739

Merged
merged 2 commits into from
Oct 31, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
5 changes: 5 additions & 0 deletions .changeset/young-cups-shout.md
Original file line number Diff line number Diff line change
@@ -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
Original file line number Diff line number Diff line change
@@ -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
Original file line number Diff line number Diff line change
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)
`;