UNPKG

@graphql-eslint/eslint-plugin

Version:
82 lines (81 loc) 2.62 kB
"use strict"; var __defProp = Object.defineProperty; var __getOwnPropDesc = Object.getOwnPropertyDescriptor; var __getOwnPropNames = Object.getOwnPropertyNames; var __hasOwnProp = Object.prototype.hasOwnProperty; var __export = (target, all) => { for (var name in all) __defProp(target, name, { get: all[name], enumerable: !0 }); }, __copyProps = (to, from, except, desc) => { if (from && typeof from == "object" || typeof from == "function") for (let key of __getOwnPropNames(from)) !__hasOwnProp.call(to, key) && key !== except && __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable }); return to; }; var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: !0 }), mod); var require_nullable_fields_with_oneof_exports = {}; __export(require_nullable_fields_with_oneof_exports, { rule: () => rule }); module.exports = __toCommonJS(require_nullable_fields_with_oneof_exports); var import_graphql = require("graphql"), import_utils = require("../utils.js"); const RULE_ID = "require-nullable-fields-with-oneof", rule = { meta: { type: "suggestion", docs: { category: "Schema", description: "Require `input` or `type` fields to be non-nullable with `@oneOf` directive.", url: `https://the-guild.dev/graphql/eslint/rules/${RULE_ID}`, examples: [ { title: "Incorrect", code: ( /* GraphQL */ ` input Input @oneOf { foo: String! b: Int } ` ) }, { title: "Correct", code: ( /* GraphQL */ ` input Input @oneOf { foo: String bar: Int } ` ) } ] }, messages: { [RULE_ID]: '{{ nodeName }} must be nullable when "@oneOf" is in use' }, schema: [] }, create(context) { return { "Directive[name.value=oneOf]"({ parent }) { if ([ import_graphql.Kind.OBJECT_TYPE_DEFINITION, import_graphql.Kind.INPUT_OBJECT_TYPE_DEFINITION ].includes(parent.kind)) for (const field of parent.fields || []) field.gqlType.kind === import_graphql.Kind.NON_NULL_TYPE && context.report({ node: field.name, messageId: RULE_ID, data: { nodeName: (0, import_utils.getNodeName)(field) } }); } }; } }; // Annotate the CommonJS export names for ESM import in node: 0 && (module.exports = { rule });