I'm trying to reproduce this example, after 3 hours testing, I have no idea how to get the values of enum using nestjs/graphql (type-graphql works fine).
## I'm submitting a...
[ ] Regression
[ ] Bug report
[ ] Feature request
[*] Documentation issue or request
[ ] Support request => Please do not submit support request here, instead post your question on Stack Overflow.
Let's say we have an enum:
import { registerEnumType } from "type-graphql";
export enum Difficulty {
Beginner = 1,
Easy = 2,
Medium = 3,
Hard = 4,
MasterChef = 5,
}
registerEnumType(Difficulty, {
name: "Difficulty",
});
And the resolver:
import {
Resolver,
Args,
} from '@nestjs/graphql';
import {
Recipe,
} from './recipe.entity';
import { Difficulty } from './recipe.constant';
@Resolver(Recipe)
export class RecipeResolver {
@Query(returns => [Recipe])
recipes(@Args({ name: 'difficulty', type: () => Difficulty }) difficulty: Difficulty) {
console.log(difficulty); // I'm getting the string key name
}
}
Query:
query {
recipes (difficulty: Beginner) {
name
}
}
The console output is "Beginner".
Should be 1.
If it's necessary, I'll creating one.
Common usage.
Nest version: 6.1.1
For Tooling issues:
- Node version: 10.15.3
- Platform: Windows
Others:
- TypeScript: 3.4.3
I've been facing that exact same issue, too. Directly using type-graphql works fine.
It should be fixed in the @next version ($ npm i @nestjs/graphql@next). You will also have to update @nestjs/core to 6.2.0 ($ npm i @nestjs/[email protected])
I can confirm it's fixed in next, thanks @kamilmysliwiec!
Published as 6.2.0 ($ npm i @nestjs/graphql@latest). You will also have to update @nestjs/core to 6.2.0 ($ npm i @nestjs/core@latest)
Could GraphQLDefinitionsFactory generate definitions with custom enum values?
This thread has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs.