UNPKG

@vanta-inc/eslint-plugin-vanta

Version:
53 lines (52 loc) 1.87 kB
"use strict"; /** * @fileoverview Ensure that all mutations return a nullable type with the suffix "Payload" */ Object.defineProperty(exports, "__esModule", { value: true }); var rule = { meta: { type: "suggestion", docs: { // @ts-ignore description: "All mutations must return a nullable type with the suffix `Payload`", category: "Operations", url: "https://github.com/VantaInc/eslint-plugin-vanta/blob/main/docs/rules/mutations-return-payload.md", }, }, create: function (context) { var validatePayload = function (node) { var _a; if (node.name.value !== "Mutation") { return; } (_a = node.rawNode().fields) === null || _a === void 0 ? void 0 : _a.forEach(function (field) { if (field.type.kind === "ListType") { context.report({ node: node, message: "Mutation payloads must not be list types", }); return; } if (field.type.kind === "NonNullType") { context.report({ node: node, message: "Mutation payloads must be nullable", }); return; } if (!field.type.name.value.endsWith("Payload")) { context.report({ node: node, message: "Mutations must return types with the suffix \"Payload\"", }); } }); }; return { ObjectTypeDefinition: validatePayload, ObjectTypeExtension: validatePayload, }; }, }; module.exports = rule; exports.default = rule;