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

reducer option ignored by query and watchQuery #1218

Closed
daniel-nagy opened this issue Jan 22, 2017 · 8 comments
Closed

reducer option ignored by query and watchQuery #1218

daniel-nagy opened this issue Jan 22, 2017 · 8 comments

Comments

@daniel-nagy
Copy link

Both ApolloClient::query and ApolloClient::watchQuery list reducer as an option. The query method seems to ignore the option and watchQuery only calls the reducer if you create a subscription as well. I'm not sure if this is intended but it wasn't what I expected.

version: 0.8.3
framework: React Native

Intended outcome

If I provide reducer as an option to query or watchQuery I would expect it to be invoked every time a query returns a new result.

Actual outcome

My reducer is ignored unless I also add a subscription on the observable returned from watchQuery.

Reproduction

Create a query with ApolloClient::query and provide a reducer as an option.

client.query({
  query: ...
  reducer(result, action) {
    // never called
  }
});
@calebmer
Copy link
Contributor

@daniel-nagy could you use updateQueries instead?

@helfer
Copy link
Contributor

helfer commented Jan 23, 2017

Could this be a duplicate of #1129?

@helfer
Copy link
Contributor

helfer commented Jan 26, 2017

Btw, reducer should not be an option on query, only on watchQuery. We're likely to remove this API in upcoming versions (at least temporarily) for the reasons mentioned in #1129.

@calebmer
Copy link
Contributor

Closing this issue. We don’t recommend using reducer. Please use updateQueries or update instead.

@m14t
Copy link

m14t commented May 2, 2017

@calebmer according to http://dev.apollodata.com/react/cache-updates.html#resultReducers

We recommend using the reducer option, except when there’s a good reason to use updateQueries instead (eg. if it would make your app much easier to understand and maintain).

To me that sounds like reducer is the preferred way? If that's not the case would it be possible to update that doc?

https://github.com/apollographql/react-docs/blame/master/source/cache-updates.md#L291

@helfer
Copy link
Contributor

helfer commented May 3, 2017

@m14t yeah, reducer isn't the recommended way any more. We think update is much more versatile and will be a stable API in the future. Would you mind making a PR to the docs to change that sentence? There's a "edit on GitHub" button on every page.

@m14t
Copy link

m14t commented May 3, 2017

Thanks for the speedy reply @helfer. I'm actually quite new to Apollo and so re-writing that paragraph which does not currently reference update is a slightly nuanced task for my current knowledge level.

@helfer
Copy link
Contributor

helfer commented May 3, 2017

Haha, no worries, I hope you're liking it so far! I'll update the docs as soon as I get around to it.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Feb 17, 2023
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

4 participants