Apollo: data / mutation prop not passed to component

随声附和 提交于 2019-12-10 21:06:18

问题


I have the following component with a query and a mutation, but my Component does not receive the data and the mutation prop.

Am I doing something wrong or missing in my code? The query does get executed though, it's just not passed down. this.props.mutate as well as this.props.data is 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)))
);

回答1:


You have used name to name the mutation prop SetNewPasswordMutation.

This means that you need to call it from your component like:

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


来源:https://stackoverflow.com/questions/40643719/apollo-data-mutation-prop-not-passed-to-component

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!