如何在React-Apollo-hook的useMutation中包含ID和变量

时间:2019-05-17 01:39:58

标签: javascript reactjs graphql apollo react-hooks

我的架构如下设置:

updatePost(id: ID!, data: UpdatePostInput!): Post!

我也将前端查询设置如下:

export const UPDATE_POST_MUTATION = gql`
 mutation UpdatePost($id: ID!, $title: String, $body: String, $location: String, $published: Boolean) {
    updatePost(
        id: $id,
        data: {
            title: $title, body: $body, location: $location, published: $published
        }
    ){
      id
      title
      body
    }
  }
`

如果在这种情况下我想使用useMutation,我将如何包含ID和变量? 我尝试了以下操作,但没有成功:

const formSubmit = useMutation(UPDATE_POST_MUTATION, {
        variables: { id: props.match.params.id, variables } // or ...variables  
    })

0 个答案:

没有答案