Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
function enumerationDeclaration(
generator: CodeGenerator,
type: GraphQLEnumType
) {
const { name, description } = type;
const values = type.getValues();
generator.printNewlineIfNeeded();
if (description) {
description.split("\n").forEach(line => {
generator.printOnNewline(`// ${line.trim()}`);
});
}
generator.printOnNewline(`export type ${name} =`);
const nValues = values.length;
sortEnumValues(values).forEach((value, i) => {
if (!value.description || value.description.indexOf("\n") === -1) {
generator.printOnNewline(
` "${value.value}"${i === nValues - 1 ? ";" : " |"}${wrap(
" // ",
value.description || undefined
)}`
);
} else {
if (value.description) {
value.description.split("\n").forEach(line => {
generator.printOnNewline(` // ${line.trim()}`);
});
}
generator.printOnNewline(
` "${value.value}"${i === nValues - 1 ? ";" : " |"}`
);
public enumerationDeclaration(type: GraphQLEnumType) {
const { name, description } = type;
const enumMembers = sortEnumValues(type.getValues()).map(({ value }) => {
return t.TSEnumMember(t.identifier(value), t.stringLiteral(value));
});
const typeAlias = t.exportNamedDeclaration(
t.TSEnumDeclaration(t.identifier(name), enumMembers),
[]
);
if (description) {
typeAlias.leadingComments = [
{
type: "CommentBlock",
value: commentBlockContent(description)
} as t.CommentBlock
];
}
function enumerationDeclaration(
generator: CodeGenerator,
type: GraphQLEnumType
) {
const { name, description } = type;
const values = type.getValues();
generator.printNewlineIfNeeded();
printDocComment(generator, description || undefined);
generator.printOnNewline(`export enum ${name} {`);
sortEnumValues(values).forEach(value => {
printDocComment(generator, value.description || undefined, 1);
generator.printOnNewline(` ${value.value} = "${value.value}",`);
});
generator.printOnNewline(`}`);
generator.printNewline();
}
public enumerationDeclaration(type: GraphQLEnumType) {
const { name, description } = type;
const unionValues = sortEnumValues(type.getValues()).map(({ value }) => {
const type = t.stringLiteralTypeAnnotation(value);
return type;
});
const typeAlias = t.exportNamedDeclaration(
t.typeAlias(
t.identifier(name),
undefined,
t.unionTypeAnnotation(unionValues)
),
[]
);
typeAlias.leadingComments = [
{