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

📖 Improve cache documentation #2433

Merged

Conversation

martinbonnin
Copy link
Contributor

@martinbonnin martinbonnin commented Jul 8, 2020

Separate HTTP and normalized cache and give more details for the normalized cache.

Closes #2429

@tasomaniac
Copy link
Contributor

Looks awesome. I've read it all and do not have any comment.


</MultiCodeBlock>

Once the dependency added, you can create the `SqlNormalizedCacheFactory`:
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

english nit: Once the dependency is added

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done, I also took this opportunity to switch to imperative voice, that felt more positive:

Once the dependency is added, create the `SqlNormalizedCacheFactory`:

}
```

In the above example, requesting the author of your favorite book with the `AuthorById` query will return a result from the cache if you requested your favorite book before. This is because the author is stored only once in the cache.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What do you think to mention that the selection set of fields should be the same or less than in cache? Otherwise we won;t be able to resolve it.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I added a small explanation and a link to https://www.apollographql.com/blog/the-concepts-of-graphql-bc68bd819be3. Since the process of normalization is the same for all platforms, I'd like to focus on the Android specific parts in this page.

)
// Write to the store. All watchers will be notified
apolloClient.apolloStore.writeAndPublish(BookWithAuthorName(), data).execute()
```
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do you think we should add section like trouble shooting, what user should check first / pay attention to in case of cache miss or other issues?

Also we can mentioned here how to dump the cache content:

Map<KClass<?>, Map<String, Record>> dump = apolloClient.getApolloStore().normalizedCache().dump();
NormalizedCache.prettifyDump(dump)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do you think we should add section like trouble shooting

That's definitely something that could be useful (See #2397). Not sure what to recommend though, did you have something specific in mind?

Also we can mentioned here how to dump the cache content

👍

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think we should start with dump cache. Second we should mention to double check how cache key generated (make sure that there is stable ids). Third mention again about selection set should be the same or less. At least to start with these 3 points.

Maybe later we can expand more.

@martinbonnin martinbonnin merged commit 560448b into apollographql:master Jul 14, 2020
@martinbonnin martinbonnin deleted the doc-2429/cache-documentation branch July 14, 2020 09:35
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Improve documentation on normalized cache
5 participants