@graphql-eslint/eslint-plugin
Version:
GraphQL plugin for ESLint
34 lines (33 loc) • 1.24 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.getSchema = void 0;
const tslib_1 = require("tslib");
const debug_1 = tslib_1.__importDefault(require("debug"));
const fast_glob_1 = tslib_1.__importDefault(require("fast-glob"));
const graphql_1 = require("graphql");
const cache_js_1 = require("./cache.js");
const schemaCache = new cache_js_1.ModuleCache();
const debug = (0, debug_1.default)('graphql-eslint:schema');
function getSchema(project, schemaOptions) {
const schemaKey = project.schema;
if (!schemaKey) {
return null;
}
const cache = schemaCache.get(schemaKey);
if (cache) {
return cache;
}
debug('Loading schema from %o', project.schema);
const schema = project.loadSchemaSync(project.schema, 'GraphQLSchema', {
...schemaOptions,
pluckConfig: project.extensions.pluckConfig,
});
if (debug.enabled) {
debug('Schema loaded: %o', schema instanceof graphql_1.GraphQLSchema);
const schemaPaths = fast_glob_1.default.sync(project.schema, { absolute: true });
debug('Schema pointers %O', schemaPaths);
}
schemaCache.set(schemaKey, schema);
return schema;
}
exports.getSchema = getSchema;