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

Cannot access result from mutation hoc #1842

Closed
doniyor2109 opened this issue Mar 25, 2018 · 13 comments
Closed

Cannot access result from mutation hoc #1842

doniyor2109 opened this issue Mar 25, 2018 · 13 comments

Comments

@doniyor2109
Copy link

doniyor2109 commented Mar 25, 2018

I have used mutation-hoc for RN Component. I can access mutation function however I cannot access the _result from mutation.

{(mutate, _result) => {

@doniyor2109
Copy link
Author

Here is PR #1844

@fenok
Copy link

fenok commented Mar 27, 2018

I need this badly. However, I don't think that #1844 does this right. What if there are multiple mutations in HOCs chain? I believe the right way is:
let childProps = { [name]: Object.assign(mutate, _result) };
It's 100% backward-compatible and allows accessing each mutation's state individually.

@doniyor2109
Copy link
Author

doniyor2109 commented Mar 30, 2018

Maybe temporary workaround is to use old graphql from react-apollo

@fenok
Copy link

fenok commented Mar 30, 2018

Could you explain that a bit further? What do you mean by “old graphql”? Currently graphql uses mutation-hoc internally.

@doniyor2109
Copy link
Author

Sorry for mixing, I mean currently graphql

@fenok
Copy link

fenok commented Apr 1, 2018

I still don't get it, because

Currently graphql uses mutation-hoc internally.

Can you provide an example?

@doniyor2109
Copy link
Author

It is possible to get loading and error states with the help of some additional hocs. There is some solution in #421

@doniyor2109
Copy link
Author

I opened new PR which only adds new prop called mutationResult #1881

@fenok
Copy link

fenok commented Apr 1, 2018

It is possible to get loading and error states with the help of some additional hocs. There is some solution in #421

I'm aware of it, but I want this functionality included in react-apollo itself.

I opened new PR which only adds new prop called mutationResult #1881

Again, this will fail if component is wrapped by several mutation-hocs. You could at least use [`${name}Result`]: _result. But I'm still convinced that it should be done like let childProps = { [name]: Object.assign(mutate, _result) };.

@doniyor2109
Copy link
Author

Yes you are right. It overrides when there are multiple hocs. You should also create PR for your solution. That could be the right solution.

@brendanmoore
Copy link

I am a little bit baffled as to why _result is not passed to the child with the mutation-hoc I cannot find any documentation explaining the decision. If somebody "in the know" could share, that would be great.

@ekfn
Copy link

ekfn commented Jun 24, 2018

Is there any good workarounds? Or may be news on this one?

@rosskevin
Copy link
Contributor

Explanation:
#1844 (comment)

jbaxleyiii commented on Mar 26
@doniyor2109 this is actually intentional to keep backwards compat 100%. I'm curious why you wouldn't use the Mutation component instead?

FYI - In-house, we don't use the Mutation component or hoc, we just mutate directly on the client.

Given this explanation from a core maintainer, I'm going to close this in an effort to keep the tracker focused on actionable issues. I suspect a hooks implementation in 2019 will make us think about our patterns of use and perhaps transition us to something simpler yet to use.

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

5 participants