How to use the @graphql-codegen/core.codegen function in @graphql-codegen/core

To help you get started, we’ve selected a few @graphql-codegen/core 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 atomist / automation-client / bin / gql-gen.ts View on Github external
if (graphqlFiles && graphqlFiles.length > 0) {
            for (const graphqlFile of graphqlFiles) {
                const content = (await fs.readFile(graphqlFile)).toString();
                const document = parse(content);
                documents.push({
                    content: document,
                    filePath: graphqlFile,
                });
            }
            config.documents = documents;

            await fs.ensureDir(path.dirname(gqlGenOutput));

            // Make all properties optional to retain backwards compatibility
            const typesContent = (await codegen(config)).replace(/ ([a-zA-Z_\-0-9]+): Maybe/g, ` $1?: Maybe`);

            // Write the new types.ts content back out
            await fs.writeFile(gqlGenOutput, `/* tslint:disable */\n\n${typesContent}`, "utf8");
        }
        process.exit(0);

    } catch (e) {
        console.error(`Generating GraphQL types failed: ${e.message}`);
        process.exit(1);
    }
    throw new Error("Should never get here, process.exit() called above");
}
github arackaf / mongo-graphql-starter / src / codeGen / createTypeScriptTypes.js View on Github external
// used by a plugin internally, although the 'typescript' plugin currently returns the string output, rather than writing to a file
    filename: outputFile,
    schema: parse(printSchema(schema)),
    plugins: [{ typescript: { skipTypename: true, avoidOptionals: true } }, { typescriptOperations: {} }],
    documents: [], //needed, for now
    pluginMap: {
      typescript: {
        plugin: typescriptPlugin
      },
      typescriptOperations: {
        plugin: typescriptOperationsPlugin
      }
    }
  };

  const output = await codegen(config);
  fs.writeFileSync(outputFile, additionalTypes + "\n\n" + output);

  console.log("TypeScript Types Generated!");
}
github d4rekanguok / gatsby-typescript / packages / gatsby-plugin-ts / src / graphql-codegen.config.ts View on Github external
return async (schema) => {
    const config = await createConfigFromSchema(schema)
    const output = await codegen(config)
    return fs.writeFile(config.filename, output)
  }
}
github dotansimha / graphql-code-generator / packages / graphql-codegen-cli / src / codegen.ts View on Github external
const process = async (outputArgs: Types.GenerateOptions) => {
                        const output = await codegen(outputArgs);
                        result.push({
                          filename: outputArgs.filename,
                          content: output,
                          hooks: outputConfig.hooks || {},
                        });
                      };
github d4rekanguok / gatsby-typescript / packages / gatsby-plugin-graphql-codegen / src / graphql-codegen.config.ts View on Github external
return async (schema) => {
    const config = await createConfigFromSchema(schema)
    const output = await codegen(config)
    return fs.writeFile(config.filename, output)
  }
}

@graphql-codegen/core

<p align="center"> <img src="https://github.com/dotansimha/graphql-code-generator/blob/master/logo.png?raw=true" /> </p>

MIT
Latest version published 10 months ago

Package Health Score

86 / 100
Full package analysis