Skip to content

Commit 4640370

Browse files
Merge pull request #1543 from mattleff/patch-2
feat(): Add support for enum descriptions and value deprecation
2 parents a30edbe + 5fc4b00 commit 4640370

File tree

1 file changed

+38
-0
lines changed

1 file changed

+38
-0
lines changed

content/graphql/enums.md

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,44 @@ enum AllowedColor {
4242
}
4343
```
4444

45+
To provide a description for the enum, pass the `description` property into the `registerEnumType()` function.
46+
47+
```typescript
48+
registerEnumType(AllowedColor, {
49+
name: 'AllowedColor',
50+
description: 'The supported colors.',
51+
});
52+
```
53+
54+
To provide a description for the enum values, or to mark a value as deprecated, pass the `valuesMap` property, as follows:
55+
56+
```typescript
57+
registerEnumType(AllowedColor, {
58+
name: 'AllowedColor',
59+
description: 'The supported colors.',
60+
valuesMap: {
61+
RED: {
62+
description: 'The default color.',
63+
},
64+
BLUE: {
65+
deprecationReason: 'Too blue.',
66+
}
67+
}
68+
});
69+
```
70+
71+
This will generate the following GraphQL schema in SDL:
72+
73+
```graphql
74+
"""The supported colors."""
75+
enum AllowedColor {
76+
"""The default color."""
77+
RED
78+
GREEN
79+
BLUE @deprecated(reason: "Too blue.")
80+
}
81+
```
82+
4583
#### Schema first
4684

4785
To define an enumerator in the schema first approach, simply create a GraphQL enum with SDL.

0 commit comments

Comments
 (0)