Apollo:数据/变异道具未传递给组件

时间:2016-11-16 22:47:00

标签: javascript reactjs apollo apollostack react-apollo

我有以下组件带有查询和变异,但我的组件没有收到数据和变异道具。

我在代码中做错了什么或丢失了什么?查询确实已执行,但它没有传递下来。 this.props.mutate以及this.props.data未定义。

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)))
);

1 个答案:

答案 0 :(得分:5)

您已使用name命名变异道具SetNewPasswordMutation

这意味着您需要从组件中调用它,如:

this.props.SetNewPasswordMutation(
  { variables: { password: model.password, token: this.props.token } })