Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
t.TSTypeAnnotation(type)
);
// TODO: Check if this works
propertySignatureType.optional =
keyInheritsNullability && this.isNullableType(type);
if (this.options.useReadOnlyTypes) {
propertySignatureType.readonly = true;
}
if (description) {
propertySignatureType.leadingComments = [
{
type: "CommentBlock",
value: commentBlockContent(description)
} as t.CommentBlock
];
}
return propertySignatureType;
});
}
);
// Nullable fields on input objects do not have to be defined
// as well, so allow these fields to be "undefined"
objectTypeProperty.optional =
keyInheritsNullability &&
annotation.type === "NullableTypeAnnotation";
if (this.options.useReadOnlyTypes) {
objectTypeProperty.variance = { kind: "plus" };
}
if (description) {
objectTypeProperty.leadingComments = [
{
type: "CommentBlock",
value: commentBlockContent(description)
} as t.CommentBlock
];
}
return objectTypeProperty;
})
);
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
];
}
return typeAlias;
}
public exportDeclaration(
declaration: t.Declaration,
options: { comments?: string } = {}
) {
const exportedDeclaration = t.exportNamedDeclaration(declaration, []);
if (options.comments) {
exportedDeclaration.trailingComments = [
{
type: "CommentBlock",
value: commentBlockContent(options.comments)
} as t.CommentBlock
];
}
return exportedDeclaration;
}
return type;
});
const typeAlias = t.exportNamedDeclaration(
t.typeAlias(
t.identifier(name),
undefined,
t.unionTypeAnnotation(unionValues)
),
[]
);
typeAlias.leadingComments = [
{
type: "CommentBlock",
value: commentBlockContent(description || "")
} as t.CommentBlock
];
return typeAlias;
}
type: this.typeFromGraphQLType(field.type)
};
});
const inputType = t.exportNamedDeclaration(
this.interface(name, fields, {
keyInheritsNullability: true
}),
[]
);
if (description) {
inputType.leadingComments = [
{
type: "CommentBlock",
value: commentBlockContent(description)
} as t.CommentBlock
];
}
return inputType;
}