Docblock tags
Enums
To define a GraphQL enum, put a @gqlEnum docblock directly before a:
- TypeScript enum declaration;
- type alias of a union of string literals.
As with other tags, the name after the tag, if any, is the enum's name in the schema, when it differs from the type's name.
/**
* A description of my enum.
* @gqlEnum
*/
enum MyEnum {
/** A description of my variant */
OK = "OK",
/** A description of my other variant */
ERROR = "ERROR",
}"""A description of my enum."""
enum MyEnum {
"""A description of my other variant"""
ERROR
"""A description of my variant"""
OK
}The values of the enum are the GraphQL enum's values, and must be string literals.
Note
A TypeScript enum needs a transpiler: Node's type stripping, which runs .ts files directly, rejects it (ERR_UNSUPPORTED_TYPESCRIPT_SYNTAX). To run your code that way, use a union of string literals instead (below).
To mark a value as deprecated, put the @deprecated JSDoc tag directly before it:
/** @gqlEnum */
enum MyEnum {
OK = "OK",
/** @deprecated Please use OK instead. */
OKAY = "OKAY",
ERROR = "ERROR",
}enum MyEnum {
ERROR
OK
OKAY @deprecated(reason: "Please use OK instead.")
}An enum can also be a union of string literals, with some limitations:
- you cannot add descriptions to its values;
- you cannot mark its values as deprecated.
This is because TypeScript does not "attach" JSDoc comments to string literal types.
/** @gqlEnum */
type MyEnum = "OK" | "ERROR";enum MyEnum {
ERROR
OK
}