-
Notifications
You must be signed in to change notification settings - Fork 2.7k
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
Idea: Factor out a graphQLSelector to be used independently #244
Comments
I'm all about this. I'm in. |
OK I have a few important questions:
|
I'll get started on this ASAP. |
I have a question about this one. Why does this have to be a method off the client itself, this should be a stateless function that handles the computation no? Ideally a selector that given inputs outputs normalized data? |
Also what do we gain here? I guess it's hard to see how people would use this when they can just mapqueries? |
Or actually we could replace mapqueries entirely. Collocate your graphql state with client state |
Alright, so I got this going...
so it takes a couple runs of mapState to get the result. Which is chillin. Just sucks we have to trycatch! Also this example is pretty useless because it is |
I think next to do is refactor the "selectors" we already have to be inline with something like common redux patterns. Still need to explore 2. of your question. As for 3. i think we can use reselect itself? |
@abhiaiyer91 @stubailo being able to utilize
I think
That would result in something like:
As far as the question in 2.
This could just be another "selector" into the Apollo state.
Can that state be kept in redux and provide similar "selector" methods to access the state? |
@davidwoody But if mapQueriesToProps already maps todos and its data to props, why use mapStateToProps to fetch the same data? Or are you saying that we can use mapStateToProps primarily for selectors that take the data of the apollo store and some other stuff to compute some new type of state? Without that case, mapStateToProps and mapQueries doing the same thing is overkill? EDIT: i see what youre saying, let me try to document the couple flows you would have has a consumer |
@abhiaiyer91 This may or may not be helpful, but this is sort of how I'm thinking about
|
I use global unique id's and nodes (actually using The thing is, ideally this selectors could support get data from store by its id, something like: const mapStateToProps = (state, ownProps) => ({
todo: getFromStoreId(ownProps.id),
}) The default behaviour would be return the entire denormalized data, and may pass an optional |
Well guys I wanted to have some fun, so I made a ton of progress in this direction: https://github.com/stubailo/graphql-anywhere It's a totally standalone library that factors out all of apollo's query execution functionality, and even removes the need for a custom store format. Hope to refactor AC to use this soon, and perhaps make a complementary normalization library - like normalizr, but one that takes advantage of GraphQL's structure. |
Only send request cookie rather than full headers
@gaearon has been talking a ton about a new-ish concept for Redux called "selectors" - basically the idea that your Redux store shape can be an implementation detail of the store logic, and then you use custom functions as the actual public API to get data out.
readQueryFromStore
is basically exactly this for Apollo - it's a selector that takes a GraphQL query and generates that result from the normalized store format. Now that there's a name for this concept and some great recommendations for how to use selectors, we should make sure that taking this approach with Apollo Client makes sense. We might also want to rename our internal functions to map onto this concept so that people familiar with Redux might feel more at home.This can be as simple as exporting the selector properly, and teaching people how to use that in vanilla Redux
connect
or their reducers to do custom GraphQL stuff.@abhiaiyer91 want to take a stab at the design? Since the
ApolloClient
takes some options that affect how denormalization/selecting might work, we might want this to be a function onclient
, something like:With a little bit of cleverness, this API could be extended to work for fetching any appropriately normalized Redux data with a GraphQL query.
The text was updated successfully, but these errors were encountered: