Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
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");
}
// 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!");
}
return async (schema) => {
const config = await createConfigFromSchema(schema)
const output = await codegen(config)
return fs.writeFile(config.filename, output)
}
}
const process = async (outputArgs: Types.GenerateOptions) => {
const output = await codegen(outputArgs);
result.push({
filename: outputArgs.filename,
content: output,
hooks: outputConfig.hooks || {},
});
};
return async (schema) => {
const config = await createConfigFromSchema(schema)
const output = await codegen(config)
return fs.writeFile(config.filename, output)
}
}