1 | import { GraphQLError } from '../error/GraphQLError';
|
2 | import { visit, visitWithTypeInfo } from '../language/visitor';
|
3 | import { getNamedType } from '../type/definition';
|
4 | import { TypeInfo } from './TypeInfo';
|
5 |
|
6 |
|
7 |
|
8 |
|
9 |
|
10 |
|
11 | export function findDeprecatedUsages(schema, ast) {
|
12 | var errors = [];
|
13 | var typeInfo = new TypeInfo(schema);
|
14 | visit(ast, visitWithTypeInfo(typeInfo, {
|
15 | Field: function Field(node) {
|
16 | var fieldDef = typeInfo.getFieldDef();
|
17 |
|
18 | if (fieldDef && fieldDef.isDeprecated) {
|
19 | var parentType = typeInfo.getParentType();
|
20 |
|
21 | if (parentType) {
|
22 | var reason = fieldDef.deprecationReason;
|
23 | errors.push(new GraphQLError("The field ".concat(parentType.name, ".").concat(fieldDef.name, " is deprecated.") + (reason ? ' ' + reason : ''), node));
|
24 | }
|
25 | }
|
26 | },
|
27 | EnumValue: function EnumValue(node) {
|
28 | var enumVal = typeInfo.getEnumValue();
|
29 |
|
30 | if (enumVal && enumVal.isDeprecated) {
|
31 | var type = getNamedType(typeInfo.getInputType());
|
32 |
|
33 | if (type) {
|
34 | var reason = enumVal.deprecationReason;
|
35 | errors.push(new GraphQLError("The enum value ".concat(type.name, ".").concat(enumVal.name, " is deprecated.") + (reason ? ' ' + reason : ''), node));
|
36 | }
|
37 | }
|
38 | }
|
39 | }));
|
40 | return errors;
|
41 | }
|