UNPKG

@graphql-eslint/eslint-plugin

Version:
94 lines (91 loc) 2.55 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 unique_operation_name_exports = {}; __export(unique_operation_name_exports, { rule: () => rule }); module.exports = __toCommonJS(unique_operation_name_exports); var import_unique_fragment_name = require("./unique-fragment-name.js"); const RULE_ID = "unique-operation-name", rule = { meta: { type: "suggestion", docs: { category: "Operations", description: "Enforce unique operation names across your project.", url: `https://the-guild.dev/graphql/eslint/rules/${RULE_ID}`, requiresSiblings: !0, recommended: !0, examples: [ { title: "Incorrect", code: ( /* GraphQL */ ` # foo.query.graphql query user { user { id } } # bar.query.graphql query user { me { id } } ` ) }, { title: "Correct", code: ( /* GraphQL */ ` # foo.query.graphql query user { user { id } } # bar.query.graphql query me { me { id } } ` ) } ] }, messages: { [RULE_ID]: `Operation named "{{ documentName }}" already defined in: {{ summary }}` }, schema: [] }, create(context) { return { "OperationDefinition[name!=undefined]"(node) { (0, import_unique_fragment_name.checkNode)(context, node, RULE_ID); } }; } }; // Annotate the CommonJS export names for ESM import in node: 0 && (module.exports = { rule });