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

QueryManager.transformCache: use WeakCache #11387

Merged
merged 10 commits into from
Nov 29, 2023
5 changes: 5 additions & 0 deletions .changeset/shaggy-sheep-pull.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@apollo/client": patch
---

`QueryManager.transformCache`: use `WeakCache` instead of `WeakMap`
4 changes: 2 additions & 2 deletions .size-limits.json
Original file line number Diff line number Diff line change
@@ -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
Original file line number Diff line number Diff line change
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