Skip to content

Commit

Permalink
feat: add a check for deprecation errors
Browse files Browse the repository at this point in the history
  • Loading branch information
koddsson committed Nov 9, 2017
1 parent d3de0db commit ba24262
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 0 deletions.
11 changes: 11 additions & 0 deletions src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import {
buildClientSchema,
buildSchema,
specifiedRules as allGraphQLValidators,
findDeprecatedUsages
} from 'graphql';

import {
Expand Down Expand Up @@ -372,6 +373,16 @@ function handleTemplateTag(node, context, schema, env, validators) {
});
return;
}

const deprecationErrors = schema ? findDeprecatedUsages(schema, ast) : [];
if (deprecationErrors && deprecationErrors.length > 0) {
context.report({
node,
message: deprecationErrors[0].message,
loc: locFrom(node, deprecationErrors[0]),
});
return;
}
}

function locFrom(node, error) {
Expand Down
22 changes: 22 additions & 0 deletions test/makeRule.js
Original file line number Diff line number Diff line change
Expand Up @@ -526,6 +526,28 @@ const parserOptions = {
column: 19
}]
},
{
options,
parser,
code: `
@relay({
fragments: {
greetings: () => Relay.QL\`
fragment on Greetings {
hi,
}
\`,
}
})
class HelloApp extends React.Component {}
`,
errors: [{
message: "The field Greetings.hi is deprecated. Please use the more formal greeting 'hello'",
type: 'TaggedTemplateExpression',
line: 6,
column: 19
}]
},

// Example from issue report:
// https://github.com/apollostack/eslint-plugin-graphql/issues/12#issuecomment-215445880
Expand Down
1 change: 1 addition & 0 deletions test/schema.graphql
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ type Film {
type Greetings {
id: ID
hello: String
hi: String @deprecated(reason: "Please use the more formal greeting 'hello'")
}

type Story {
Expand Down

0 comments on commit ba24262

Please sign in to comment.