@graphql-inspector/loaders
Advanced tools
Comparing version 0.0.0-canary.da4bdcc to 0.0.0-canary.f71f99b
@@ -8,33 +8,35 @@ 'use strict'; | ||
class LoadersRegistry { | ||
constructor() { | ||
this.loaders = []; | ||
constructor() { | ||
this.loaders = []; | ||
} | ||
register(loader) { | ||
this.loaders.push(loader); | ||
} | ||
registerModule(loaderName) { | ||
try { | ||
const loader = loadModule(`@graphql-inspector/${loaderName}-loader`); | ||
this.register(loader); | ||
} catch (error) { | ||
console.error(error); | ||
throw new Error(`Couldn't load ${loaderName} loader`); | ||
} | ||
register(loader) { | ||
this.loaders.push(loader); | ||
} | ||
registerModule(loaderName) { | ||
try { | ||
const loader = loadModule(`@graphql-inspector/${loaderName}-loader`); | ||
this.register(loader); | ||
} | ||
catch (error) { | ||
console.error(error); | ||
throw new Error(`Couldn't load ${loaderName} loader`); | ||
} | ||
} | ||
loadSchema(pointer, options = {}) { | ||
return load.loadSchema(pointer, Object.assign({ loaders: this.loaders }, options)); | ||
} | ||
loadDocuments(pointer, options = {}) { | ||
return load.loadDocuments(pointer, Object.assign({ loaders: this.loaders }, options)); | ||
} | ||
} | ||
loadSchema(pointer, options = {}) { | ||
return load.loadSchema(pointer, Object.assign({loaders: this.loaders}, options)); | ||
} | ||
loadDocuments(pointer, options = {}) { | ||
return load.loadDocuments( | ||
pointer, | ||
Object.assign({loaders: this.loaders}, options), | ||
); | ||
} | ||
} | ||
function useLoaders(config) { | ||
const loaders = new LoadersRegistry(); | ||
config.loaders.forEach((loaderName) => loaders.registerModule(loaderName)); | ||
return loaders; | ||
const loaders = new LoadersRegistry(); | ||
config.loaders.forEach((loaderName) => loaders.registerModule(loaderName)); | ||
return loaders; | ||
} | ||
function loadModule(name) { | ||
const mod = require(name); | ||
return mod.default ? mod.default : mod; | ||
const mod = require(name); | ||
return mod.default ? mod.default : mod; | ||
} | ||
@@ -41,0 +43,0 @@ |
@@ -1,13 +0,26 @@ | ||
import { InspectorConfig } from '@graphql-inspector/config'; | ||
import { Source, UniversalLoader, SchemaPointerSingle } from '@graphql-tools/utils'; | ||
import { LoadSchemaOptions, LoadTypedefsOptions } from '@graphql-tools/load'; | ||
import { GraphQLSchema } from 'graphql'; | ||
import {InspectorConfig} from '@graphql-inspector/config'; | ||
import { | ||
Source, | ||
UniversalLoader, | ||
SchemaPointerSingle, | ||
} from '@graphql-tools/utils'; | ||
import {LoadSchemaOptions, LoadTypedefsOptions} from '@graphql-tools/load'; | ||
import {GraphQLSchema} from 'graphql'; | ||
export declare class LoadersRegistry { | ||
private loaders; | ||
register(loader: UniversalLoader): void; | ||
registerModule(loaderName: string): void; | ||
loadSchema(pointer: SchemaPointerSingle, options?: Omit<LoadSchemaOptions, 'loaders'>): Promise<GraphQLSchema>; | ||
loadDocuments(pointer: SchemaPointerSingle, options?: Omit<LoadTypedefsOptions, 'loaders'>): Promise<Source[]>; | ||
private loaders; | ||
register(loader: UniversalLoader): void; | ||
registerModule(loaderName: string): void; | ||
loadSchema( | ||
pointer: SchemaPointerSingle, | ||
options?: Omit<LoadSchemaOptions, 'loaders'>, | ||
): Promise<GraphQLSchema>; | ||
loadDocuments( | ||
pointer: SchemaPointerSingle, | ||
options?: Omit<LoadTypedefsOptions, 'loaders'>, | ||
): Promise<Source[]>; | ||
} | ||
export declare type Loaders = Pick<LoadersRegistry, 'loadSchema' | 'loadDocuments'>; | ||
export declare type Loaders = Pick< | ||
LoadersRegistry, | ||
'loadSchema' | 'loadDocuments' | ||
>; | ||
export declare function useLoaders(config: InspectorConfig): Loaders; |
import { loadSchema, loadDocuments } from '@graphql-tools/load'; | ||
class LoadersRegistry { | ||
constructor() { | ||
this.loaders = []; | ||
constructor() { | ||
this.loaders = []; | ||
} | ||
register(loader) { | ||
this.loaders.push(loader); | ||
} | ||
registerModule(loaderName) { | ||
try { | ||
const loader = loadModule(`@graphql-inspector/${loaderName}-loader`); | ||
this.register(loader); | ||
} catch (error) { | ||
console.error(error); | ||
throw new Error(`Couldn't load ${loaderName} loader`); | ||
} | ||
register(loader) { | ||
this.loaders.push(loader); | ||
} | ||
registerModule(loaderName) { | ||
try { | ||
const loader = loadModule(`@graphql-inspector/${loaderName}-loader`); | ||
this.register(loader); | ||
} | ||
catch (error) { | ||
console.error(error); | ||
throw new Error(`Couldn't load ${loaderName} loader`); | ||
} | ||
} | ||
loadSchema(pointer, options = {}) { | ||
return loadSchema(pointer, Object.assign({ loaders: this.loaders }, options)); | ||
} | ||
loadDocuments(pointer, options = {}) { | ||
return loadDocuments(pointer, Object.assign({ loaders: this.loaders }, options)); | ||
} | ||
} | ||
loadSchema(pointer, options = {}) { | ||
return loadSchema(pointer, Object.assign({loaders: this.loaders}, options)); | ||
} | ||
loadDocuments(pointer, options = {}) { | ||
return loadDocuments( | ||
pointer, | ||
Object.assign({loaders: this.loaders}, options), | ||
); | ||
} | ||
} | ||
function useLoaders(config) { | ||
const loaders = new LoadersRegistry(); | ||
config.loaders.forEach((loaderName) => loaders.registerModule(loaderName)); | ||
return loaders; | ||
const loaders = new LoadersRegistry(); | ||
config.loaders.forEach((loaderName) => loaders.registerModule(loaderName)); | ||
return loaders; | ||
} | ||
function loadModule(name) { | ||
const mod = require(name); | ||
return mod.default ? mod.default : mod; | ||
const mod = require(name); | ||
return mod.default ? mod.default : mod; | ||
} | ||
@@ -36,0 +38,0 @@ |
{ | ||
"name": "@graphql-inspector/loaders", | ||
"version": "0.0.0-canary.da4bdcc", | ||
"version": "0.0.0-canary.f71f99b", | ||
"description": "Loaders in GraphQL Inspector", | ||
"sideEffects": false, | ||
"peerDependencies": { | ||
"@graphql-inspector/config": "0.0.0-canary.da4bdcc", | ||
"@graphql-inspector/config": "0.0.0-canary.f71f99b", | ||
"@graphql-tools/utils": "^6.0.0", | ||
@@ -9,0 +9,0 @@ "graphql": "^0.13.0 || ^14.0.0 || ^15.0.0" |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
105
9068