Skip to content

Commit fb8a582

Browse files
Merge pull request #2381 from EdouardBougon/feature/fix-plugin-args-generation
fix(@nestjs/graphql): Fix generation of ArgsType metadata
2 parents 198b217 + a5383c6 commit fb8a582

File tree

2 files changed

+77
-1
lines changed

2 files changed

+77
-1
lines changed

packages/graphql/lib/plugin/visitors/model-class.visitor.ts

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import * as ts from 'typescript';
22
import {
3+
ArgsType,
34
Field,
45
HideField,
56
InputType,
@@ -30,7 +31,12 @@ import {
3031
replaceImportPath,
3132
} from '../utils/plugin-utils';
3233

33-
const CLASS_DECORATORS = [ObjectType.name, InterfaceType.name, InputType.name];
34+
const CLASS_DECORATORS = [
35+
ObjectType.name,
36+
InterfaceType.name,
37+
InputType.name,
38+
ArgsType.name,
39+
];
3440

3541
export class ModelClassVisitor {
3642
private importsToAdd: Set<string>;

packages/graphql/tests/plugin/fixtures/create-cat.dto.ts

Lines changed: 70 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,44 @@ export class CreateCatDto {
2929
3030
static staticProperty: string;
3131
}
32+
33+
@InputType()
34+
export class CreateCatInput {
35+
name: string;
36+
age: number = 3;
37+
tags: string[];
38+
status: Status = Status.ENABLED;
39+
status2?: Status;
40+
statusArr?: Status[];
41+
readonly breed?: string;
42+
nodes: Node[];
43+
date: Date;
44+
45+
@HideField()
46+
hidden: number;
47+
48+
static staticProperty: string;
49+
}
50+
51+
@ArgsType()
52+
export class CreateCatArgs {
53+
name: string;
54+
age: number = 3;
55+
tags: string[];
56+
status: Status = Status.ENABLED;
57+
status2?: Status;
58+
statusArr?: Status[];
59+
readonly breed?: string;
60+
nodes: Node[];
61+
date: Date;
62+
63+
@HideField()
64+
hidden: number;
65+
66+
static staticProperty: string;
67+
68+
input: CreateCatInput;
69+
}
3270
`;
3371

3472
export const createCatDtoTextTranspiled = `var Status;
@@ -56,4 +94,36 @@ CreateCatDto = __decorate([
5694
ObjectType()
5795
], CreateCatDto);
5896
export { CreateCatDto };
97+
let CreateCatInput = class CreateCatInput {
98+
constructor() {
99+
this.age = 3;
100+
this.status = Status.ENABLED;
101+
}
102+
static _GRAPHQL_METADATA_FACTORY() {
103+
return { name: { type: () => String }, age: { type: () => Number }, tags: { type: () => [String] }, status: { type: () => Status }, status2: { nullable: true, type: () => Status }, statusArr: { nullable: true, type: () => [Status] }, breed: { nullable: true, type: () => String }, nodes: { type: () => [Object] }, date: { type: () => Date } };
104+
}
105+
};
106+
__decorate([
107+
HideField()
108+
], CreateCatInput.prototype, \"hidden\", void 0);
109+
CreateCatInput = __decorate([
110+
InputType()
111+
], CreateCatInput);
112+
export { CreateCatInput };
113+
let CreateCatArgs = class CreateCatArgs {
114+
constructor() {
115+
this.age = 3;
116+
this.status = Status.ENABLED;
117+
}
118+
static _GRAPHQL_METADATA_FACTORY() {
119+
return { name: { type: () => String }, age: { type: () => Number }, tags: { type: () => [String] }, status: { type: () => Status }, status2: { nullable: true, type: () => Status }, statusArr: { nullable: true, type: () => [Status] }, breed: { nullable: true, type: () => String }, nodes: { type: () => [Object] }, date: { type: () => Date }, input: { type: () => require(\"./create-cat.input\").CreateCatInput } };
120+
}
121+
};
122+
__decorate([
123+
HideField()
124+
], CreateCatArgs.prototype, \"hidden\", void 0);
125+
CreateCatArgs = __decorate([
126+
ArgsType()
127+
], CreateCatArgs);
128+
export { CreateCatArgs };
59129
`;

0 commit comments

Comments
 (0)