UNPKG

@vanta-inc/eslint-plugin-vanta

Version:
48 lines (47 loc) 2.03 kB
"use strict"; /** * @fileoverview Lint rule to ensure that all lists are either paginated as part of connections, or marked as explicitly not needing pagination. */ Object.defineProperty(exports, "__esModule", { value: true }); var graphqlutils_1 = require("../utils/graphqlutils"); var SHORT_LIST_DIRECTIVE = "tinylist"; var rule = { meta: { type: "problem", docs: { // @ts-ignore description: "Ensures that all list types are edges in connections, or marked as " + SHORT_LIST_DIRECTIVE, category: "Schema", url: "https://github.com/VantaInc/eslint-plugin-vanta/blob/main/docs/rules/all-lists-in-connections.md", }, }, create: function (context) { var hasShortListDirective = function (directives) { return Boolean(directives === null || directives === void 0 ? void 0 : directives.find(function (x) { return x.name.value === SHORT_LIST_DIRECTIVE; })); }; return { FieldDefinition: function (node) { // if it has the directive, it's allowed to be a list if (hasShortListDirective(node.directives)) { return; } // if it's an edge type on a connection, it's allowed to be a list // node typings don't include parent but it's there! var nodeParentName = node.parent.name.value; if (node.name.value === "edges" && nodeParentName.endsWith("Connection")) { return; } if (graphqlutils_1.isListType(node.rawNode().type)) { context.report({ node: node, message: "Lists must be paginated or marked as guaranteed to be short using the directive @" + SHORT_LIST_DIRECTIVE + ".", }); return; } }, }; }, }; module.exports = rule; exports.default = rule;