@neo4j/graphql
Version:
A GraphQL to Cypher query execution layer for Neo4j and JavaScript GraphQL implementations
69 lines • 3.74 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.WarnIfAMaxLimitCanBeBypassedThroughInterface = WarnIfAMaxLimitCanBeBypassedThroughInterface;
const neo4j_driver_1 = require("neo4j-driver");
const interface_to_implementing_types_1 = require("../utils/interface-to-implementing-types");
const path_parser_1 = require("../utils/path-parser");
const utils_1 = require("../utils/utils");
function WarnIfAMaxLimitCanBeBypassedThroughInterface() {
return function () {
const entityToMaxLimitMap = new Map();
const interfaceToImplementingTypes = new Map();
const doOnInterface = {
leave(interfaceType) {
const interfaceMax = entityToMaxLimitMap.get(interfaceType.name.value);
if (!interfaceMax) {
return;
}
const concreteThatIsBypassed = ((0, interface_to_implementing_types_1.getInheritedTypeNames)(interfaceType, interfaceToImplementingTypes) || []).find((typeName) => {
const concreteEntityLimit = entityToMaxLimitMap.get(typeName);
if (concreteEntityLimit && concreteEntityLimit.lessThan(interfaceMax)) {
return typeName;
}
});
if (concreteThatIsBypassed) {
console.warn(`Max limit set on ${concreteThatIsBypassed} may be bypassed by its interface ${interfaceType.name.value}. To fix this update the \`@limit\` max value on the interface type. Ignore this message if the behavior is intended!`);
}
},
};
const doOnObject = {
enter(objectType) {
(0, interface_to_implementing_types_1.hydrateInterfaceWithImplementedTypesMap)(objectType, interfaceToImplementingTypes);
},
leave(objectType) {
const concreteMax = entityToMaxLimitMap.get(objectType.name.value);
if (!concreteMax) {
return;
}
const interfaceThatBypasses = ((0, interface_to_implementing_types_1.getInheritedTypeNames)(objectType, interfaceToImplementingTypes) || []).find((typeName) => {
const interfaceMax = entityToMaxLimitMap.get(typeName);
if (!interfaceMax || interfaceMax.greaterThan(concreteMax)) {
return typeName;
}
});
if (interfaceThatBypasses) {
console.warn(`Max limit set on ${objectType.name.value} may be bypassed by its interface ${interfaceThatBypasses}. To fix this update the \`@limit\` max value on the interface type. Ignore this message if the behavior is intended!`);
}
},
};
return {
Directive(directiveNode, _key, _parent, path, ancestors) {
if (directiveNode.name.value !== "limit") {
return;
}
const [, traversedDef] = (0, path_parser_1.getPathToNode)(path, ancestors);
if (!traversedDef) {
return;
}
const maxArg = directiveNode.arguments?.find((a) => a.name.value === "max");
const maxLimit = (0, utils_1.parseArgumentToInt)(maxArg) || neo4j_driver_1.Integer.MAX_SAFE_VALUE;
entityToMaxLimitMap.set(traversedDef.name.value, maxLimit);
},
ObjectTypeDefinition: doOnObject,
ObjectTypeExtension: doOnObject,
InterfaceTypeDefinition: doOnInterface,
InterfaceTypeExtension: doOnInterface,
};
};
}
//# sourceMappingURL=limit-max-can-be-bypassed.js.map