-
Notifications
You must be signed in to change notification settings - Fork 1.5k
[bestpractices] Add caching section to talk about identifiers #70
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
Conversation
Goal here was to have the article establish three major things:
@stubailo - really interested in your thoughts on this one , I tried to incorporate some of what you wrote up in https://medium.com/apollo-stack/graphql-at-facebook-by-dan-schafer-38d65ef075af#.x1mwck563 |
Going to take a look in a bit! |
I don't think you need a globally unique id for caching per se. You pretty much always have an object type, so as long as you have a per-type-unique id, it should be fine for caching. Ember.js requires this, for example - in the ember store, every object needs both a type and a per-type-unique-id. So to me this is one way to do it but I wouldn't really describe it as best practices, to think in terms of "globally unique ids". |
@lacker yeah that's about what we do in our example app: https://github.com/apollostack/GitHunt-React/blob/a1756d31ac5f6c1d048eab642b5b507c91c302c2/ui/client.js#L43 I think the way this section is worded has enough caveats that it makes sense to me. I think it's reasonable to say that life becomes a bit easier if you have unique IDs provided by the server, but this page reinforces that it's not a hard requirement. |
OK, YOLO let's run with it 🏃 |
permalink: /learn/caching/ | ||
--- | ||
|
||
> Providing Object Identifiers allows clients to build rich caches |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I disagree that this is associated with whether or not it is possible to build a rich cache, since it's definitely achievable without one. So I think this is a best practice, but not because it's easier to cache - it just makes your API cleaner since you have a consistent source of IDs for all objects.
This looks good. Something to mention just on this thread is that we've been toying with a |
Yeah for sure. |
I'm not sure if this is relevant here, but UUID-based caches are in general not enough for Relay-style patterns that allow refetching based on these IDs. I guess maybe this is one of those things that Relay 2 fixes and makes non-existent, but I had to think a bit before realizing why I couldn't just use my UUIDs as my global IDs for my Relay-compatible GraphQL server. |
* APIReference-Utilities translation done Signed-off-by: Jonir Rings <[email protected]> * 修正用词,添加几个标题的翻译 Signed-off-by: Jonir Rings <[email protected]> * 统一“根模块”这个用词 Signed-off-by: Jonir Rings <[email protected]>
Add a caching section, talking about how to replace a URL-based cache. This mentions globally unique identifier as a recommendation, describes how to use additional fields for backwards compatibility, then talks about how you can also allow the client to derive this, which is ideal in situations where existing APIs already have an established pattern for what ID means.