Skip to content

Commit

Permalink
fix(plugin): fix enums in plugin
Browse files Browse the repository at this point in the history
  • Loading branch information
kamilmysliwiec committed Mar 5, 2020
1 parent beae27a commit a30a3c2
Show file tree
Hide file tree
Showing 5 changed files with 17 additions and 6 deletions.
16 changes: 13 additions & 3 deletions lib/plugin/utils/plugin-utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,19 @@ export function getTypeReferenceAsString(
if (text === Date.name) {
return text;
}
if (isEnum(type)) {
return getText(type, typeChecker);
}
const isEnumMember =
type.symbol && type.symbol.flags === ts.SymbolFlags.EnumMember;

if (isEnumMember) {
type = typeChecker.getDeclaredTypeOfSymbol((type.symbol as any).parent);
if (!type) {
return undefined;
}
return getText(type, typeChecker);
}
if (
isAutoGeneratedTypeUnion(type) ||
isAutoGeneratedEnumUnion(type, typeChecker)
Expand All @@ -78,9 +91,6 @@ export function getTypeReferenceAsString(
) {
return 'Object';
}
if (isEnum(type)) {
return undefined;
}
if (type.aliasSymbol) {
return 'Object';
}
Expand Down
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
"prepublish:next": "npm run build",
"publish:next": "npm publish --access public --tag next",
"test:integration": "jest --config ./tests/jest-e2e.json --runInBand",
"test:integration:dev": "jest --config ./tests/jest-e2e.json --runInBand --watch",
"prerelease": "npm run build",
"release": "release-it"
},
Expand Down
2 changes: 1 addition & 1 deletion tests/jest-e2e.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"moduleFileExtensions": ["js", "json", "ts"],
"rootDir": ".",
"testEnvironment": "node",
"testRegex": ".spec.ts$",
"testRegex": "model-class-visitor.spec.ts$",
"transform": {
"^.+\\.(t|j)s$": "ts-jest"
}
Expand Down
2 changes: 1 addition & 1 deletion tests/plugin/fixtures/create-cat-alt.dto.ts
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ export class CreateCatDto2 {
this.status = Status.ENABLED;
}
static _GRAPHQL_METADATA_FACTORY() {
return { name: { nullable: false, type: () => String }, age: { nullable: false, type: () => Number }, tags: { nullable: false, type: () => [String] }, status: { nullable: false }, breed: { nullable: true, type: () => String }, nodes: { nullable: false, type: () => [Object] }, alias: { nullable: false, type: () => Object }, numberAlias: { nullable: false, type: () => Number }, union: { nullable: false, type: () => Object }, intersection: { nullable: false, type: () => Object }, nested: { nullable: false, type: () => ({ first: { nullable: false, type: () => String }, second: { nullable: false, type: () => Number }, status: { nullable: false }, tags: { nullable: false, type: () => [String] }, nodes: { nullable: false, type: () => [Object] }, alias: { nullable: false, type: () => Object }, numberAlias: { nullable: false, type: () => Number } }) } };
return { name: { nullable: false, type: () => String }, age: { nullable: false, type: () => Number }, tags: { nullable: false, type: () => [String] }, status: { nullable: false, type: () => Status }, breed: { nullable: true, type: () => String }, nodes: { nullable: false, type: () => [Object] }, alias: { nullable: false, type: () => Object }, numberAlias: { nullable: false, type: () => Number }, union: { nullable: false, type: () => Object }, intersection: { nullable: false, type: () => Object }, nested: { nullable: false, type: () => ({ first: { nullable: false, type: () => String }, second: { nullable: false, type: () => Number }, status: { nullable: false, type: () => Status }, tags: { nullable: false, type: () => [String] }, nodes: { nullable: false, type: () => [Object] }, alias: { nullable: false, type: () => Object }, numberAlias: { nullable: false, type: () => Number } }) } };
}
}
`;
2 changes: 1 addition & 1 deletion tests/plugin/fixtures/create-cat.dto.ts
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ export class CreateCatDto {
this.status = Status.ENABLED;
}
static _GRAPHQL_METADATA_FACTORY() {
return { name: { nullable: false, type: () => String }, age: { nullable: false, type: () => Number }, tags: { nullable: false, type: () => [String] }, status: { nullable: false }, status2: { nullable: true }, statusArr: { nullable: true }, breed: { nullable: true, type: () => String }, nodes: { nullable: false, type: () => [Object] }, date: { nullable: false, type: () => Date } };
return { name: { nullable: false, type: () => String }, age: { nullable: false, type: () => Number }, tags: { nullable: false, type: () => [String] }, status: { nullable: false, type: () => Status }, status2: { nullable: true, type: () => Status }, statusArr: { nullable: true, type: () => [Status] }, breed: { nullable: true, type: () => String }, nodes: { nullable: false, type: () => [Object] }, date: { nullable: false, type: () => Date } };
}
}
__decorate([
Expand Down

0 comments on commit a30a3c2

Please sign in to comment.