阿波罗:数据/突变道具没有传递给组件

Apollo: data / mutation prop not passed to component

本文关键字:组件 数据 突变 变道 阿波罗      更新时间:2023-09-26

我有一个查询和一个突变的组件,但是我的组件没有接收到数据和突变道具。

我做错了什么或遗漏在我的代码?查询确实执行了,只是没有传递下去。This.props.mutate和this.props.data都是undefined

class ResetConfirm extends React.Component {
  static propTypes = {
    intl: intlShape.isRequired,
    token: React.PropTypes.string,
    data: React.PropTypes.shape({
      loading: React.PropTypes.bool.isRequired,
      checkToken: React.PropTypes.array,
    }).isRequired,
    mutate: React.PropTypes.func.isRequired,
  }
  submitForm = (model) => {
    this.setState({
      loading: true,
    });
    this.props.mutate({ variables: { password: model.password, token: this.props.token } })
      .then(({ data }) => {
        // redirect
      }).catch((error) => {
        console.log('there was an error sending the query', error);
      });
  }
  render() {
       //render jsx
  }
}
const CheckTokenQuery = gql`
  query CheckToken($token: String!) {
    checkToken(token: $token) {
      response
    }
  }
`;
const SetNewPasswordMutation = gql`
  mutation SetNewPasswordMutation($password: String!, $token: String!) {
    resetPassword(password: $password, token: $token) {
      response
    }
  }
`;
export default graphql(SetNewPasswordMutation, { name: SetNewPasswordMutation })(
  graphql(CheckTokenQuery, { name: CheckTokenQuery, forceFetch: true })(injectIntl(connect(ResetConfirm)))
);

您已经使用name来命名突变道具SetNewPasswordMutation

这意味着你需要从你的组件中调用它,如:
this.props.SetNewPasswordMutation(
  { variables: { password: model.password, token: this.props.token } })