Skip to content

Commit

Permalink
feat: combination of zod and InputType
Browse files Browse the repository at this point in the history
  • Loading branch information
KoichiKiyokawa committed Feb 3, 2023
1 parent 888c06a commit 9b02382
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 6 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
import { Field, InputType } from '@nestjs/graphql';
import { createZodDto } from '@project/zod-nestjs';
import { createPostSchema } from '@project/zod-schemas';

@InputType()
export class CreatePostInput extends createZodDto(createPostSchema) {
@Field()
title!: string;

@Field()
content!: string;
}
Original file line number Diff line number Diff line change
@@ -1,9 +1,6 @@
import { Args, ID, Mutation, Query, Resolver } from '@nestjs/graphql';
import { CreatePostInput } from './dto/create-post.input';
import { Post } from './models/post.model';
import { createZodDto } from '@project/zod-nestjs';
import { createPostSchema } from '@project/zod-schemas';

class CreatePostDto extends createZodDto(createPostSchema) {}

@Resolver(() => Post)
export class PostResolver {
Expand All @@ -17,9 +14,8 @@ export class PostResolver {
return null;
}

// NOTE: CreatePostDtoには@Fieldデコレータがついていないので、GraphQLのスキーマに反映できない...
@Mutation(() => Post)
createPost(@Args('input') input: CreatePostDto) {
createPost(@Args('input') input: CreatePostInput) {
console.log({ input });
return null;
}
Expand Down

0 comments on commit 9b02382

Please sign in to comment.