UNPKG

1.61 kBJavaScriptView Raw
1"use strict";
2
3Object.defineProperty(exports, "__esModule", {
4 value: true
5});
6exports.findDeprecatedUsages = findDeprecatedUsages;
7
8var _GraphQLError = require("../error/GraphQLError");
9
10var _visitor = require("../language/visitor");
11
12var _definition = require("../type/definition");
13
14var _TypeInfo = require("./TypeInfo");
15
16/**
17 * A validation rule which reports deprecated usages.
18 *
19 * Returns a list of GraphQLError instances describing each deprecated use.
20 */
21function 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}