我的 Hasura API 数据库中有 2 个表,books(id,name,authorId) 和 authors(id,name)。我想通过前端的输入字段在这些表中插入数据。
我有以下突变,但我不知道如何在我的前端定义架构,以便将数据保存在 Hasura API 表中
const ADD_BOOK = gql`
mutation AddBook($type: String!) {
addBook(type: $type) {
name
}
}
`;
const ADD_AUTHOR = gql`
mutation AddAuthor($type: String!) {
addAuthor(type: $type) {
name
}
}
`;
这是输入表单
function Form(){
let book,author;
return (
<Mutation mutation={ADD_BOOK}>
{(addBook, { data }) => (
<Mutation mutation={ADD_AUTHOR}>
{(addAuthor, { data }) => (
<div>
<form
onSubmit={e => {
e.preventDefault();
addBook({ variables: { type: book.value } });
addAuthor({ variables: { type: author.value } });
book.value = "";
author.value = "";
}}
>
<input
ref={node => {
book = node;
}}
/>
<input
ref={node => {
author = node;
}}
/>
<button type="submit">Add Item</button>
</form>
</div>
)}
</Mutation>
)}
</Mutation>
);
}