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

Documentation for custom cache implementations #2484

Closed
migueloller opened this issue Nov 6, 2017 · 13 comments
Closed

Documentation for custom cache implementations #2484

migueloller opened this issue Nov 6, 2017 · 13 comments

Comments

@migueloller
Copy link

Hi there! 👋

I was wondering if there was a plan to document the API for custom cache implementations.

As a huge fan of Apollo and happy user of 1.0, I can't wait to migrate to 2.0 and take advantage of all the awesome new features. Unfortunately, I won't be able to do that until there's a cache implementation with Redux.

Where would be the best place to start learning about the contract needed for the Apollo cache so that a Redux version can be implemented? Also, is the 1.0 implementation close enough so that a Redux implementation of the cache can be extracted from there?

@jbaxleyiii
Copy link
Contributor

@migueloller we absolutely are planning on documenting it 🎉 @kamilkisiela has even started work on an rx-js variant of the InMemoryCache that we should be able to adapt as a guide for redux integration.

I am curious, why is the cache being in redux a blocker for you?

@btroia
Copy link

btroia commented Nov 6, 2017

@jbaxleyiii I'm in the same boat. I need query persistence for certain queries when a user quits/restarts my app. Previously I was using redux-persist to include Apollo data, but with 2.0 all queries will refetch once each time my app is restarted. Or am I missing something? Thanks.

@migueloller
Copy link
Author

@jbaxleyiii, awesome! Great to hear that's on the works.

As to why the Redux cache is a blocker, there are a couple of reasons.

  • We use tools in the Redux ecosystem to manage various things related to state/side effects, including but not limited to:
    • Tracking errors in a central location and sending them to an error reporting service like Sentry
    • Adding offline functionality using tools like redux-persist like @btroia mentioned
  • Using Redux's benefits of time-travel and a better development experience by having state changes and side effects logged by middleware.

There are various things we use that I'm not mentioning here. Also, one could argue that we could move away from these features and use the new programming patterns that Apollo 2.0 allows. Ultimately, though, it would be optimal to adopt these patterns incrementally. Having a cache that uses Redux internally would allow a smooth transition from 1.0 to 2.0 and then we can slowly transition to new patterns as we see fit.

Hopefully these are reasons enough to justify the implementation of a Redux cache. 😅

tl;dr: Having a Redux cache would allow to take advantage of the mature Redux ecosystem and tools while smoothly transitioning into new patterns from Apollo 2.0 as needed.

@simontegg
Copy link

I'm also using redux-persist.
I'm not sure if you consider this bad practice but I also sometimes find it useful to use reselect for querying data that depends in apollo's redux cache, rather than write a whole query.

@lancygoyal
Copy link

GraphQL + Apollo + Redux + React = 😊

@entropitor
Copy link

@jbaxleyiii Another reason why redux can be useful is so we can use reselect as to only compute the denormalized state if the relevant normalized state has changed

@jbmeslin
Copy link

@jbaxleyiii in my case i catch the APOLLO_QUERY_RESULT action in a redux middleware in which i can inspect the extensions of my query. I got some anonymized fields then i call an other graphQL endpoint and finally i dispatch a second time this action with my resolved fields. If there is a solution to do that in V2 (or a better way in V1 ;) ) i agree to say redux is no more needed.

@jbaxleyiii
Copy link
Contributor

@jbmeslin so you get a result, fire another query, then write to the cache with that data? That can be done using an apollo-link now!

@jbmeslin
Copy link

Ok i have to spend some times to understand how works apollo-link and reproduce my use case.

I call => uri1/graphqlX -> {dataX: {}, extensionsX, } in dataX i have some anonymized field listed in extensionsX then i call an other endPoint to resolved these fields => uir2/graphQLY-> {dataY} with this result replace in dataX the anonymized fields with the resolved fields in dataY.

The second query use another URI and the result structure of dataY is not the same as dataX.

@Amareis
Copy link

Amareis commented Apr 10, 2018

Hey, anybody? Where are docs for custom cache implementations? I find some interfaces at https://github.com/apollographql/apollo-client/blob/master/packages/apollo-cache/src/cache.ts but it's very bad docs :)

@hwillson
Copy link
Member

@Amareis The custom cache implementation docs don't exist (yet). This is still something we'd love to get in place though. If anyone is interested in helping out, this issue is now help-wanted 🙏 🙇. Thanks!

@hwillson
Copy link
Member

hwillson commented Aug 5, 2018

To help provide a more clear separation between feature requests / discussions and bugs, and to help clean up the feature request / discussion backlog, Apollo Client feature requests / discussions are now being managed under the https://github.com/apollographql/apollo-feature-requests repository.

This feature request / discussion will be closed here, but anyone interested in migrating this issue to the new repository (to make sure it stays active), can click here to start the migration process. This manual migration process is intended to help identify which of the older feature requests are still considered to be of value to the community. Thanks!

@fbartho
Copy link

fbartho commented Sep 5, 2018

@apollographql apollographql locked and limited conversation to collaborators Sep 18, 2018
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

10 participants