-
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
Map query result to another query's cache #706
Comments
This is an interesting idea; maybe instead of mapping a query to a part of another query, instead we should have a mechanism to map to a data id -- so So in this case, we'd say "the root field |
Yes, that would be a nice way to go about it. Here are 2 possible APIs that we could think about:
Which of the 2 seems more natural? Should we expand on one over the other or should we expand on both and see which API makes the most sense? |
This is now implemented! #809 Just some tests to do. |
Thanks so much for implementing this! Would you mind posting a quick snippet of how the new API could be used to solve the issue mentioned above? |
Great! Having this issue as well, the PR would reduce my app's network traffic dramatically. 👍 |
Hoping to get this done and documented before the end of the week! Things have been very busy around here because of the GraphQL Summit. |
It looks like this is now documented here. Thanks for all the hard work! |
Implemented in #921 |
Looking again at the original use case presented in the originating issue description, it doesn't look like result reducers solve this problem because the |
@migueloller I'm not sure I understand what result reducers have to do with cache redirects? |
@helfer, originally I believed that result reducers would solve the issue I mentioned above in #706 (comment). It looks like it's more of a cache redirect issue (as you say). Should a separate issue be opened or this same on reopened (and maybe the title changed)? |
@migueloller Have you looked at #921? I think that should do what you need. |
I'm using Apollo to build a production React Native app and I'm super grateful for all the great work you guys have done. Kudos!
There are a couple of things that I think could improve and I know many of them are already in the works (e.g., reimplementing
loading
logic inreact-apollo
and restructuring the design around fragments inapollo-client
). It's super annoying thatloading
can be undefined sometimes and it's impossible to work with fragments so I'm looking forward to those changes!There is another improvement that I wanted to mention because I'm not sure if it is in the works and I would love
apollo-client
to have something like it.Imagine you have the following 2 queries:
If the second query returns a post that would've been included in the users's post from the first query, there should be no network request. Currently with
apollo-client
, because they're different queries, the cache doesn't know any better.I propose that we add an option to
ApolloClient
, similar todataIdFromObject
, calledqueryIdFromObject
(this name is probably a bad one) that will let you map the result of a query to another query's key in the internal Redux store, with the purpose of improving the cache.Here's how the option would be used for the example above:
Potentially, this option could only be allowed for the root query (I don't see it being beneficial elsewhere) and
dataIdFromObject
could be used internally so that the code above could be simplified to:Regardless, this would greatly reduce the number of trips to the API that the app needs to make.
Thoughts?
EDIT: If the server is Relay compatible, then it would be even simpler because the relevant root query would be
node
and/ornodes
The text was updated successfully, but these errors were encountered: