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

Cache query documents transformed by InMemoryCache. #3553

Merged
merged 3 commits into from
Jun 6, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions packages/apollo-cache-inmemory/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,9 @@
- Restore non-enumerability of `resultFields[ID_KEY]`.
[PR #3544](https://github.com/apollographql/apollo-client/pull/3544)

- Cache query documents transformed by InMemoryCache.
[PR #3553](https://github.com/apollographql/apollo-client/pull/3553)

### 1.2.2

- Fixed an issue that caused fragment only queries to sometimes fail.
Expand Down
12 changes: 11 additions & 1 deletion packages/apollo-cache-inmemory/src/inMemoryCache.ts
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ export class InMemoryCache extends ApolloCache<NormalizedCacheObject> {
protected optimistic: OptimisticStoreItem[] = [];
private watches: Cache.WatchOptions[] = [];
private addTypename: boolean;
private typenameDocumentCache = new WeakMap<DocumentNode, DocumentNode>();

// Set this while in a transaction to prevent broadcasts...
// don't forget to turn it back on!
Expand Down Expand Up @@ -204,7 +205,16 @@ export class InMemoryCache extends ApolloCache<NormalizedCacheObject> {
}

public transformDocument(document: DocumentNode): DocumentNode {
if (this.addTypename) return addTypenameToDocument(document);
if (this.addTypename) {
let result = this.typenameDocumentCache.get(document);
if (!result) {
this.typenameDocumentCache.set(
document,
(result = addTypenameToDocument(document)),
);
}
return result;
}
return document;
}

Expand Down