Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(@nestjs/graphql): Fix generation of ArgsType metadata #2381

Merged
merged 1 commit into from
Sep 5, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
8 changes: 7 additions & 1 deletion packages/graphql/lib/plugin/visitors/model-class.visitor.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import * as ts from 'typescript';
import {
ArgsType,
Field,
HideField,
InputType,
Expand Down Expand Up @@ -30,7 +31,12 @@ import {
replaceImportPath,
} from '../utils/plugin-utils';

const CLASS_DECORATORS = [ObjectType.name, InterfaceType.name, InputType.name];
const CLASS_DECORATORS = [
ObjectType.name,
InterfaceType.name,
InputType.name,
ArgsType.name,
];

export class ModelClassVisitor {
private importsToAdd: Set<string>;
Expand Down
70 changes: 70 additions & 0 deletions packages/graphql/tests/plugin/fixtures/create-cat.dto.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,44 @@ export class CreateCatDto {

static staticProperty: string;
}

@InputType()
export class CreateCatInput {
name: string;
age: number = 3;
tags: string[];
status: Status = Status.ENABLED;
status2?: Status;
statusArr?: Status[];
readonly breed?: string;
nodes: Node[];
date: Date;

@HideField()
hidden: number;

static staticProperty: string;
}

@ArgsType()
export class CreateCatArgs {
name: string;
age: number = 3;
tags: string[];
status: Status = Status.ENABLED;
status2?: Status;
statusArr?: Status[];
readonly breed?: string;
nodes: Node[];
date: Date;

@HideField()
hidden: number;

static staticProperty: string;

input: CreateCatInput;
}
`;

export const createCatDtoTextTranspiled = `var Status;
Expand Down Expand Up @@ -56,4 +94,36 @@ CreateCatDto = __decorate([
ObjectType()
], CreateCatDto);
export { CreateCatDto };
let CreateCatInput = class CreateCatInput {
constructor() {
this.age = 3;
this.status = Status.ENABLED;
}
static _GRAPHQL_METADATA_FACTORY() {
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 } };
}
};
__decorate([
HideField()
], CreateCatInput.prototype, \"hidden\", void 0);
CreateCatInput = __decorate([
InputType()
], CreateCatInput);
export { CreateCatInput };
let CreateCatArgs = class CreateCatArgs {
constructor() {
this.age = 3;
this.status = Status.ENABLED;
}
static _GRAPHQL_METADATA_FACTORY() {
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 } };
}
};
__decorate([
HideField()
], CreateCatArgs.prototype, \"hidden\", void 0);
CreateCatArgs = __decorate([
ArgsType()
], CreateCatArgs);
export { CreateCatArgs };
`;