Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
async function normalize() {
/* Load Require extensions */
const requireExtensions = normalizeInstanceOrArray(config.require);
for (const mod of requireExtensions) {
await import(mod);
}
/* Root templates-config */
rootConfig = config.config || {};
/* Normalize root "schema" field */
rootSchemas = normalizeInstanceOrArray(config.schema);
/* Normalize root "documents" field */
rootDocuments = normalizeInstanceOrArray(config.documents);
/* Normalize "generators" field */
const generateKeys = Object.keys(config.generates);
async function normalize() {
/* Load Require extensions */
const requireExtensions = normalizeInstanceOrArray(config.require);
for (const mod of requireExtensions) {
await import(mod);
}
/* Root templates-config */
rootConfig = config.config || {};
/* Normalize root "schema" field */
rootSchemas = normalizeInstanceOrArray(config.schema);
/* Normalize root "documents" field */
rootDocuments = normalizeInstanceOrArray(config.documents);
/* Normalize "generators" field */
const generateKeys = Object.keys(config.generates);
if (generateKeys.length === 0) {
throw new DetailedError(
'Invalid Codegen Configuration!',
`
Please make sure that your codegen config file contains the "generates" field, with a specification for the plugins you need.
It should looks like that:
schema:
export const createWatcher = (initalContext: CodegenContext, onNext: (result: Types.FileOutput[]) => Promise) => {
debugLog(`[Watcher] Starting watcher...`);
let config: Types.Config = initalContext.getConfig();
const files: string[] = [initalContext.filepath].filter(a => a);
const documents = normalizeInstanceOrArray(config.documents);
const schemas = normalizeInstanceOrArray(config.schema);
// Add schemas and documents from "generates"
Object.keys(config.generates)
.map(filename => normalizeOutputParam(config.generates[filename]))
.forEach(conf => {
schemas.push(...normalizeInstanceOrArray(conf.schema));
documents.push(...normalizeInstanceOrArray(conf.documents));
});
if (documents) {
documents.forEach(doc => {
if (typeof doc === 'string') {
files.push(doc);
} else {
files.push(...Object.keys(doc));
}
export const createWatcher = (initalContext: CodegenContext, onNext: (result: Types.FileOutput[]) => Promise) => {
debugLog(`[Watcher] Starting watcher...`);
let config: Types.Config = initalContext.getConfig();
const files: string[] = [initalContext.filepath].filter(a => a);
const documents = normalizeInstanceOrArray(config.documents);
const schemas = normalizeInstanceOrArray(config.schema);
// Add schemas and documents from "generates"
Object.keys(config.generates)
.map(filename => normalizeOutputParam(config.generates[filename]))
.forEach(conf => {
schemas.push(...normalizeInstanceOrArray(conf.schema));
documents.push(...normalizeInstanceOrArray(conf.documents));
});
if (documents) {
documents.forEach(doc => {
if (typeof doc === 'string') {
files.push(doc);
} else {
files.push(...Object.keys(doc));
async function normalize() {
/* Load Require extensions */
const requireExtensions = normalizeInstanceOrArray(config.require);
for (const mod of requireExtensions) {
await import(mod);
}
/* Root templates-config */
rootConfig = config.config || {};
/* Normalize root "schema" field */
rootSchemas = normalizeInstanceOrArray(config.schema);
/* Normalize root "documents" field */
rootDocuments = normalizeInstanceOrArray(config.documents);
/* Normalize "generators" field */
const generateKeys = Object.keys(config.generates);
if (generateKeys.length === 0) {
throw new DetailedError(
'Invalid Codegen Configuration!',
`
Please make sure that your codegen config file contains the "generates" field, with a specification for the plugins you need.
It should looks like that:
schema:
- my-schema.graphql
generates:
my-file.ts:
task: () => {
const outputFileTemplateConfig = outputConfig.config || {};
const outputDocuments: Types.DocumentFile[] = [];
let outputSchemaAst: GraphQLSchema;
let outputSchema: DocumentNode;
const outputSpecificSchemas = normalizeInstanceOrArray(outputConfig.schema);
const outputSpecificDocuments = normalizeInstanceOrArray(outputConfig.documents);
return new Listr(
[
{
title: 'Load GraphQL schemas',
task: wrapTask(async () => {
debugLog(`[CLI] Loading Schemas`);
const schemaPointerMap: any = {};
const allSchemaUnnormalizedPointers = [...rootSchemas, ...outputSpecificSchemas];
for (const unnormalizedPtr of allSchemaUnnormalizedPointers) {
if (typeof unnormalizedPtr === 'string') {
schemaPointerMap[unnormalizedPtr] = {};
} else if (typeof unnormalizedPtr === 'object') {
Object.assign(schemaPointerMap, unnormalizedPtr);
}
.forEach(conf => {
schemas.push(...normalizeInstanceOrArray(conf.schema));
documents.push(...normalizeInstanceOrArray(conf.documents));
});
if (typeof doc === 'string') {
files.push(doc);
} else {
files.push(...Object.keys(doc));
}
});
}
schemas.forEach((schema: string) => {
if (isGlob(schema) || isValidPath(schema)) {
files.push(schema);
}
});
if (typeof config.watch !== 'boolean') {
files.push(...normalizeInstanceOrArray(config.watch));
}
let watcher: FSWatcher;
const runWatcher = async () => {
const chokidar = await import('chokidar');
let isShutdown = false;
const debouncedExec = debounce(() => {
if (!isShutdown) {
executeCodegen(initalContext)
.then(onNext, () => Promise.resolve())
.then(() => emitWatching());
}
}, 100);
emitWatching();
.forEach(conf => {
schemas.push(...normalizeInstanceOrArray(conf.schema));
documents.push(...normalizeInstanceOrArray(conf.documents));
});