UNPKG

@graphql-eslint/eslint-plugin

Version:
56 lines (55 loc) 1.71 kB
import "./chunk-BMTV3EA2.js"; import { dirname } from "path"; import { CodeFileLoader } from "@graphql-tools/code-file-loader"; import debugFactory from "debug"; import { GraphQLConfig, loadConfigSync } from "graphql-config"; const debug = debugFactory("graphql-eslint:graphql-config"); let graphQLConfig; function loadOnDiskGraphQLConfig(filePath) { return loadConfigSync({ // load config relative to the file being linted rootDir: dirname(filePath), throwOnEmpty: false, throwOnMissing: false, extensions: [codeFileLoaderExtension] }); } function loadGraphQLConfig(options) { if (graphQLConfig) { return graphQLConfig; } const onDiskConfig = !options.skipGraphQLConfig && loadOnDiskGraphQLConfig(options.filePath); debug("options.skipGraphQLConfig: %o", options.skipGraphQLConfig); if (onDiskConfig) { debug("Graphql-config path %o", onDiskConfig.filepath); } const configOptions = options.projects ? { projects: options.projects } : { schema: options.schema || "", // if `schema` is `undefined` will throw error `Project 'default' not found` documents: options.documents, extensions: options.extensions, include: options.include, exclude: options.exclude }; graphQLConfig = onDiskConfig || new GraphQLConfig( { config: configOptions, filepath: "virtual-config" }, [codeFileLoaderExtension] ); return graphQLConfig; } const codeFileLoaderExtension = (api) => { const { schema, documents } = api.loaders; schema.register(new CodeFileLoader()); documents.register(new CodeFileLoader()); return { name: "graphql-eslint-loaders" }; }; export { loadGraphQLConfig, loadOnDiskGraphQLConfig };