![](/img/trans.png)
[英]GraphQL mutation not being sent to request when using Apollo client?
[英]Run GraphQL Mutation using Apollo Client
所以我有這個 GraphQL Mutation 允許用戶創建一個帳戶:
mutation {
register(input: {
email: "bob@gmail.com"
password: "bob123"
}) {
user {
id
email
}
errors {
path
message
}
}
}
我想使用 Apollo Client 運行這個突變(注意:我使用的是 TypeScript)
const REGISTER: DocumentNode = gql`
mutation Register($type: String!) {
register(input: {
email: $type
password: $type
}) {
email
id
}
}
`
<form onSubmit={(e: React.FormEvent<HTMLFormElement>) => {
e.preventDefault()
register({ variables: { input: {email: emailValue, password: passwordValue} } })
}}>
任何幫助,將不勝感激! 提前致謝!
更新:我通過這樣做修復了它:
// GraphQL Mutation to register an account
const REGISTER: DocumentNode = gql`
mutation register($email: String!, $password: String!) {
register(input: {
email: $email
password: $password
}) {
user {
email
id
}
errors {
path
message
}
}
}
`
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.