UNPKG

@graphql-eslint/eslint-plugin

Version:
42 lines (41 loc) 1.48 kB
import "./chunk-U3TKCM4X.js"; import { resolve } from "node:path"; import debugFactory from "debug"; import fg from "fast-glob"; import { ModuleCache } from "./cache.js"; const debug = debugFactory("graphql-eslint:operations"), operationsCache = new 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: 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 = fg.sync(project.documents, { absolute: !0 }); debug("Operations pointers %O", operationsPaths); } siblings = handleVirtualPath(documents), operationsCache.set(documentsKey, siblings); } return siblings; }; export { getDocuments };