@graphql-eslint/eslint-plugin
Version:
GraphQL plugin for ESLint
29 lines (28 loc) • 968 B
JavaScript
import debugFactory from 'debug';
import fg from 'fast-glob';
import { GraphQLSchema } from 'graphql';
import { ModuleCache } from './cache.js';
const schemaCache = new ModuleCache();
const debug = debugFactory('graphql-eslint:schema');
export 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 GraphQLSchema);
const schemaPaths = fg.sync(project.schema, { absolute: true });
debug('Schema pointers %O', schemaPaths);
}
schemaCache.set(schemaKey, schema);
return schema;
}