Skip to content

Commit bcfd255

Browse files
committed
docs(codegen): add documentation on how to bind existing enums
1 parent 6398fd8 commit bcfd255

File tree

1 file changed

+20
-1
lines changed

1 file changed

+20
-1
lines changed

docs/codegen/schema-configuration.md

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ By default, the code generator **will generate code for all available types**, t
55
#### Directives
66
```graphql
77
# Defines the representation of a object or scalar in the kotlin code.
8-
directive @kRepresentation(class: String!) on OBJECT | SCALAR
8+
directive @kRepresentation(class: String!) on OBJECT | SCALAR | INTERFACE | ENUM
99

1010
# Tells the code generator that a data class for the object shall be generated.
1111
directive @kGenerate on OBJECT
@@ -36,6 +36,25 @@ type User @kRepresentation(class: "com.auritylab.graphql.entity.User") {
3636
}
3737
```
3838

39+
#### Enums
40+
When binding existing enums using `@kRepresentation`, the generated code slightly differs to a normal object.
41+
The generated enum provides converter functions to convert from the generated enum to the representation enum and vice versa.
42+
43+
Example:
44+
```kotlin
45+
/// Will convert the DEFAULT enum constant to the matching representation enum constant.
46+
GQLEUserType.DEFAULT.presentation
47+
// - or -
48+
GQLEUserType.DEFAULT()
49+
50+
51+
// Will convert the DEFAULT representation enum constant to the matching enum constant of the generated enum.
52+
GQLEUserType.of(EUserType.DEFAULT)
53+
// - or -
54+
GQLEUserType(EUserType.DEFAULT)
55+
56+
```
57+
3958
### Avoid generating all resolvers (`@kResolver`)
4059
When building a large GraphQL API there can be a lot of resolvers. By default, the code generator will generate code for every resolver.
4160
This behavior can be adjusted using the `generateAll` option (See [usage](#disable-generating-code-for-everything)). When setting it to `false` the code generator will only generate code if the `@kResolver` directive has been added in the schema.

0 commit comments

Comments
 (0)