Open MattReimer opened 6 years ago
@MattReimer We're working on a new version of apollo-link-state
that replaces the concept of defaults
with more dynamic function based initializers
. These initializer functions can be run to prime the cache in whatever way you see fit, and have access to both the cache and the instantiated Apollo Client instance. These new initializer functions can also be run at any point; they're not limited to being called when Apollo Client is instantiated or when your link chain is first constructed. To address your issue here, you could create a new initializer function that takes care of priming the cache the way you need, by running (async) your initial network query. So in other words, you can do something like:
client.addLocalStateInitializers({
async projectTaxes(client) {
// ... run your query, prime the cache, etc.
},
});
Would this work for you?
Yeah! I think this would be fantastic. Sounds exactly like what I need.
@hwillson that makes sense.
@hwillson Hi! I've seen your "we're working on a new version of apollo-link-state
" response on different issues for this repo, do you have any preview for these changes and estimated date of new release?
me wants to know too
Scott
@Borales @smolinari We'll have something to share hopefully very soon! The beta is almost ready; we just have a few more edge cases to address, as well as additional tests and documentation work. Most of the outstanding issues in this repository have been addressed by the new local state project (the issues in this repo that are tagged with ac-local-state-ready
), so we're very close. It would be awesome to have the beta ready before GraphQL Summit (Nov. 7th), so🤞!
@hwillson any news about release date?
@hwillson - would love to test out the beta, ran into this problem with our product
It's November 7th. Please do give us an update about the update. :)
Scott
Looks like apollo-link-state
is being merged into apollo-client
(https://github.com/apollographql/apollo-client/compare/hwillson/link-state-merge)
Ohh.. that is a lot of opinionation to be packing into the core.
Scott
https://summit-2018-apollo-client.netlify.com/ "What's next for Apollo Client" presentation slides from yesterday (there are a few words about state management - it's going to be merged into apollo-client
)
Any news on this, ran into same problem looking for solution, even something quick and dirty to solve problem. Is there a way to use ‘client’ in resolver to make query?
@pulpfree the client is available in the context
parameter of the resolver. I am also facing the same use case and wonder if this is the right way to go...
I have a case where my derived state depends on a query to the server. I realize that
cache.readQuery
only reads from the cache so if I haven't already run theprojQuery
I won't get anything back.Sure enough I get the dreaded error:
So how can I write my resolver with a dependency to the server data? All I have t make queries here is the
cache
object and that doesn't seem to have aquery
function attached to it?My resolver that I use with
withClientState
looks like this: