Skip to content

Commit f573b17

Browse files
Update enums.md
1 parent 02a8086 commit f573b17

File tree

1 file changed

+13
-4
lines changed

1 file changed

+13
-4
lines changed

content/graphql/enums.md

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -64,13 +64,22 @@ export enum AllowedColor {
6464
}
6565
```
6666

67-
Sometimes a backend forces a different value for an enum internally than in the public API. In this example the API contains `RED`, however in resolvers we may use `#f00` instead (read more [here](https://www.apollographql.com/docs/apollo-server/schema/scalars-enums/#internal-values)). To accomplish this, declare a resolver class for the `AllowedColor` enum:
67+
Sometimes a backend forces a different value for an enum internally than in the public API. In this example the API contains `RED`, however in resolvers we may use `#f00` instead (read more [here](https://www.apollographql.com/docs/apollo-server/schema/scalars-enums/#internal-values)). To accomplish this, declare a resolver object for the `AllowedColor` enum:
6868

6969
```typescript
70-
@Resolver('AllowedColor')
71-
export class AllowedColorResolver {
72-
[AllowedColor.RED]: '#f00';
70+
export const allowedColorResolver: Record<keyof typeof AllowedColor, any> = {
71+
RED: '#f00',
7372
}
7473
```
7574

7675
> info **Hint** All decorators are exported from the `@nestjs/graphql` package.
76+
77+
Then use this resolver object together with the `resolvers` property of the `GraphQLModule#forRoot()` method, as follows:
78+
79+
```typescript
80+
GraphQLModule.forRoot({
81+
resolvers: {
82+
AllowedColor: allowedColorResolver,
83+
},
84+
})
85+
```

0 commit comments

Comments
 (0)