给定以下突变,如何 return 返回数据?

Given the following mutation, how to return back data?

我有以下突变

const SET_NAME_MUTATION = gql`
  mutation ($name: String!) {
    setName(name: $name)
  }
`;

const withSetFullNameMutation = graphql( SET_NAME_MUTATION, {
  name: 'setName',
});

在我的 onSubmit 表单中,我像这样使用上面的内容:

await setName({ variables: "data is here" });

我如何更新上面的内容以便像这样取回值:

const result = setName({ variables:"data is here });
console.log(result)

结果将包含 user.id、user.title、user.photo_url?

谢谢

突变的结果在突变字符串的大括号内定义。 我的情况可能看起来像:

const SET_NAME_MUTATION = gql `
  mutation ($name: String!) {
    setName(name: $name) {
      user {
        id
        title
        photo_url
      }
    }
  }
`;

const withSetFullNameMutation = graphql(SET_NAME_MUTATION, {
  name: 'setName',
});

当您调用突变时,可以像这样检索结果:

this.props.setName(name).then(response => {
  const user = response.data.setName.user;
}).catch(errors => {});

在这种情况下,服务器上的突变本身需要传递正确的数据对象。所以你还需要更改服务器上的突变。