Skip to content
This repository has been archived by the owner on Apr 13, 2023. It is now read-only.

Why Query component does not pass all errors as render prop? #2124

Closed
erfoon opened this issue Jun 19, 2018 · 2 comments
Closed

Why Query component does not pass all errors as render prop? #2124

erfoon opened this issue Jun 19, 2018 · 2 comments

Comments

@erfoon
Copy link

erfoon commented Jun 19, 2018

Hi, I've been using react-apollo for weeks and it's been great. But there is one thing with the Query component that I don't understand and makes some problems. Why Query component does not pass all errors as render props and some of them should be caught using try-catch?
Look at the code below:

renderComponent = () => {
    try {
      const value = (
        <Query
          query={MY_QUERY} variables={MY_VARS}>
          {({  error, data }) => this.renderContent(error, data)}
        </Query>
      );
      return value;
    } catch (e) {
      return this.renderContent(error);
    }
  }; 

Some errors are passed as error and there is no error thrown, but some of errors are caught using try-catch. It is fine but it cause some problems, like the inner component had to be render two times, so some problems like losing focus and resting the whole things happen which is not fine.
So my question: Is there any way to make the Query component pass all types of errors as render props and nothing needs to be caught by try-catch?

p.s: I used errorPolicy prop and it didn't make any changes.

Thanks

@rosskevin
Copy link
Contributor

If you do not have a problem with your client side setup, apollo should return errors as part of the result. If you are seeing different behavior, please file an issue with apollo-client.

react-apollo is a react component based consumer of apollo-client. In the case of Query, it uses client.watchQuery. I suspect you are seeing an error thrown from your link setup code or something else, not from a HTTP 200 graphql error that apollo interprets and returns as a result.

We have a large app and have never encountered the case you are presenting. If you can reproduce, please ping me and I'll reopen if it is a problem inside Query.

@erfoon
Copy link
Author

erfoon commented Dec 29, 2018

@rosskevin As you see this issue was for months ago and I had same problems till the last time I remember so I gave up using render prop and used the HOC style (withApollo) and it works fine. I don't know if it's still an issue with <Query /> or not (I saw some activities regarding similar issues). However I think React is making some changes on the whole HOC and its problems so with new React we may not need render prop anymore in near future. Maybe!

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants