apollographql / apollo-client

:rocket:  A fully-featured, production ready caching GraphQL client for every UI framework and GraphQL server.
https://apollographql.com/client
MIT License
19.34k stars 2.65k forks source link

throw error in graphl(mutation) #2328

Closed webmobiles closed 6 years ago

webmobiles commented 6 years ago

I have the following code, i've tried to insert ".catch" in the first line, but i'm gettint this error:

TypeError: Object(...)(...)(...).catch is not a function
./src/components/SignInPage.js
src/components/SignInPage.js:60
  57 |   }
  58 | `;
  59 | 
> 60 | const SignInWithData = graphql(signInMutation)(withRouter(SignInFormContainer))
  61 |   .catch(error => {

anyone can help me to understand ?

const SignInWithData = graphql(signInMutation)(withRouter(SignInFormContainer))
  .catch(error => {
    console.log('error');
    console.log(error);
  })
;

const mapDispatchToProps = dispatch => ({
  signInDispatcher(token) {
    dispatch(signIn(token));
  },
});

const SignInWithDataAndState = connect(
  null,
  mapDispatchToProps,
)(SignInWithData);

export default SignInWithDataAndState;
webmobiles commented 6 years ago

the right way is in handleSubmit of component:


  handleSubmit(values) {
    this.props.mutate({ variables: values })
      .then((response) => {
        if (response.data.signIn.errors.length <= 0) {
          this.props.signInDispatcher(response.data.signIn.token);
          this.props.history.push('/customers');
        } else {
          this.setState({
            errors: response.data.signIn.errors,
          });
        }
      })
      .catch((err) => {
        console.log('error');
        console.error(err);
      });
  }