Spaces:
Running
Running
File size: 4,059 Bytes
d4b85c0 |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 |
'use strict';
Object.defineProperty(exports, '__esModule', {
value: true,
});
exports.NoDeprecatedCustomRule = NoDeprecatedCustomRule;
var _invariant = require('../../../jsutils/invariant.js');
var _GraphQLError = require('../../../error/GraphQLError.js');
var _definition = require('../../../type/definition.js');
/**
* No deprecated
*
* A GraphQL document is only valid if all selected fields and all used enum values have not been
* deprecated.
*
* Note: This rule is optional and is not part of the Validation section of the GraphQL
* Specification. The main purpose of this rule is detection of deprecated usages and not
* necessarily to forbid their use when querying a service.
*/
function NoDeprecatedCustomRule(context) {
return {
Field(node) {
const fieldDef = context.getFieldDef();
const deprecationReason =
fieldDef === null || fieldDef === void 0
? void 0
: fieldDef.deprecationReason;
if (fieldDef && deprecationReason != null) {
const parentType = context.getParentType();
parentType != null || (0, _invariant.invariant)(false);
context.reportError(
new _GraphQLError.GraphQLError(
`The field ${parentType.name}.${fieldDef.name} is deprecated. ${deprecationReason}`,
{
nodes: node,
},
),
);
}
},
Argument(node) {
const argDef = context.getArgument();
const deprecationReason =
argDef === null || argDef === void 0
? void 0
: argDef.deprecationReason;
if (argDef && deprecationReason != null) {
const directiveDef = context.getDirective();
if (directiveDef != null) {
context.reportError(
new _GraphQLError.GraphQLError(
`Directive "@${directiveDef.name}" argument "${argDef.name}" is deprecated. ${deprecationReason}`,
{
nodes: node,
},
),
);
} else {
const parentType = context.getParentType();
const fieldDef = context.getFieldDef();
(parentType != null && fieldDef != null) ||
(0, _invariant.invariant)(false);
context.reportError(
new _GraphQLError.GraphQLError(
`Field "${parentType.name}.${fieldDef.name}" argument "${argDef.name}" is deprecated. ${deprecationReason}`,
{
nodes: node,
},
),
);
}
}
},
ObjectField(node) {
const inputObjectDef = (0, _definition.getNamedType)(
context.getParentInputType(),
);
if ((0, _definition.isInputObjectType)(inputObjectDef)) {
const inputFieldDef = inputObjectDef.getFields()[node.name.value];
const deprecationReason =
inputFieldDef === null || inputFieldDef === void 0
? void 0
: inputFieldDef.deprecationReason;
if (deprecationReason != null) {
context.reportError(
new _GraphQLError.GraphQLError(
`The input field ${inputObjectDef.name}.${inputFieldDef.name} is deprecated. ${deprecationReason}`,
{
nodes: node,
},
),
);
}
}
},
EnumValue(node) {
const enumValueDef = context.getEnumValue();
const deprecationReason =
enumValueDef === null || enumValueDef === void 0
? void 0
: enumValueDef.deprecationReason;
if (enumValueDef && deprecationReason != null) {
const enumTypeDef = (0, _definition.getNamedType)(
context.getInputType(),
);
enumTypeDef != null || (0, _invariant.invariant)(false);
context.reportError(
new _GraphQLError.GraphQLError(
`The enum value "${enumTypeDef.name}.${enumValueDef.name}" is deprecated. ${deprecationReason}`,
{
nodes: node,
},
),
);
}
},
};
}
|