Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Errors and partially successful response #176

Closed
aleksandrlat opened this issue Jun 21, 2021 · 9 comments
Closed

Errors and partially successful response #176

aleksandrlat opened this issue Jun 21, 2021 · 9 comments

Comments

@aleksandrlat
Copy link

aleksandrlat commented Jun 21, 2021

Hello @morrys!
Thank you for great library.

I'm trying to figure out if useQuery supports partial success and ability to access errors when partially successful response is returned.

I don't know if relay supports it or not. Or if it is possible to implement some workaround to access errors.
What I can see here https://github.com/relay-tools/relay-hooks/blob/master/src/FetchResolver.ts#L171
next method accepts entire payload including errors. What if we can set these errors and return from useQuery hook with partial success response?
I think this would be simple to implement, right?

This is separate from above topic

Also I found interesting idea in this comment facebook/relay#1913 (comment)
I'm curious if it would be possible to implement something in relay-hooks. Maybe with new hook?

I don't see official relay hooks support this.

@aleksandrlat
Copy link
Author

aleksandrlat commented Jun 21, 2021

Just something like this?

next: function (data) {
  var _a;

  if (data && data.errors) {
    error = data.errors
  }
  var store = environment.lookup(operation.fragment);
  promise = null;
  ((_a = operation.request.cacheConfig) === null || _a === void 0 ? void 0 : _a.poll) && updateLoading(false);
  resolveNetworkPromise_1();
  onNext(operation, store);
},

EDIT: I tested this on my local dev env and it works like a charm

@aleksandrlat
Copy link
Author

Or maybe errors or serverErrors can be returned from useQuery hook for backward compatibility with old code?

@morrys
Copy link
Member

morrys commented Jun 22, 2021

Hi @aleksandrlat,
I understand the need and your possible solution.

Have you tried to open an issue in Relay to discuss it with the relay team to understand their point of view?

@aleksandrlat
Copy link
Author

@morrys I have not created issue in Relay.
My colleague found this relatively old issue facebook/relay#1913 in Relay repo

That is why I have not created new issue.

And also this old answer facebook/relay#1816 (comment)

Do you think I should open new issue?

All solutions from issues above are just workarounds.
And if useQuery can return both it will not be workaround.

And what @hayes talks about in facebook/relay#1913 (comment) would be even better

@aleksandrlat
Copy link
Author

@morrys what do you think about my prev comment?

@morrys
Copy link
Member

morrys commented Jul 2, 2021

Hi @aleksandrlat,
sorry for the delay in replying but in this period I have many deadlines at work that keep me very busy :)
I currently prefer to keep error handling at the network level as it could make the store inconsistent (morrys/react-relay-offline#72)

@aleksandrlat
Copy link
Author

Thank you @morrys!

But if I don't throw error in network layer (which I don't want to do) then store is "inconsistent" anyway.
I propose just returning error from the useQuery hook along with partially successful response.

This does not affect store. It only allows to get error.

@aleksandrlat
Copy link
Author

Hello @morrys!

Are you available for this issue? What do you think about my small proposal #176 (comment)? It does not affect store just allows to access error.

@morrys
Copy link
Member

morrys commented Feb 7, 2022

fixed with version 7.0.0

@morrys morrys closed this as completed Feb 7, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants