【问题标题】:Apollo: data / mutation prop not passed to componentApollo:数据/突变道具未传递给组件
【发布时间】:2017-03-31 08:02:55
【问题描述】:

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

我的代码中是否做错了什么或遗漏了什么?查询确实被执行了,只是没有传递下去。 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)))
);

【问题讨论】:

    标签: javascript reactjs apollo apollostack react-apollo


    【解决方案1】:

    您已使用name 将突变道具命名为SetNewPasswordMutation

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

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

    【讨论】:

      猜你喜欢
      • 2018-07-13
      • 2019-10-31
      • 2019-08-06
      • 1970-01-01
      • 1970-01-01
      • 2017-12-27
      • 2020-09-01
      • 2018-01-07
      • 2019-06-30
      相关资源
      最近更新 更多