Skip to content

Commit

Permalink
QueryManager.transformCache: use WeakCache (#11387)
Browse files Browse the repository at this point in the history
Co-authored-by: phryneas <phryneas@users.noreply.github.com>
  • Loading branch information
phryneas and phryneas committed Nov 29, 2023
1 parent 25e2cb4 commit 4dce867
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 5 deletions.
5 changes: 5 additions & 0 deletions .changeset/shaggy-sheep-pull.md
@@ -0,0 +1,5 @@
---
"@apollo/client": patch
---

`QueryManager.transformCache`: use `WeakCache` instead of `WeakMap`
4 changes: 2 additions & 2 deletions .size-limits.json
@@ -1,4 +1,4 @@
{
"dist/apollo-client.min.cjs": 38625,
"import { ApolloClient, InMemoryCache, HttpLink } from \"dist/index.js\" (production)": 32203
"dist/apollo-client.min.cjs": 38630,
"import { ApolloClient, InMemoryCache, HttpLink } from \"dist/index.js\" (production)": 32213
}
6 changes: 3 additions & 3 deletions src/core/QueryManager.ts
Expand Up @@ -4,6 +4,7 @@ import type { DocumentNode } from "graphql";
// TODO(brian): A hack until this issue is resolved (https://github.com/graphql/graphql-js/issues/3356)
type OperationTypeNode = any;
import { equal } from "@wry/equality";
import { WeakCache } from "@wry/caches";

import type { ApolloLink, FetchResult } from "../link/core/index.js";
import { execute } from "../link/core/index.js";
Expand All @@ -27,7 +28,6 @@ import {
hasClientExports,
graphQLResultHasError,
getGraphQLErrorsFromResult,
canUseWeakMap,
Observable,
asyncMap,
isNonEmptyArray,
Expand Down Expand Up @@ -651,10 +651,10 @@ export class QueryManager<TStore> {
return this.documentTransform.transformDocument(document);
}

private transformCache = new (canUseWeakMap ? WeakMap : Map)<
private transformCache = new WeakCache<
DocumentNode,
TransformCacheEntry
>();
>(/** TODO: decide on a maximum size (will do all max sizes in a combined separate PR) */);

public getDocumentInfo(document: DocumentNode) {
const { transformCache } = this;
Expand Down

0 comments on commit 4dce867

Please sign in to comment.