UNPKG

@graphql-eslint/eslint-plugin

Version:
67 lines (66 loc) 3.14 kB
"use strict"; var __create = Object.create; var __defProp = Object.defineProperty; var __getOwnPropDesc = Object.getOwnPropertyDescriptor; var __getOwnPropNames = Object.getOwnPropertyNames; var __getProtoOf = Object.getPrototypeOf, __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 __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps( // If the importer is in node compatibility mode or this is not an ESM // file that has been converted to a CommonJS file using a Babel- // compatible transform (i.e. "__esModule" has not been set), then set // "default" to the CommonJS "module.exports" for node compatibility. isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: !0 }) : target, mod )), __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: !0 }), mod); var documents_exports = {}; __export(documents_exports, { getDocuments: () => getDocuments }); module.exports = __toCommonJS(documents_exports); var import_node_path = require("node:path"), import_debug = __toESM(require("debug")), import_fast_glob = __toESM(require("fast-glob")), import_cache = require("./cache.js"); const debug = (0, import_debug.default)("graphql-eslint:operations"), operationsCache = new import_cache.ModuleCache(), handleVirtualPath = (documents) => { const filepathMap = /* @__PURE__ */ Object.create(null); return documents.map((source) => { const location = source.location; if ([".gql", ".graphql"].some((extension) => location.endsWith(extension))) return source; filepathMap[location] ??= -1; const index = filepathMap[location] += 1; return { ...source, location: (0, import_node_path.resolve)(location, `${index}_document.graphql`) }; }); }, getDocuments = (project) => { const documentsKey = project.documents; if (!documentsKey) return []; let siblings = operationsCache.get(documentsKey); if (!siblings) { debug("Loading operations from %o", project.documents); const documents = project.loadDocumentsSync(project.documents, { skipGraphQLImport: !0, pluckConfig: project.extensions.pluckConfig }); if (debug.enabled) { debug("Loaded %d operations", documents.length); const operationsPaths = import_fast_glob.default.sync(project.documents, { absolute: !0 }); debug("Operations pointers %O", operationsPaths); } siblings = handleVirtualPath(documents), operationsCache.set(documentsKey, siblings); } return siblings; }; // Annotate the CommonJS export names for ESM import in node: 0 && (module.exports = { getDocuments });