NestJS
├─src
│ ├─users
│ │ ├─dtos
│ │ │ └─create-user.dto.ts
│ │ ├─entities
│ │ │ └─users.entitiy.ts
│ │ ├─users.module.ts
│ │ └─users.resolver.ts
│ ├─app.module.ts
│ └─main.ts
├─test
│ └─...test files
└─eslint,env,prettier etc config files
Last active
February 16, 2021 10:25
-
-
Save DillonMemo/54f990f5994058001a944b0b7f1266c1 to your computer and use it in GitHub Desktop.
finally NestJS configure practice
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import { ArgsType, Field, Int } from '@nestjs/graphql'; | |
import { | |
IsBoolean, | |
IsInt, | |
IsOptional, | |
IsString, | |
Length, | |
} from 'class-validator'; | |
// data transfet object(DTO) | |
@ArgsType() | |
export class CreateUserDto { | |
@Field(() => Int) | |
@IsInt() | |
id: number; | |
@Field(() => String) | |
@IsString() | |
@Length(2, 10) | |
name: string; | |
@Field(() => String) | |
@IsString() | |
email: string; | |
@Field(() => String, { nullable: true }) | |
@IsOptional() | |
@IsString() | |
gender?: 'male' | 'female'; | |
@Field(() => String) | |
@IsString() | |
address: string; | |
@Field(() => Boolean) | |
@IsBoolean() | |
isVIP: boolean; | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import { Field, Int, ObjectType } from '@nestjs/graphql'; | |
@ObjectType() | |
export class User { | |
@Field(() => Int) | |
id: number; | |
@Field(() => String) | |
name: string; | |
@Field(() => String) | |
email: string; | |
@Field(() => String, { nullable: true }) | |
gender?: 'male' | 'female'; | |
@Field(() => String) | |
address: string; | |
@Field(() => Boolean) | |
isVIP: boolean; | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import { Args, Mutation, Query, Resolver } from '@nestjs/graphql'; | |
import { CreateUserDto } from './dtos/create-user.dto'; | |
import { User } from './entities/users.entity'; | |
@Resolver(() => User) | |
export class UserResolver { | |
@Query(() => Boolean) | |
users(@Args('bool') bool: boolean): boolean { | |
return bool; | |
} | |
@Mutation(() => Boolean) | |
createUser(@Args() createUserDto: CreateUserDto): boolean { | |
console.log(createUserDto); | |
return true; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment