본문 바로가기

실습

게시판 만들기.03

gql을 이용하여 데이터를 보내주는 작업을 하였습니다.

const CREATE_BOARD = gql`
  mutation createBoard($createBoardInput: CreateBoardInput!){
    createBoard(createBoardInput: $createBoardInput){
      _id
    }
  }
`

gql선언 

createBoardInput: $createBoardInput : 변수값
 
$createBoardInput: CreateBoardInput!: 변수타입
  // 쿼리문 적용
  const [createBoard] = useMutation(CREATE_BOARD
const result = await createBoard({
          variables: {
            createBoardInput: {
              writer: writer,
              password: password,
              title: title,
              contents: contents
            }
          }
        })
    console.log(result)

onClickSubmit에 동기적으로 적용을 해주었습니다.

'실습' 카테고리의 다른 글

게시판 만들기.04  (0) 2023.01.31
게시판 만들기.02  (0) 2023.01.30
게시판 만들기.01  (0) 2023.01.30