좀 더 복잡한 자료인 createProduct 로 graphql 심화 실습 해보기
import { useMutation, gql } from "@apollo/client";
// 세팅
const CREATE_PRODUCT = gql`
# 변수의 타입 적는 곳
mutation createProduct(
$seller: String
$createProductInput: CreateProductInput!
) {
#실제 우리가 전달할 변수 적는 곳
createProduct(seller: $seller, createProductInput: $createProductInput) {
_id
number
message
}
}
`;
export default function GraphqlMutationPage() {
const [createProduct] = useMutation(CREATE_PRODUCT);
const onClickSubmit = async () => {
const result = await createProduct({
variables: {
seller: "판매자 이름",
createProductInput: {
name: "티셔츠",
detail: "좋은 티셔츠 입니다.",
price: 30000,
},
},
});
console.log(result);
};
return <button onClick={onClickSubmit}>GRAPHQL-API 요청하기</button>;
'비공개 > 강의 간단 정리(추후 복습하면서 수정)' 카테고리의 다른 글
[Section05-02] static-routing-board (0) | 2023.05.05 |
---|---|
[Section05-01] static-routing (0) | 2023.05.05 |
[Section04-04] graphql-mutation-input (0) | 2023.05.05 |
[Section04-03] graphql-mutation-args (0) | 2023.05.05 |
[Section04-02] graphql-mutation (& 에러를 해결하는 방법) (0) | 2023.05.05 |