연동되어 있는 데이터베이스 세팅에서 값을 맞춰준다. 여기서는 받은 데이터베이스에서 데이터베이스 이름과 비밀번호만 세팅 다시 해줬다.
에러난 것 해결 :
er_not_supported_auth_mode: client does not support authentication protocol requested by server; consider upgrading mysql client
alter user 'einere'@'%' identified with mysql_native_password by 'mypassword';
mutation{
createCat(input:{
name :"Name",
description : "Description"
}
){
ok
error
__typename
}
}
query{
getCat(input:{
id :1
}){
error
ok
}
}
resolver, service, dto, entity에 정해진대로밖에 입력이 안 된다.
mutation{
updateCat(input:{
id :3,
name : "냥이",
description : "냥이입니다."
# create와 달리 id가 들어간다.
}){
error
ok
__typename
}
}
Input -> objectType(output) 으로 생각하기
이를 위해 만든 다른 코드
<update-cat_dto.ts>
import { InputType, ObjectType, PartialType, PickType } from "@nestjs/graphql";
import { CoreOutput } from "src/common/dtos/output.dto";
import { Cat } from "../entities/cat.entity";
@InputType()
export class UpdateCatInput extends PickType(Cat, ["id", "name", "description"]){
// PickType으로 원하는 자료를 가져온다.
}
@ObjectType()
export class UpdateCatOutput extends CoreOutput {
}
<cats.resolver.ts>
@Mutation(returns => UpdateCatOutput)
async updateCat(
@Args('input') updateCatInput: UpdateCatInput
): Promise<UpdateCatOutput>{
return this.catService.updateCat(updateCatInput)
}
<cats.service.ts>
async updateCat(updateCatInput: UpdateCatInput): Promise<UpdateCatOutput> {
try {
/* update Cat */
await this.cats.update(updateCatInput.id, {...updateCatInput});
return {
ok: true
}
}catch(e){
console.log(e);
return {
ok: false,
error: "Cannot update cat"
}
}
}
mutation{
deleteCat(input:{
id : 2,
name : "Nero",
description : "Description"
}){
error
ok
__typename
}
}
어떤 걸 지울지 확인
앞에 내용은 delete로만 바꾸면 됨.