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

experimental ApolloClient.getMemoryInternals helper #11409

Merged
merged 71 commits into from
Dec 15, 2023
Merged
Show file tree
Hide file tree
Changes from 57 commits
Commits
Show all changes
71 commits
Select commit Hold shift + click to select a range
d5d8cb1
`print`: use `WeakCache` instead of `WeakMap`
phryneas Nov 16, 2023
29bf59d
format
phryneas Nov 16, 2023
9942e61
pull in memory testing tools from PR 11358
phryneas Nov 17, 2023
b933dfb
Persisted Query Link: improve memory management
phryneas Nov 17, 2023
a117bd0
re-add accidentally removed dependency
phryneas Nov 17, 2023
0a1b718
update api
phryneas Nov 17, 2023
d64eee1
Merge remote-tracking branch 'origin/release-3.9' into pr/print-weakC…
phryneas Nov 17, 2023
bd40e8e
update size limit
phryneas Nov 17, 2023
c712446
Merge branch 'release-3.9' into pr/print-weakCache
phryneas Nov 17, 2023
f84da80
size-limit
phryneas Nov 17, 2023
7485662
Merge branch 'pr/print-weakCache' into pr/persisted-query-weakCache
phryneas Nov 17, 2023
5361820
Merge branch 'release-3.9' into pr/persisted-query-weakCache
phryneas Nov 29, 2023
6ad8e56
fix test failure
phryneas Nov 29, 2023
7cbf8dc
better cleanup of interval/timeout
phryneas Nov 29, 2023
d609c67
Merge remote-tracking branch 'origin/release-3.9' into pr/persisted-q…
phryneas Dec 4, 2023
0521529
apply formatting
phryneas Dec 4, 2023
188dd0a
remove unneccessary type
phryneas Dec 4, 2023
4283908
format again after updating prettier
phryneas Dec 4, 2023
9d3bd68
add central confiuguration for Apollo Client cache sizes
phryneas Dec 4, 2023
825e012
resolve import cycle
phryneas Dec 4, 2023
3762c5e
add exports
phryneas Dec 4, 2023
554240c
reduce cache collection throttle timeout
phryneas Dec 4, 2023
af8b16f
typo in comment
phryneas Dec 4, 2023
6ce2613
experimental `ApolloClient.getCacheStatus` helper
phryneas Dec 4, 2023
147a491
update size-limits
phryneas Dec 4, 2023
324e4c9
fix circular import
phryneas Dec 4, 2023
2e65620
size-limits
phryneas Dec 4, 2023
717dc2d
update type to remove `WeakKey`
phryneas Dec 4, 2023
b2d33d0
api-extractor
phryneas Dec 4, 2023
f09cd6e
Merge branch 'pr/cache-sizes' into pr/getCacheStatus
phryneas Dec 4, 2023
15db6d0
work around ES5 class compat
phryneas Dec 4, 2023
fc605d7
update api-report
phryneas Dec 4, 2023
c503b2d
fix typo in comment
phryneas Dec 4, 2023
bd3ec84
Merge branch 'pr/cache-sizes' into pr/getCacheStatus
phryneas Dec 4, 2023
71318ff
chores
phryneas Dec 4, 2023
96b8d26
changeset
phryneas Dec 4, 2023
6e60676
stop recursion
phryneas Dec 5, 2023
4d9928b
add some internal annotations and optional readonly cacheSize property
phryneas Dec 5, 2023
7d7b7e6
slight remodel, add more caches
phryneas Dec 5, 2023
0ce3f55
chores
phryneas Dec 5, 2023
001da1a
add more caches
phryneas Dec 5, 2023
2ab6bd6
add more caches
phryneas Dec 5, 2023
74df662
chores
phryneas Dec 5, 2023
517b133
add type export
phryneas Dec 6, 2023
06e2e2c
update test
phryneas Dec 6, 2023
f380a57
chores
phryneas Dec 6, 2023
b8a1f0c
formatting
phryneas Dec 6, 2023
28a4289
adjust more tests
phryneas Dec 6, 2023
6a66526
Merge branch 'pr/cache-sizes' into pr/getCacheStatus
phryneas Dec 6, 2023
1a392b2
chores
phryneas Dec 6, 2023
e0bef2a
rename, add more caches
phryneas Dec 12, 2023
0054428
rename file
phryneas Dec 12, 2023
bb85784
chores
phryneas Dec 12, 2023
fee0f92
size-limits
phryneas Dec 12, 2023
21c0c4b
Update wet-forks-rhyme.md
phryneas Dec 12, 2023
9f3db9c
PR feedback, long explanatory comment
phryneas Dec 13, 2023
ade170d
Clean up Prettier, Size-limit, and Api-Extractor
phryneas Dec 13, 2023
ea82c2e
adjust comments
phryneas Dec 14, 2023
61c80a3
remove `expect.objectContaining`
phryneas Dec 14, 2023
2ccd229
flip conditionals
phryneas Dec 14, 2023
e283de3
extract function
phryneas Dec 14, 2023
94d1b85
Merge remote-tracking branch 'origin/release-3.9' into pr/getCacheStatus
phryneas Dec 15, 2023
d84a05b
Clean up Prettier, Size-limit, and Api-Extractor
phryneas Dec 15, 2023
55cb419
report correct size limits
phryneas Dec 15, 2023
c7a65aa
Clean up Prettier, Size-limit, and Api-Extractor
phryneas Dec 15, 2023
4283e22
adjust report shape to roughly match configuration
phryneas Dec 15, 2023
47534c8
Clean up Prettier, Size-limit, and Api-Extractor
phryneas Dec 15, 2023
3fcab50
Update src/utilities/caching/getMemoryInternals.ts
phryneas Dec 15, 2023
a4c4aae
Clean up Prettier, Size-limit, and Api-Extractor
phryneas Dec 15, 2023
6f85640
better types
phryneas Dec 15, 2023
c3ad505
Clean up Prettier, Size-limit, and Api-Extractor
phryneas Dec 15, 2023
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
31 changes: 30 additions & 1 deletion .api-reports/api-report-cache.md
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,10 @@ export abstract class ApolloCache<TSerialized> implements DataProxy {
abstract extract(optimistic?: boolean): TSerialized;
// (undocumented)
gc(): string[];
// Warning: (ae-forgotten-export) The symbol "getApolloCacheMemoryInternals" needs to be exported by the entry point index.d.ts
//
// @internal
getMemoryInternals?: typeof getApolloCacheMemoryInternals;
// (undocumented)
identify(object: StoreObject | Reference): string | undefined;
// (undocumented)
Expand Down Expand Up @@ -474,6 +478,27 @@ export interface FragmentRegistryAPI {
transform<D extends DocumentNode>(document: D): D;
}

// @internal
const getApolloCacheMemoryInternals: (() => {
fragmentQueryDocuments: number | undefined;
}) | undefined;

// @internal
const getInMemoryCacheMemoryInternals: (() => {
addTypenameTransform: number[];
storeReader: {
executeSelectionSet: number | undefined;
executeSubSelectedArray: number | undefined;
};
maybeBroadcastWatch: number | undefined;
fragmentRegistry: {
findFragmentSpreads: number | undefined;
lookup: number | undefined;
transform: number | undefined;
};
fragmentQueryDocuments: number | undefined;
}) | undefined;

// @public (undocumented)
export type IdGetter = (value: IdGetterObj) => string | undefined;

Expand Down Expand Up @@ -513,6 +538,10 @@ export class InMemoryCache extends ApolloCache<NormalizedCacheObject> {
resetResultCache?: boolean;
resetResultIdentities?: boolean;
}): string[];
// Warning: (ae-forgotten-export) The symbol "getInMemoryCacheMemoryInternals" needs to be exported by the entry point index.d.ts
//
// @internal
getMemoryInternals?: typeof getInMemoryCacheMemoryInternals;
// (undocumented)
identify(object: StoreObject | Reference): string | undefined;
// (undocumented)
Expand Down Expand Up @@ -551,7 +580,7 @@ export interface InMemoryCacheConfig extends ApolloReducerConfig {
fragments?: FragmentRegistryAPI;
// (undocumented)
possibleTypes?: PossibleTypesMap;
// (undocumented)
// @deprecated (undocumented)
resultCacheMaxSize?: number;
// (undocumented)
resultCaching?: boolean;
Expand Down
89 changes: 87 additions & 2 deletions .api-reports/api-report-core.md
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,10 @@ export abstract class ApolloCache<TSerialized> implements DataProxy {
abstract extract(optimistic?: boolean): TSerialized;
// (undocumented)
gc(): string[];
// Warning: (ae-forgotten-export) The symbol "getApolloCacheMemoryInternals" needs to be exported by the entry point index.d.ts
//
// @internal
getMemoryInternals?: typeof getApolloCacheMemoryInternals;
// (undocumented)
identify(object: StoreObject | Reference): string | undefined;
// (undocumented)
Expand Down Expand Up @@ -104,6 +108,10 @@ export class ApolloClient<TCacheShape> implements DataProxy {
disableNetworkFetches: boolean;
get documentTransform(): DocumentTransform;
extract(optimistic?: boolean): TCacheShape;
// Warning: (ae-forgotten-export) The symbol "getApolloClientMemoryInternals" needs to be exported by the entry point index.d.ts
//
// @internal
getMemoryInternals?: typeof getApolloClientMemoryInternals;
getObservableQueries(include?: RefetchQueriesInclude): Map<string, ObservableQuery<any>>;
getResolvers(): Resolvers;
// (undocumented)
Expand Down Expand Up @@ -221,10 +229,16 @@ export class ApolloLink {
static execute(link: ApolloLink, operation: GraphQLRequest): Observable<FetchResult>;
// (undocumented)
static from(links: (ApolloLink | RequestHandler)[]): ApolloLink;
// @internal
getMemoryInternals?: () => unknown;
// @internal
readonly left?: ApolloLink;
// (undocumented)
protected onError(error: any, observer?: Observer<FetchResult>): false | void;
// (undocumented)
request(operation: Operation, forward?: NextLink): Observable<FetchResult> | null;
// @internal
readonly right?: ApolloLink;
// (undocumented)
setOnError(fn: ApolloLink["onError"]): this;
// (undocumented)
Expand Down Expand Up @@ -384,6 +398,24 @@ class CacheGroup {
resetCaching(): void;
}

// @public
interface CacheSizes {
canonicalStringify: number;
documentTransform: number;
executeSelectionSet: number;
executeSubSelectedArray: number;
fragmentQueryDocuments: number;
fragmentRegistryFindFragmentSpreads: number;
fragmentRegistryLookup: number;
fragmentRegistryTransform: number;
getVariableDefinitions: number;
maybeBroadcastWatch: number;
parser: number;
persistedQueryHashes: number;
print: number;
queryManagerTransforms: number;
}

// @public (undocumented)
const enum CacheWriteBehavior {
// (undocumented)
Expand Down Expand Up @@ -559,9 +591,16 @@ export class DocumentTransform {
concat(otherTransform: DocumentTransform): DocumentTransform;
// (undocumented)
static identity(): DocumentTransform;
// (undocumented)
readonly left?: DocumentTransform;
resetCache(): void;
// (undocumented)
static split(predicate: (document: DocumentNode) => boolean, left: DocumentTransform, right?: DocumentTransform): DocumentTransform;
readonly right?: DocumentTransform;
// (undocumented)
static split(predicate: (document: DocumentNode) => boolean, left: DocumentTransform, right?: DocumentTransform): DocumentTransform & {
left: DocumentTransform;
right: DocumentTransform;
};
// (undocumented)
transformDocument(document: DocumentNode): DocumentNode;
}
Expand Down Expand Up @@ -860,6 +899,47 @@ export function fromError<T>(errorValue: any): Observable<T>;
// @public (undocumented)
export function fromPromise<T>(promise: Promise<T>): Observable<T>;

// @internal
const getApolloCacheMemoryInternals: (() => {
fragmentQueryDocuments: number | undefined;
}) | undefined;

// @internal
const getApolloClientMemoryInternals: (() => {
limits: CacheSizes;
sizes: {
global: {
print: number | undefined;
parser: number | undefined;
canonicalStringify: number | undefined;
};
links: unknown[];
queryManager: {
Transforms: number;
documentTransforms: number[];
};
cache: {
fragmentQueryDocuments: number | undefined;
} | undefined;
};
}) | undefined;

// @internal
const getInMemoryCacheMemoryInternals: (() => {
addTypenameTransform: number[];
storeReader: {
executeSelectionSet: number | undefined;
executeSubSelectedArray: number | undefined;
};
maybeBroadcastWatch: number | undefined;
fragmentRegistry: {
findFragmentSpreads: number | undefined;
lookup: number | undefined;
transform: number | undefined;
};
fragmentQueryDocuments: number | undefined;
}) | undefined;

export { gql }

// @public (undocumented)
Expand Down Expand Up @@ -973,6 +1053,10 @@ export class InMemoryCache extends ApolloCache<NormalizedCacheObject> {
resetResultCache?: boolean;
resetResultIdentities?: boolean;
}): string[];
// Warning: (ae-forgotten-export) The symbol "getInMemoryCacheMemoryInternals" needs to be exported by the entry point index.d.ts
//
// @internal
getMemoryInternals?: typeof getInMemoryCacheMemoryInternals;
// (undocumented)
identify(object: StoreObject | Reference): string | undefined;
// (undocumented)
Expand Down Expand Up @@ -1013,7 +1097,7 @@ export interface InMemoryCacheConfig extends ApolloReducerConfig {
fragments?: FragmentRegistryAPI;
// (undocumented)
possibleTypes?: PossibleTypesMap;
// (undocumented)
// @deprecated (undocumented)
resultCacheMaxSize?: number;
// (undocumented)
resultCaching?: boolean;
Expand Down Expand Up @@ -2117,6 +2201,7 @@ interface WriteContext extends ReadMergeModifyContext {
// src/core/QueryManager.ts:395:7 - (ae-forgotten-export) The symbol "UpdateQueries" needs to be exported by the entry point index.d.ts
// src/core/watchQueryOptions.ts:253:2 - (ae-forgotten-export) The symbol "UpdateQueryFn" needs to be exported by the entry point index.d.ts
// src/link/http/selectHttpOptionsAndBody.ts:128:32 - (ae-forgotten-export) The symbol "HttpQueryOptions" needs to be exported by the entry point index.d.ts
// src/utilities/caching/getMemoryInternals.ts:66:44 - (ae-forgotten-export) The symbol "CacheSizes" needs to be exported by the entry point index.d.ts

// (No @packageDocumentation comment for this package)

Expand Down
6 changes: 6 additions & 0 deletions .api-reports/api-report-link_batch-http.md
Original file line number Diff line number Diff line change
Expand Up @@ -29,12 +29,18 @@ class ApolloLink {
//
// (undocumented)
static from(links: (ApolloLink | RequestHandler)[]): ApolloLink;
// @internal
getMemoryInternals?: () => unknown;
// @internal
readonly left?: ApolloLink;
// (undocumented)
protected onError(error: any, observer?: Observer<FetchResult>): false | void;
// Warning: (ae-forgotten-export) The symbol "NextLink" needs to be exported by the entry point index.d.ts
//
// (undocumented)
request(operation: Operation, forward?: NextLink): Observable<FetchResult> | null;
// @internal
readonly right?: ApolloLink;
// (undocumented)
setOnError(fn: ApolloLink["onError"]): this;
// Warning: (ae-forgotten-export) The symbol "Operation" needs to be exported by the entry point index.d.ts
Expand Down
6 changes: 6 additions & 0 deletions .api-reports/api-report-link_batch.md
Original file line number Diff line number Diff line change
Expand Up @@ -28,12 +28,18 @@ class ApolloLink {
//
// (undocumented)
static from(links: (ApolloLink | RequestHandler)[]): ApolloLink;
// @internal
getMemoryInternals?: () => unknown;
// @internal
readonly left?: ApolloLink;
// (undocumented)
protected onError(error: any, observer?: Observer<FetchResult>): false | void;
// Warning: (ae-forgotten-export) The symbol "NextLink" needs to be exported by the entry point index.d.ts
//
// (undocumented)
request(operation: Operation, forward?: NextLink): Observable<FetchResult> | null;
// @internal
readonly right?: ApolloLink;
// (undocumented)
setOnError(fn: ApolloLink["onError"]): this;
// Warning: (ae-forgotten-export) The symbol "Operation" needs to be exported by the entry point index.d.ts
Expand Down
6 changes: 6 additions & 0 deletions .api-reports/api-report-link_context.md
Original file line number Diff line number Diff line change
Expand Up @@ -28,12 +28,18 @@ class ApolloLink {
//
// (undocumented)
static from(links: (ApolloLink | RequestHandler)[]): ApolloLink;
// @internal
getMemoryInternals?: () => unknown;
// @internal
readonly left?: ApolloLink;
// (undocumented)
protected onError(error: any, observer?: Observer<FetchResult>): false | void;
// Warning: (ae-forgotten-export) The symbol "NextLink" needs to be exported by the entry point index.d.ts
//
// (undocumented)
request(operation: Operation, forward?: NextLink): Observable<FetchResult> | null;
// @internal
readonly right?: ApolloLink;
// (undocumented)
setOnError(fn: ApolloLink["onError"]): this;
// Warning: (ae-forgotten-export) The symbol "Operation" needs to be exported by the entry point index.d.ts
Expand Down
6 changes: 6 additions & 0 deletions .api-reports/api-report-link_core.md
Original file line number Diff line number Diff line change
Expand Up @@ -23,10 +23,16 @@ export class ApolloLink {
static execute(link: ApolloLink, operation: GraphQLRequest): Observable<FetchResult>;
// (undocumented)
static from(links: (ApolloLink | RequestHandler)[]): ApolloLink;
// @internal
getMemoryInternals?: () => unknown;
// @internal
readonly left?: ApolloLink;
// (undocumented)
protected onError(error: any, observer?: Observer<FetchResult>): false | void;
// (undocumented)
request(operation: Operation, forward?: NextLink): Observable<FetchResult> | null;
// @internal
readonly right?: ApolloLink;
// (undocumented)
setOnError(fn: ApolloLink["onError"]): this;
// (undocumented)
Expand Down
6 changes: 6 additions & 0 deletions .api-reports/api-report-link_error.md
Original file line number Diff line number Diff line change
Expand Up @@ -28,12 +28,18 @@ class ApolloLink {
//
// (undocumented)
static from(links: (ApolloLink | RequestHandler)[]): ApolloLink;
// @internal
getMemoryInternals?: () => unknown;
// @internal
readonly left?: ApolloLink;
// (undocumented)
protected onError(error: any, observer?: Observer<FetchResult>): false | void;
// Warning: (ae-forgotten-export) The symbol "NextLink" needs to be exported by the entry point index.d.ts
//
// (undocumented)
request(operation: Operation, forward?: NextLink): Observable<FetchResult> | null;
// @internal
readonly right?: ApolloLink;
// (undocumented)
setOnError(fn: ApolloLink["onError"]): this;
// Warning: (ae-forgotten-export) The symbol "Operation" needs to be exported by the entry point index.d.ts
Expand Down
6 changes: 6 additions & 0 deletions .api-reports/api-report-link_http.md
Original file line number Diff line number Diff line change
Expand Up @@ -30,12 +30,18 @@ class ApolloLink {
//
// (undocumented)
static from(links: (ApolloLink | RequestHandler)[]): ApolloLink;
// @internal
getMemoryInternals?: () => unknown;
// @internal
readonly left?: ApolloLink;
// (undocumented)
protected onError(error: any, observer?: Observer<FetchResult>): false | void;
// Warning: (ae-forgotten-export) The symbol "NextLink" needs to be exported by the entry point index.d.ts
//
// (undocumented)
request(operation: Operation, forward?: NextLink): Observable<FetchResult> | null;
// @internal
readonly right?: ApolloLink;
// (undocumented)
setOnError(fn: ApolloLink["onError"]): this;
// Warning: (ae-forgotten-export) The symbol "Operation" needs to be exported by the entry point index.d.ts
Expand Down
16 changes: 15 additions & 1 deletion .api-reports/api-report-link_persisted-queries.md
Original file line number Diff line number Diff line change
Expand Up @@ -28,12 +28,18 @@ class ApolloLink {
//
// (undocumented)
static from(links: (ApolloLink | RequestHandler)[]): ApolloLink;
// @internal
getMemoryInternals?: () => unknown;
// @internal
readonly left?: ApolloLink;
// (undocumented)
protected onError(error: any, observer?: Observer<FetchResult>): false | void;
// Warning: (ae-forgotten-export) The symbol "NextLink" needs to be exported by the entry point index.d.ts
//
// (undocumented)
request(operation: Operation, forward?: NextLink): Observable<FetchResult> | null;
// @internal
readonly right?: ApolloLink;
// (undocumented)
setOnError(fn: ApolloLink["onError"]): this;
// Warning: (ae-forgotten-export) The symbol "Operation" needs to be exported by the entry point index.d.ts
Expand All @@ -57,7 +63,15 @@ interface BaseOptions {
// Warning: (ae-forgotten-export) The symbol "ApolloLink" needs to be exported by the entry point index.d.ts
//
// @public (undocumented)
export const createPersistedQueryLink: (options: PersistedQueryLink.Options) => ApolloLink;
export const createPersistedQueryLink: (options: PersistedQueryLink.Options) => ApolloLink & {
resetHashCache: () => void;
} & ({
getMemoryInternals(): {
persistedQueryHashes: number;
};
} | {
getMemoryInternals?: undefined;
});

// @public (undocumented)
interface DefaultContext extends Record<string, any> {
Expand Down
14 changes: 13 additions & 1 deletion .api-reports/api-report-link_remove-typename.md
Original file line number Diff line number Diff line change
Expand Up @@ -28,12 +28,18 @@ class ApolloLink {
//
// (undocumented)
static from(links: (ApolloLink | RequestHandler)[]): ApolloLink;
// @internal
getMemoryInternals?: () => unknown;
// @internal
readonly left?: ApolloLink;
// (undocumented)
protected onError(error: any, observer?: Observer<FetchResult>): false | void;
// Warning: (ae-forgotten-export) The symbol "NextLink" needs to be exported by the entry point index.d.ts
//
// (undocumented)
request(operation: Operation, forward?: NextLink): Observable<FetchResult> | null;
// @internal
readonly right?: ApolloLink;
// (undocumented)
setOnError(fn: ApolloLink["onError"]): this;
// Warning: (ae-forgotten-export) The symbol "Operation" needs to be exported by the entry point index.d.ts
Expand Down Expand Up @@ -160,7 +166,13 @@ type Path = ReadonlyArray<string | number>;
// Warning: (ae-forgotten-export) The symbol "ApolloLink" needs to be exported by the entry point index.d.ts
//
// @public (undocumented)
export function removeTypenameFromVariables(options?: RemoveTypenameFromVariablesOptions): ApolloLink;
export function removeTypenameFromVariables(options?: RemoveTypenameFromVariablesOptions): ApolloLink & ({
getMemoryInternals(): {
getVariableDefinitions: number;
};
} | {
getMemoryInternals?: undefined;
});

// @public (undocumented)
export interface RemoveTypenameFromVariablesOptions {
Expand Down
Loading