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