UNPKG

1.84 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 _schema = require('../type/schema');
15
16var _TypeInfo = require('./TypeInfo');
17
18/**
19 * A validation rule which reports deprecated usages.
20 *
21 * Returns a list of GraphQLError instances describing each deprecated use.
22 */
23function findDeprecatedUsages(schema, ast) {
24 var errors = [];
25 var typeInfo = new _TypeInfo.TypeInfo(schema);
26
27 (0, _visitor.visit)(ast, (0, _visitor.visitWithTypeInfo)(typeInfo, {
28 Field: function Field(node) {
29 var fieldDef = typeInfo.getFieldDef();
30 if (fieldDef && fieldDef.isDeprecated) {
31 var parentType = typeInfo.getParentType();
32 if (parentType) {
33 var reason = fieldDef.deprecationReason;
34 errors.push(new _GraphQLError.GraphQLError('The field ' + parentType.name + '.' + fieldDef.name + ' is deprecated.' + (reason ? ' ' + reason : ''), [node]));
35 }
36 }
37 },
38 EnumValue: function EnumValue(node) {
39 var enumVal = typeInfo.getEnumValue();
40 if (enumVal && enumVal.isDeprecated) {
41 var type = (0, _definition.getNamedType)(typeInfo.getInputType());
42 if (type) {
43 var reason = enumVal.deprecationReason;
44 errors.push(new _GraphQLError.GraphQLError('The enum value ' + type.name + '.' + enumVal.name + ' is deprecated.' + (reason ? ' ' + reason : ''), [node]));
45 }
46 }
47 }
48 }));
49
50 return errors;
51} /**
52 * Copyright (c) 2015-present, Facebook, Inc.
53 *
54 * This source code is licensed under the MIT license found in the
55 * LICENSE file in the root directory of this source tree.
56 *
57 *
58 */
\No newline at end of file