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