@graphql-eslint/eslint-plugin
Version:
GraphQL plugin for ESLint
46 lines (43 loc) • 2.07 kB
JavaScript
;Object.defineProperty(exports, "__esModule", {value: true}); function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }var _nodepath = require('node:path'); var _nodepath2 = _interopRequireDefault(_nodepath);
var _debug = require('debug'); var _debug2 = _interopRequireDefault(_debug);
var _fastglob = require('fast-glob'); var _fastglob2 = _interopRequireDefault(_fastglob);
var _cachejs = require('./cache.js');
const debug = _debug2.default.call(void 0, "graphql-eslint:operations"), operationsCache = new (0, _cachejs.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,
// When using glob pattern e.g. `**/*.gql` location contains always forward slashes even on
// Windows
location: _nodepath2.default.resolve(location)
};
filepathMap[location] ??= -1;
const index = filepathMap[location] += 1;
return {
...source,
location: _nodepath2.default.resolve(location, `${index}_document.graphql`)
};
});
}, getDocuments = exports.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 = _fastglob2.default.sync(project.documents, { absolute: !0 });
debug("Operations pointers %O", operationsPaths);
}
siblings = handleVirtualPath(documents), operationsCache.set(documentsKey, siblings);
}
return siblings;
};
exports.getDocuments = getDocuments;