interaction with domain state and redux
See original GitHub issueI have a couple questions about the Apollo Client store implementation
I see in the example that we have one reducer called apollo
. What state does this represent? The current query? The thing with ambitious projects like this is I feel that we should be thinking long term. Having all state under one reducer seems like a bad idea and hard to manage going forward. Imagine mapping state to props over a huge reducer whos shape may be nested etc.
you may end up with something like
function mapStateToProps(state) {
return {
job: state.apolloReucer.job.title
foo: state.apolloReducer.foo.bar.baz
};
}
Is there a way we can represent each query has a slice of our state. Where we somehow generate multiple reducers to manage domain state from different queries?
Sorry if this is naive in approach, just going off the docs at this point!
Issue Analytics
- State:
- Created 7 years ago
- Comments:14 (13 by maintainers)
Top Results From Across the Web
How To Manage State in React with Redux - DigitalOcean
Redux operates according to a few concepts. First, the store is a single object with fields for each selection of data. You update...
Read more >Redux and Doman-Driven Design - Level Up Coding
Aggregates communicate with each other through queries, commands, and domain events. They consume domain events to keep their states consistent, ...
Read more >Redux Fundamentals, Part 2: Concepts and Data Flow
The official Redux Fundamentals tutorial: learn key Redux terms and how data flows in a Redux app.
Read more >Mastering Meteor + Redux: Domain State vs UI State
This is the part I'm interested in, how does the client represents domain state that's been gathered from many locations using REST, Graph, ......
Read more >Sharing state between browser tabs with Redux. - Dave Rivera
You also have to keep in mind that there's no way to update the entire state from Redux, you have to dispatch actions...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
The apollo client itself manages both the reducer and mapping state to props - so rather than using redux-react, you would use
watchQuery
with a custom Apollo container. Check out this article:https://medium.com/apollo-stack/building-a-graphql-store-from-first-principles-413e19ea65b4
Also, if you have read about Relay, it uses a similar store shape, and it does the same management for you under the hood.
The point is, the store needs to be a normalized cache of result objects, rather than something that keeps the result of each query independently. Right now, it doesn’t bring as much benefit, but once you start dealing with pagination, optimistic UI, data preloading, refetching, etc - you basically need a normalized store to take advantage of GraphQL.
In short, we don’t expect people to be using the
apollo
part of the redux store directly, but rather with some provided helpers. Here’s a sketch of a React container I wrote for a demo:(that’s not the final API, just a sketch)
See now this makes more sense. In my mind I envision this playing out something like:
From there you use ActionCreators to as the public API to update Client State / Server State.
Whats the API look for calling a mutation in this world? Are we still using
thunk
writing functions that under the hood call Apollo methods?