簡體   English   中英

使用 Apollo 客戶端運行 GraphQL Mutation

[英]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.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM