How to use the @graphql-codegen/plugin-helpers.normalizeInstanceOrArray function in @graphql-codegen/plugin-helpers

To help you get started, we’ve selected a few @graphql-codegen/plugin-helpers examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github dotansimha / graphql-code-generator / packages / graphql-codegen-cli / src / codegen.ts View on Github external
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);
github dotansimha / graphql-code-generator / packages / graphql-codegen-cli / src / codegen.ts View on Github external
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:
github dotansimha / graphql-code-generator / packages / graphql-codegen-cli / src / utils / watcher.ts View on Github external
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));
      }
github dotansimha / graphql-code-generator / packages / graphql-codegen-cli / src / utils / watcher.ts View on Github external
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));
github dotansimha / graphql-code-generator / packages / graphql-codegen-cli / src / codegen.ts View on Github external
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:
github dotansimha / graphql-code-generator / packages / graphql-codegen-cli / src / codegen.ts View on Github external
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);
                        }
github dotansimha / graphql-code-generator / packages / graphql-codegen-cli / src / utils / watcher.ts View on Github external
.forEach(conf => {
      schemas.push(...normalizeInstanceOrArray(conf.schema));
      documents.push(...normalizeInstanceOrArray(conf.documents));
    });
github dotansimha / graphql-code-generator / packages / graphql-codegen-cli / src / utils / watcher.ts View on Github external
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();
github dotansimha / graphql-code-generator / packages / graphql-codegen-cli / src / utils / watcher.ts View on Github external
.forEach(conf => {
      schemas.push(...normalizeInstanceOrArray(conf.schema));
      documents.push(...normalizeInstanceOrArray(conf.documents));
    });