diff --git a/.api-reports/api-report-cache.md b/.api-reports/api-report-cache.md index 1f2efd837fc..8cd3cb53be1 100644 --- a/.api-reports/api-report-cache.md +++ b/.api-reports/api-report-cache.md @@ -30,6 +30,10 @@ export abstract class ApolloCache 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) @@ -474,6 +478,33 @@ export interface FragmentRegistryAPI { transform(document: D): D; } +// @internal +const getApolloCacheMemoryInternals: (() => { + cache: { + fragmentQueryDocuments: number | undefined; + }; +}) | undefined; + +// @internal +const getInMemoryCacheMemoryInternals: (() => { + addTypenameDocumentTransform: { + cache: number; + }[]; + inMemoryCache: { + executeSelectionSet: number | undefined; + executeSubSelectedArray: number | undefined; + maybeBroadcastWatch: number | undefined; + }; + fragmentRegistry: { + findFragmentSpreads: number | undefined; + lookup: number | undefined; + transform: number | undefined; + }; + cache: { + fragmentQueryDocuments: number | undefined; + }; +}) | undefined; + // @public (undocumented) export type IdGetter = (value: IdGetterObj) => string | undefined; @@ -513,6 +544,10 @@ export class InMemoryCache extends ApolloCache { 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) diff --git a/.api-reports/api-report-core.md b/.api-reports/api-report-core.md index d2ec18f333b..16c8ea5ed87 100644 --- a/.api-reports/api-report-core.md +++ b/.api-reports/api-report-core.md @@ -46,6 +46,10 @@ export abstract class ApolloCache 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) @@ -104,6 +108,10 @@ export class ApolloClient 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>; getResolvers(): Resolvers; // (undocumented) @@ -221,10 +229,16 @@ export class ApolloLink { static execute(link: ApolloLink, operation: GraphQLRequest): Observable; // (undocumented) static from(links: (ApolloLink | RequestHandler)[]): ApolloLink; + // @internal + getMemoryInternals?: () => unknown; + // @internal + readonly left?: ApolloLink; // (undocumented) protected onError(error: any, observer?: Observer): false | void; // (undocumented) request(operation: Operation, forward?: NextLink): Observable | null; + // @internal + readonly right?: ApolloLink; // (undocumented) setOnError(fn: ApolloLink["onError"]): this; // (undocumented) @@ -559,9 +573,16 @@ export class DocumentTransform { concat(otherTransform: DocumentTransform): DocumentTransform; // (undocumented) static identity(): DocumentTransform; + // @internal + readonly left?: DocumentTransform; resetCache(): void; + // @internal + readonly right?: DocumentTransform; // (undocumented) - static split(predicate: (document: DocumentNode) => boolean, left: DocumentTransform, right?: DocumentTransform): DocumentTransform; + static split(predicate: (document: DocumentNode) => boolean, left: DocumentTransform, right?: DocumentTransform): DocumentTransform & { + left: DocumentTransform; + right: DocumentTransform; + }; // (undocumented) transformDocument(document: DocumentNode): DocumentNode; } @@ -860,6 +881,68 @@ export function fromError(errorValue: any): Observable; // @public (undocumented) export function fromPromise(promise: Promise): Observable; +// @internal +const getApolloCacheMemoryInternals: (() => { + cache: { + fragmentQueryDocuments: number | undefined; + }; +}) | undefined; + +// @internal +const getApolloClientMemoryInternals: (() => { + limits: { + [k: string]: number; + }; + sizes: { + cache?: { + fragmentQueryDocuments: number | undefined; + } | undefined; + addTypenameDocumentTransform?: { + cache: number; + }[] | undefined; + inMemoryCache?: { + executeSelectionSet: number | undefined; + executeSubSelectedArray: number | undefined; + maybeBroadcastWatch: number | undefined; + } | undefined; + fragmentRegistry?: { + findFragmentSpreads: number | undefined; + lookup: number | undefined; + transform: number | undefined; + } | undefined; + print: number | undefined; + parser: number | undefined; + canonicalStringify: number | undefined; + links: unknown[]; + queryManager: { + getDocumentInfo: number; + documentTransforms: { + cache: number; + }[]; + }; + }; +}) | undefined; + +// @internal +const getInMemoryCacheMemoryInternals: (() => { + addTypenameDocumentTransform: { + cache: number; + }[]; + inMemoryCache: { + executeSelectionSet: number | undefined; + executeSubSelectedArray: number | undefined; + maybeBroadcastWatch: number | undefined; + }; + fragmentRegistry: { + findFragmentSpreads: number | undefined; + lookup: number | undefined; + transform: number | undefined; + }; + cache: { + fragmentQueryDocuments: number | undefined; + }; +}) | undefined; + export { gql } // @public (undocumented) @@ -973,6 +1056,10 @@ export class InMemoryCache extends ApolloCache { 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) diff --git a/.api-reports/api-report-link_batch-http.md b/.api-reports/api-report-link_batch-http.md index 4ea94f13b7b..569450e1771 100644 --- a/.api-reports/api-report-link_batch-http.md +++ b/.api-reports/api-report-link_batch-http.md @@ -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): 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 | 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 diff --git a/.api-reports/api-report-link_batch.md b/.api-reports/api-report-link_batch.md index 7562ad80181..a547973287d 100644 --- a/.api-reports/api-report-link_batch.md +++ b/.api-reports/api-report-link_batch.md @@ -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): 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 | 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 diff --git a/.api-reports/api-report-link_context.md b/.api-reports/api-report-link_context.md index bd2790f5381..af79db73e52 100644 --- a/.api-reports/api-report-link_context.md +++ b/.api-reports/api-report-link_context.md @@ -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): 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 | 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 diff --git a/.api-reports/api-report-link_core.md b/.api-reports/api-report-link_core.md index e711dfe7fc1..f488d284b51 100644 --- a/.api-reports/api-report-link_core.md +++ b/.api-reports/api-report-link_core.md @@ -23,10 +23,16 @@ export class ApolloLink { static execute(link: ApolloLink, operation: GraphQLRequest): Observable; // (undocumented) static from(links: (ApolloLink | RequestHandler)[]): ApolloLink; + // @internal + getMemoryInternals?: () => unknown; + // @internal + readonly left?: ApolloLink; // (undocumented) protected onError(error: any, observer?: Observer): false | void; // (undocumented) request(operation: Operation, forward?: NextLink): Observable | null; + // @internal + readonly right?: ApolloLink; // (undocumented) setOnError(fn: ApolloLink["onError"]): this; // (undocumented) diff --git a/.api-reports/api-report-link_error.md b/.api-reports/api-report-link_error.md index febf5b6be00..af048d6fe6b 100644 --- a/.api-reports/api-report-link_error.md +++ b/.api-reports/api-report-link_error.md @@ -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): 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 | 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 diff --git a/.api-reports/api-report-link_http.md b/.api-reports/api-report-link_http.md index 3849a3649df..30f6fa9210c 100644 --- a/.api-reports/api-report-link_http.md +++ b/.api-reports/api-report-link_http.md @@ -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): 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 | 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 diff --git a/.api-reports/api-report-link_persisted-queries.md b/.api-reports/api-report-link_persisted-queries.md index 353d48364e6..14e7a0b47db 100644 --- a/.api-reports/api-report-link_persisted-queries.md +++ b/.api-reports/api-report-link_persisted-queries.md @@ -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): 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 | 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 @@ -59,7 +65,15 @@ interface BaseOptions { // @public (undocumented) export const createPersistedQueryLink: (options: PersistedQueryLink.Options) => ApolloLink & { resetHashCache: () => void; -}; +} & ({ + getMemoryInternals(): { + PersistedQueryLink: { + persistedQueryHashes: number; + }; + }; +} | { + getMemoryInternals?: undefined; +}); // @public (undocumented) interface DefaultContext extends Record { diff --git a/.api-reports/api-report-link_remove-typename.md b/.api-reports/api-report-link_remove-typename.md index ddec205b0ac..f50798f5f02 100644 --- a/.api-reports/api-report-link_remove-typename.md +++ b/.api-reports/api-report-link_remove-typename.md @@ -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): 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 | 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 @@ -160,7 +166,15 @@ type Path = ReadonlyArray; // 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(): { + removeTypenameFromVariables: { + getVariableDefinitions: number; + }; + }; +} | { + getMemoryInternals?: undefined; +}); // @public (undocumented) export interface RemoveTypenameFromVariablesOptions { diff --git a/.api-reports/api-report-link_retry.md b/.api-reports/api-report-link_retry.md index 1c3d0f2557d..a4a61a6ea1d 100644 --- a/.api-reports/api-report-link_retry.md +++ b/.api-reports/api-report-link_retry.md @@ -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): 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 | 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 diff --git a/.api-reports/api-report-link_schema.md b/.api-reports/api-report-link_schema.md index 31712ec362d..fcbee50828b 100644 --- a/.api-reports/api-report-link_schema.md +++ b/.api-reports/api-report-link_schema.md @@ -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): 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 | 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 diff --git a/.api-reports/api-report-link_subscriptions.md b/.api-reports/api-report-link_subscriptions.md index 5b5e1585f6e..8745a5772cb 100644 --- a/.api-reports/api-report-link_subscriptions.md +++ b/.api-reports/api-report-link_subscriptions.md @@ -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): 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 | 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 diff --git a/.api-reports/api-report-link_ws.md b/.api-reports/api-report-link_ws.md index 4ee65142d54..72a8165e4f0 100644 --- a/.api-reports/api-report-link_ws.md +++ b/.api-reports/api-report-link_ws.md @@ -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): 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 | 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 diff --git a/.api-reports/api-report-react.md b/.api-reports/api-report-react.md index 7a8606ad8fe..4b1402c6440 100644 --- a/.api-reports/api-report-react.md +++ b/.api-reports/api-report-react.md @@ -41,6 +41,10 @@ abstract class ApolloCache 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; // Warning: (ae-forgotten-export) The symbol "StoreObject" needs to be exported by the entry point index.d.ts // // (undocumented) @@ -115,6 +119,10 @@ class ApolloClient implements DataProxy { // Warning: (ae-forgotten-export) The symbol "DocumentTransform" needs to be exported by the entry point index.d.ts 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; // Warning: (ae-forgotten-export) The symbol "RefetchQueriesInclude" needs to be exported by the entry point index.d.ts getObservableQueries(include?: RefetchQueriesInclude): Map>; getResolvers(): Resolvers; @@ -281,12 +289,18 @@ class ApolloLink { // // (undocumented) static from(links: (ApolloLink | RequestHandler)[]): ApolloLink; + // @internal + getMemoryInternals?: () => unknown; + // @internal + readonly left?: ApolloLink; // (undocumented) protected onError(error: any, observer?: Observer): 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 | 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 @@ -678,9 +692,16 @@ class DocumentTransform { concat(otherTransform: DocumentTransform): DocumentTransform; // (undocumented) static identity(): DocumentTransform; + // @internal + readonly left?: DocumentTransform; resetCache(): void; + // @internal + readonly right?: DocumentTransform; // (undocumented) - static split(predicate: (document: DocumentNode) => boolean, left: DocumentTransform, right?: DocumentTransform): DocumentTransform; + static split(predicate: (document: DocumentNode) => boolean, left: DocumentTransform, right?: DocumentTransform): DocumentTransform & { + left: DocumentTransform; + right: DocumentTransform; + }; // (undocumented) transformDocument(document: DocumentNode): DocumentNode; } @@ -815,6 +836,48 @@ interface FulfilledPromise extends Promise { value: TValue; } +// @internal +const getApolloCacheMemoryInternals: (() => { + cache: { + fragmentQueryDocuments: number | undefined; + }; +}) | undefined; + +// @internal +const getApolloClientMemoryInternals: (() => { + limits: { + [k: string]: number; + }; + sizes: { + cache?: { + fragmentQueryDocuments: number | undefined; + } | undefined; + addTypenameDocumentTransform?: { + cache: number; + }[] | undefined; + inMemoryCache?: { + executeSelectionSet: number | undefined; + executeSubSelectedArray: number | undefined; + maybeBroadcastWatch: number | undefined; + } | undefined; + fragmentRegistry?: { + findFragmentSpreads: number | undefined; + lookup: number | undefined; + transform: number | undefined; + } | undefined; + print: number | undefined; + parser: number | undefined; + canonicalStringify: number | undefined; + links: unknown[]; + queryManager: { + getDocumentInfo: number; + documentTransforms: { + cache: number; + }[]; + }; + }; +}) | undefined; + // @public (undocumented) export function getApolloContext(): ReactTypes.Context; diff --git a/.api-reports/api-report-react_components.md b/.api-reports/api-report-react_components.md index b009330d47e..96429688c38 100644 --- a/.api-reports/api-report-react_components.md +++ b/.api-reports/api-report-react_components.md @@ -41,6 +41,10 @@ abstract class ApolloCache 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; // Warning: (ae-forgotten-export) The symbol "StoreObject" needs to be exported by the entry point index.d.ts // // (undocumented) @@ -115,6 +119,10 @@ class ApolloClient implements DataProxy { // Warning: (ae-forgotten-export) The symbol "DocumentTransform" needs to be exported by the entry point index.d.ts 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; // Warning: (ae-forgotten-export) The symbol "RefetchQueriesInclude" needs to be exported by the entry point index.d.ts getObservableQueries(include?: RefetchQueriesInclude): Map>; getResolvers(): Resolvers; @@ -259,12 +267,18 @@ class ApolloLink { // // (undocumented) static from(links: (ApolloLink | RequestHandler)[]): ApolloLink; + // @internal + getMemoryInternals?: () => unknown; + // @internal + readonly left?: ApolloLink; // (undocumented) protected onError(error: any, observer?: Observer): 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 | 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 @@ -592,9 +606,16 @@ class DocumentTransform { concat(otherTransform: DocumentTransform): DocumentTransform; // (undocumented) static identity(): DocumentTransform; + // @internal + readonly left?: DocumentTransform; resetCache(): void; + // @internal + readonly right?: DocumentTransform; // (undocumented) - static split(predicate: (document: DocumentNode) => boolean, left: DocumentTransform, right?: DocumentTransform): DocumentTransform; + static split(predicate: (document: DocumentNode) => boolean, left: DocumentTransform, right?: DocumentTransform): DocumentTransform & { + left: DocumentTransform; + right: DocumentTransform; + }; // (undocumented) transformDocument(document: DocumentNode): DocumentNode; } @@ -697,6 +718,48 @@ interface FragmentMap { // @public (undocumented) type FragmentMatcher = (rootValue: any, typeCondition: string, context: any) => boolean; +// @internal +const getApolloCacheMemoryInternals: (() => { + cache: { + fragmentQueryDocuments: number | undefined; + }; +}) | undefined; + +// @internal +const getApolloClientMemoryInternals: (() => { + limits: { + [k: string]: number; + }; + sizes: { + cache?: { + fragmentQueryDocuments: number | undefined; + } | undefined; + addTypenameDocumentTransform?: { + cache: number; + }[] | undefined; + inMemoryCache?: { + executeSelectionSet: number | undefined; + executeSubSelectedArray: number | undefined; + maybeBroadcastWatch: number | undefined; + } | undefined; + fragmentRegistry?: { + findFragmentSpreads: number | undefined; + lookup: number | undefined; + transform: number | undefined; + } | undefined; + print: number | undefined; + parser: number | undefined; + canonicalStringify: number | undefined; + links: unknown[]; + queryManager: { + getDocumentInfo: number; + documentTransforms: { + cache: number; + }[]; + }; + }; +}) | undefined; + // @public (undocumented) type GraphQLErrors = ReadonlyArray; diff --git a/.api-reports/api-report-react_context.md b/.api-reports/api-report-react_context.md index ead8fac4345..48fee485c29 100644 --- a/.api-reports/api-report-react_context.md +++ b/.api-reports/api-report-react_context.md @@ -40,6 +40,10 @@ abstract class ApolloCache 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; // Warning: (ae-forgotten-export) The symbol "StoreObject" needs to be exported by the entry point index.d.ts // // (undocumented) @@ -114,6 +118,10 @@ class ApolloClient implements DataProxy { // Warning: (ae-forgotten-export) The symbol "DocumentTransform" needs to be exported by the entry point index.d.ts 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; // Warning: (ae-forgotten-export) The symbol "RefetchQueriesInclude" needs to be exported by the entry point index.d.ts getObservableQueries(include?: RefetchQueriesInclude): Map>; getResolvers(): Resolvers; @@ -279,12 +287,18 @@ class ApolloLink { // // (undocumented) static from(links: (ApolloLink | RequestHandler)[]): ApolloLink; + // @internal + getMemoryInternals?: () => unknown; + // @internal + readonly left?: ApolloLink; // (undocumented) protected onError(error: any, observer?: Observer): 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 | 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 @@ -575,9 +589,16 @@ class DocumentTransform { concat(otherTransform: DocumentTransform): DocumentTransform; // (undocumented) static identity(): DocumentTransform; + // @internal + readonly left?: DocumentTransform; resetCache(): void; + // @internal + readonly right?: DocumentTransform; // (undocumented) - static split(predicate: (document: DocumentNode) => boolean, left: DocumentTransform, right?: DocumentTransform): DocumentTransform; + static split(predicate: (document: DocumentNode) => boolean, left: DocumentTransform, right?: DocumentTransform): DocumentTransform & { + left: DocumentTransform; + right: DocumentTransform; + }; // (undocumented) transformDocument(document: DocumentNode): DocumentNode; } @@ -680,6 +701,48 @@ interface FragmentMap { // @public (undocumented) type FragmentMatcher = (rootValue: any, typeCondition: string, context: any) => boolean; +// @internal +const getApolloCacheMemoryInternals: (() => { + cache: { + fragmentQueryDocuments: number | undefined; + }; +}) | undefined; + +// @internal +const getApolloClientMemoryInternals: (() => { + limits: { + [k: string]: number; + }; + sizes: { + cache?: { + fragmentQueryDocuments: number | undefined; + } | undefined; + addTypenameDocumentTransform?: { + cache: number; + }[] | undefined; + inMemoryCache?: { + executeSelectionSet: number | undefined; + executeSubSelectedArray: number | undefined; + maybeBroadcastWatch: number | undefined; + } | undefined; + fragmentRegistry?: { + findFragmentSpreads: number | undefined; + lookup: number | undefined; + transform: number | undefined; + } | undefined; + print: number | undefined; + parser: number | undefined; + canonicalStringify: number | undefined; + links: unknown[]; + queryManager: { + getDocumentInfo: number; + documentTransforms: { + cache: number; + }[]; + }; + }; +}) | undefined; + // @public (undocumented) export function getApolloContext(): ReactTypes.Context; diff --git a/.api-reports/api-report-react_hoc.md b/.api-reports/api-report-react_hoc.md index 7fde0ee923b..1a4c9bbedc9 100644 --- a/.api-reports/api-report-react_hoc.md +++ b/.api-reports/api-report-react_hoc.md @@ -40,6 +40,10 @@ abstract class ApolloCache 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; // Warning: (ae-forgotten-export) The symbol "StoreObject" needs to be exported by the entry point index.d.ts // // (undocumented) @@ -114,6 +118,10 @@ class ApolloClient implements DataProxy { // Warning: (ae-forgotten-export) The symbol "DocumentTransform" needs to be exported by the entry point index.d.ts 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; // Warning: (ae-forgotten-export) The symbol "RefetchQueriesInclude" needs to be exported by the entry point index.d.ts getObservableQueries(include?: RefetchQueriesInclude): Map>; getResolvers(): Resolvers; @@ -258,12 +266,18 @@ class ApolloLink { // // (undocumented) static from(links: (ApolloLink | RequestHandler)[]): ApolloLink; + // @internal + getMemoryInternals?: () => unknown; + // @internal + readonly left?: ApolloLink; // (undocumented) protected onError(error: any, observer?: Observer): 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 | 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 @@ -577,9 +591,16 @@ class DocumentTransform { concat(otherTransform: DocumentTransform): DocumentTransform; // (undocumented) static identity(): DocumentTransform; + // @internal + readonly left?: DocumentTransform; resetCache(): void; + // @internal + readonly right?: DocumentTransform; // (undocumented) - static split(predicate: (document: DocumentNode) => boolean, left: DocumentTransform, right?: DocumentTransform): DocumentTransform; + static split(predicate: (document: DocumentNode) => boolean, left: DocumentTransform, right?: DocumentTransform): DocumentTransform & { + left: DocumentTransform; + right: DocumentTransform; + }; // (undocumented) transformDocument(document: DocumentNode): DocumentNode; } @@ -691,6 +712,48 @@ interface FragmentMap { // @public (undocumented) type FragmentMatcher = (rootValue: any, typeCondition: string, context: any) => boolean; +// @internal +const getApolloCacheMemoryInternals: (() => { + cache: { + fragmentQueryDocuments: number | undefined; + }; +}) | undefined; + +// @internal +const getApolloClientMemoryInternals: (() => { + limits: { + [k: string]: number; + }; + sizes: { + cache?: { + fragmentQueryDocuments: number | undefined; + } | undefined; + addTypenameDocumentTransform?: { + cache: number; + }[] | undefined; + inMemoryCache?: { + executeSelectionSet: number | undefined; + executeSubSelectedArray: number | undefined; + maybeBroadcastWatch: number | undefined; + } | undefined; + fragmentRegistry?: { + findFragmentSpreads: number | undefined; + lookup: number | undefined; + transform: number | undefined; + } | undefined; + print: number | undefined; + parser: number | undefined; + canonicalStringify: number | undefined; + links: unknown[]; + queryManager: { + getDocumentInfo: number; + documentTransforms: { + cache: number; + }[]; + }; + }; +}) | undefined; + // @public (undocumented) export function graphql> & Partial>>(document: DocumentNode, operationOptions?: OperationOption): (WrappedComponent: ReactTypes.ComponentType) => ReactTypes.ComponentClass; diff --git a/.api-reports/api-report-react_hooks.md b/.api-reports/api-report-react_hooks.md index 02ae3dbf3b9..457f93bddd0 100644 --- a/.api-reports/api-report-react_hooks.md +++ b/.api-reports/api-report-react_hooks.md @@ -39,6 +39,10 @@ abstract class ApolloCache 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; // Warning: (ae-forgotten-export) The symbol "StoreObject" needs to be exported by the entry point index.d.ts // // (undocumented) @@ -113,6 +117,10 @@ class ApolloClient implements DataProxy { // Warning: (ae-forgotten-export) The symbol "DocumentTransform" needs to be exported by the entry point index.d.ts 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; // Warning: (ae-forgotten-export) The symbol "RefetchQueriesInclude" needs to be exported by the entry point index.d.ts getObservableQueries(include?: RefetchQueriesInclude): Map>; getResolvers(): Resolvers; @@ -257,12 +265,18 @@ class ApolloLink { // // (undocumented) static from(links: (ApolloLink | RequestHandler)[]): ApolloLink; + // @internal + getMemoryInternals?: () => unknown; + // @internal + readonly left?: ApolloLink; // (undocumented) protected onError(error: any, observer?: Observer): 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 | 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 @@ -649,9 +663,16 @@ class DocumentTransform { concat(otherTransform: DocumentTransform): DocumentTransform; // (undocumented) static identity(): DocumentTransform; + // @internal + readonly left?: DocumentTransform; resetCache(): void; + // @internal + readonly right?: DocumentTransform; // (undocumented) - static split(predicate: (document: DocumentNode) => boolean, left: DocumentTransform, right?: DocumentTransform): DocumentTransform; + static split(predicate: (document: DocumentNode) => boolean, left: DocumentTransform, right?: DocumentTransform): DocumentTransform & { + left: DocumentTransform; + right: DocumentTransform; + }; // (undocumented) transformDocument(document: DocumentNode): DocumentNode; } @@ -775,6 +796,48 @@ interface FulfilledPromise extends Promise { value: TValue; } +// @internal +const getApolloCacheMemoryInternals: (() => { + cache: { + fragmentQueryDocuments: number | undefined; + }; +}) | undefined; + +// @internal +const getApolloClientMemoryInternals: (() => { + limits: { + [k: string]: number; + }; + sizes: { + cache?: { + fragmentQueryDocuments: number | undefined; + } | undefined; + addTypenameDocumentTransform?: { + cache: number; + }[] | undefined; + inMemoryCache?: { + executeSelectionSet: number | undefined; + executeSubSelectedArray: number | undefined; + maybeBroadcastWatch: number | undefined; + } | undefined; + fragmentRegistry?: { + findFragmentSpreads: number | undefined; + lookup: number | undefined; + transform: number | undefined; + } | undefined; + print: number | undefined; + parser: number | undefined; + canonicalStringify: number | undefined; + links: unknown[]; + queryManager: { + getDocumentInfo: number; + documentTransforms: { + cache: number; + }[]; + }; + }; +}) | undefined; + // @public (undocumented) type GraphQLErrors = ReadonlyArray; diff --git a/.api-reports/api-report-react_ssr.md b/.api-reports/api-report-react_ssr.md index 923a6b2f00a..74218bc5e08 100644 --- a/.api-reports/api-report-react_ssr.md +++ b/.api-reports/api-report-react_ssr.md @@ -40,6 +40,10 @@ abstract class ApolloCache 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; // Warning: (ae-forgotten-export) The symbol "StoreObject" needs to be exported by the entry point index.d.ts // // (undocumented) @@ -114,6 +118,10 @@ class ApolloClient implements DataProxy { // Warning: (ae-forgotten-export) The symbol "DocumentTransform" needs to be exported by the entry point index.d.ts 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; // Warning: (ae-forgotten-export) The symbol "RefetchQueriesInclude" needs to be exported by the entry point index.d.ts getObservableQueries(include?: RefetchQueriesInclude): Map>; getResolvers(): Resolvers; @@ -258,12 +266,18 @@ class ApolloLink { // // (undocumented) static from(links: (ApolloLink | RequestHandler)[]): ApolloLink; + // @internal + getMemoryInternals?: () => unknown; + // @internal + readonly left?: ApolloLink; // (undocumented) protected onError(error: any, observer?: Observer): 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 | 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 @@ -545,9 +559,16 @@ class DocumentTransform { concat(otherTransform: DocumentTransform): DocumentTransform; // (undocumented) static identity(): DocumentTransform; + // @internal + readonly left?: DocumentTransform; resetCache(): void; + // @internal + readonly right?: DocumentTransform; // (undocumented) - static split(predicate: (document: DocumentNode) => boolean, left: DocumentTransform, right?: DocumentTransform): DocumentTransform; + static split(predicate: (document: DocumentNode) => boolean, left: DocumentTransform, right?: DocumentTransform): DocumentTransform & { + left: DocumentTransform; + right: DocumentTransform; + }; // (undocumented) transformDocument(document: DocumentNode): DocumentNode; } @@ -650,6 +671,48 @@ interface FragmentMap { // @public (undocumented) type FragmentMatcher = (rootValue: any, typeCondition: string, context: any) => boolean; +// @internal +const getApolloCacheMemoryInternals: (() => { + cache: { + fragmentQueryDocuments: number | undefined; + }; +}) | undefined; + +// @internal +const getApolloClientMemoryInternals: (() => { + limits: { + [k: string]: number; + }; + sizes: { + cache?: { + fragmentQueryDocuments: number | undefined; + } | undefined; + addTypenameDocumentTransform?: { + cache: number; + }[] | undefined; + inMemoryCache?: { + executeSelectionSet: number | undefined; + executeSubSelectedArray: number | undefined; + maybeBroadcastWatch: number | undefined; + } | undefined; + fragmentRegistry?: { + findFragmentSpreads: number | undefined; + lookup: number | undefined; + transform: number | undefined; + } | undefined; + print: number | undefined; + parser: number | undefined; + canonicalStringify: number | undefined; + links: unknown[]; + queryManager: { + getDocumentInfo: number; + documentTransforms: { + cache: number; + }[]; + }; + }; +}) | undefined; + // @public (undocumented) export function getDataFromTree(tree: ReactTypes.ReactNode, context?: { [key: string]: any; diff --git a/.api-reports/api-report-testing.md b/.api-reports/api-report-testing.md index 87e34a9e2b6..2a69d2c4e80 100644 --- a/.api-reports/api-report-testing.md +++ b/.api-reports/api-report-testing.md @@ -40,6 +40,10 @@ abstract class ApolloCache 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; // Warning: (ae-forgotten-export) The symbol "StoreObject" needs to be exported by the entry point index.d.ts // // (undocumented) @@ -114,6 +118,10 @@ class ApolloClient implements DataProxy { // Warning: (ae-forgotten-export) The symbol "DocumentTransform" needs to be exported by the entry point index.d.ts 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; // Warning: (ae-forgotten-export) The symbol "RefetchQueriesInclude" needs to be exported by the entry point index.d.ts getObservableQueries(include?: RefetchQueriesInclude): Map>; getResolvers(): Resolvers; @@ -258,12 +266,18 @@ class ApolloLink { // // (undocumented) static from(links: (ApolloLink | RequestHandler)[]): ApolloLink; + // @internal + getMemoryInternals?: () => unknown; + // @internal + readonly left?: ApolloLink; // (undocumented) protected onError(error: any, observer?: Observer): 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 | 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 @@ -539,9 +553,16 @@ class DocumentTransform { concat(otherTransform: DocumentTransform): DocumentTransform; // (undocumented) static identity(): DocumentTransform; + // @internal + readonly left?: DocumentTransform; resetCache(): void; + // @internal + readonly right?: DocumentTransform; // (undocumented) - static split(predicate: (document: DocumentNode) => boolean, left: DocumentTransform, right?: DocumentTransform): DocumentTransform; + static split(predicate: (document: DocumentNode) => boolean, left: DocumentTransform, right?: DocumentTransform): DocumentTransform & { + left: DocumentTransform; + right: DocumentTransform; + }; // (undocumented) transformDocument(document: DocumentNode): DocumentNode; } @@ -644,6 +665,48 @@ interface FragmentMap { // @public (undocumented) type FragmentMatcher = (rootValue: any, typeCondition: string, context: any) => boolean; +// @internal +const getApolloCacheMemoryInternals: (() => { + cache: { + fragmentQueryDocuments: number | undefined; + }; +}) | undefined; + +// @internal +const getApolloClientMemoryInternals: (() => { + limits: { + [k: string]: number; + }; + sizes: { + cache?: { + fragmentQueryDocuments: number | undefined; + } | undefined; + addTypenameDocumentTransform?: { + cache: number; + }[] | undefined; + inMemoryCache?: { + executeSelectionSet: number | undefined; + executeSubSelectedArray: number | undefined; + maybeBroadcastWatch: number | undefined; + } | undefined; + fragmentRegistry?: { + findFragmentSpreads: number | undefined; + lookup: number | undefined; + transform: number | undefined; + } | undefined; + print: number | undefined; + parser: number | undefined; + canonicalStringify: number | undefined; + links: unknown[]; + queryManager: { + getDocumentInfo: number; + documentTransforms: { + cache: number; + }[]; + }; + }; +}) | undefined; + // @public (undocumented) type GraphQLErrors = ReadonlyArray; diff --git a/.api-reports/api-report-testing_core.md b/.api-reports/api-report-testing_core.md index ca6f6c60b4e..dd02053d327 100644 --- a/.api-reports/api-report-testing_core.md +++ b/.api-reports/api-report-testing_core.md @@ -39,6 +39,10 @@ abstract class ApolloCache 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; // Warning: (ae-forgotten-export) The symbol "StoreObject" needs to be exported by the entry point index.d.ts // // (undocumented) @@ -113,6 +117,10 @@ class ApolloClient implements DataProxy { // Warning: (ae-forgotten-export) The symbol "DocumentTransform" needs to be exported by the entry point index.d.ts 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; // Warning: (ae-forgotten-export) The symbol "RefetchQueriesInclude" needs to be exported by the entry point index.d.ts getObservableQueries(include?: RefetchQueriesInclude): Map>; getResolvers(): Resolvers; @@ -257,12 +265,18 @@ class ApolloLink { // // (undocumented) static from(links: (ApolloLink | RequestHandler)[]): ApolloLink; + // @internal + getMemoryInternals?: () => unknown; + // @internal + readonly left?: ApolloLink; // (undocumented) protected onError(error: any, observer?: Observer): 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 | 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 @@ -538,9 +552,16 @@ class DocumentTransform { concat(otherTransform: DocumentTransform): DocumentTransform; // (undocumented) static identity(): DocumentTransform; + // @internal + readonly left?: DocumentTransform; resetCache(): void; + // @internal + readonly right?: DocumentTransform; // (undocumented) - static split(predicate: (document: DocumentNode) => boolean, left: DocumentTransform, right?: DocumentTransform): DocumentTransform; + static split(predicate: (document: DocumentNode) => boolean, left: DocumentTransform, right?: DocumentTransform): DocumentTransform & { + left: DocumentTransform; + right: DocumentTransform; + }; // (undocumented) transformDocument(document: DocumentNode): DocumentNode; } @@ -643,6 +664,48 @@ interface FragmentMap { // @public (undocumented) type FragmentMatcher = (rootValue: any, typeCondition: string, context: any) => boolean; +// @internal +const getApolloCacheMemoryInternals: (() => { + cache: { + fragmentQueryDocuments: number | undefined; + }; +}) | undefined; + +// @internal +const getApolloClientMemoryInternals: (() => { + limits: { + [k: string]: number; + }; + sizes: { + cache?: { + fragmentQueryDocuments: number | undefined; + } | undefined; + addTypenameDocumentTransform?: { + cache: number; + }[] | undefined; + inMemoryCache?: { + executeSelectionSet: number | undefined; + executeSubSelectedArray: number | undefined; + maybeBroadcastWatch: number | undefined; + } | undefined; + fragmentRegistry?: { + findFragmentSpreads: number | undefined; + lookup: number | undefined; + transform: number | undefined; + } | undefined; + print: number | undefined; + parser: number | undefined; + canonicalStringify: number | undefined; + links: unknown[]; + queryManager: { + getDocumentInfo: number; + documentTransforms: { + cache: number; + }[]; + }; + }; +}) | undefined; + // @public (undocumented) type GraphQLErrors = ReadonlyArray; diff --git a/.api-reports/api-report-utilities.md b/.api-reports/api-report-utilities.md index 65911cc6b02..6a64515659b 100644 --- a/.api-reports/api-report-utilities.md +++ b/.api-reports/api-report-utilities.md @@ -57,6 +57,10 @@ abstract class ApolloCache 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) @@ -126,6 +130,10 @@ class ApolloClient 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; // Warning: (ae-forgotten-export) The symbol "RefetchQueriesInclude" needs to be exported by the entry point index.d.ts getObservableQueries(include?: RefetchQueriesInclude): Map>; getResolvers(): Resolvers; @@ -270,12 +278,18 @@ class ApolloLink { // // (undocumented) static from(links: (ApolloLink | RequestHandler)[]): ApolloLink; + // @internal + getMemoryInternals?: () => unknown; + // @internal + readonly left?: ApolloLink; // (undocumented) protected onError(error: any, observer?: Observer): 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 | 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 @@ -783,9 +797,16 @@ export class DocumentTransform { concat(otherTransform: DocumentTransform): DocumentTransform; // (undocumented) static identity(): DocumentTransform; + // @internal + readonly left?: DocumentTransform; resetCache(): void; + // @internal + readonly right?: DocumentTransform; // (undocumented) - static split(predicate: (document: DocumentNode) => boolean, left: DocumentTransform, right?: DocumentTransform): DocumentTransform; + static split(predicate: (document: DocumentNode) => boolean, left: DocumentTransform, right?: DocumentTransform): DocumentTransform & { + left: DocumentTransform; + right: DocumentTransform; + }; // (undocumented) transformDocument(document: DocumentNode): DocumentNode; } @@ -1068,6 +1089,48 @@ interface FulfilledPromise extends Promise { value: TValue; } +// @internal +const getApolloCacheMemoryInternals: (() => { + cache: { + fragmentQueryDocuments: number | undefined; + }; +}) | undefined; + +// @internal +const getApolloClientMemoryInternals: (() => { + limits: { + [k: string]: number; + }; + sizes: { + cache?: { + fragmentQueryDocuments: number | undefined; + } | undefined; + addTypenameDocumentTransform?: { + cache: number; + }[] | undefined; + inMemoryCache?: { + executeSelectionSet: number | undefined; + executeSubSelectedArray: number | undefined; + maybeBroadcastWatch: number | undefined; + } | undefined; + fragmentRegistry?: { + findFragmentSpreads: number | undefined; + lookup: number | undefined; + transform: number | undefined; + } | undefined; + print: number | undefined; + parser: number | undefined; + canonicalStringify: number | undefined; + links: unknown[]; + queryManager: { + getDocumentInfo: number; + documentTransforms: { + cache: number; + }[]; + }; + }; +}) | undefined; + // @public (undocumented) export function getDefaultValues(definition: OperationDefinitionNode | undefined): Record; @@ -1098,6 +1161,26 @@ export function getGraphQLErrorsFromResult(result: FetchResult): GraphQLEr // @public (undocumented) export function getInclusionDirectives(directives: ReadonlyArray): InclusionDirectives; +// @internal +const getInMemoryCacheMemoryInternals: (() => { + addTypenameDocumentTransform: { + cache: number; + }[]; + inMemoryCache: { + executeSelectionSet: number | undefined; + executeSubSelectedArray: number | undefined; + maybeBroadcastWatch: number | undefined; + }; + fragmentRegistry: { + findFragmentSpreads: number | undefined; + lookup: number | undefined; + transform: number | undefined; + }; + cache: { + fragmentQueryDocuments: number | undefined; + }; +}) | undefined; + // @public export function getMainDefinition(queryDoc: DocumentNode): OperationDefinitionNode | FragmentDefinitionNode; @@ -1219,6 +1302,10 @@ class InMemoryCache extends ApolloCache { 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; // Warning: (ae-forgotten-export) The symbol "makeVar" needs to be exported by the entry point index.d.ts diff --git a/.api-reports/api-report.md b/.api-reports/api-report.md index d3549849065..ac97e197077 100644 --- a/.api-reports/api-report.md +++ b/.api-reports/api-report.md @@ -48,6 +48,10 @@ export abstract class ApolloCache 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) @@ -106,6 +110,10 @@ export class ApolloClient 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>; getResolvers(): Resolvers; // (undocumented) @@ -244,10 +252,16 @@ export class ApolloLink { static execute(link: ApolloLink, operation: GraphQLRequest): Observable; // (undocumented) static from(links: (ApolloLink | RequestHandler)[]): ApolloLink; + // @internal + getMemoryInternals?: () => unknown; + // @internal + readonly left?: ApolloLink; // (undocumented) protected onError(error: any, observer?: Observer): false | void; // (undocumented) request(operation: Operation, forward?: NextLink): Observable | null; + // @internal + readonly right?: ApolloLink; // (undocumented) setOnError(fn: ApolloLink["onError"]): this; // (undocumented) @@ -702,9 +716,16 @@ export class DocumentTransform { concat(otherTransform: DocumentTransform): DocumentTransform; // (undocumented) static identity(): DocumentTransform; + // @internal + readonly left?: DocumentTransform; resetCache(): void; + // @internal + readonly right?: DocumentTransform; // (undocumented) - static split(predicate: (document: DocumentNode) => boolean, left: DocumentTransform, right?: DocumentTransform): DocumentTransform; + static split(predicate: (document: DocumentNode) => boolean, left: DocumentTransform, right?: DocumentTransform): DocumentTransform & { + left: DocumentTransform; + right: DocumentTransform; + }; // (undocumented) transformDocument(document: DocumentNode): DocumentNode; } @@ -1033,9 +1054,71 @@ interface FulfilledPromise extends Promise { value: TValue; } +// @internal +const getApolloCacheMemoryInternals: (() => { + cache: { + fragmentQueryDocuments: number | undefined; + }; +}) | undefined; + +// @internal +const getApolloClientMemoryInternals: (() => { + limits: { + [k: string]: number; + }; + sizes: { + cache?: { + fragmentQueryDocuments: number | undefined; + } | undefined; + addTypenameDocumentTransform?: { + cache: number; + }[] | undefined; + inMemoryCache?: { + executeSelectionSet: number | undefined; + executeSubSelectedArray: number | undefined; + maybeBroadcastWatch: number | undefined; + } | undefined; + fragmentRegistry?: { + findFragmentSpreads: number | undefined; + lookup: number | undefined; + transform: number | undefined; + } | undefined; + print: number | undefined; + parser: number | undefined; + canonicalStringify: number | undefined; + links: unknown[]; + queryManager: { + getDocumentInfo: number; + documentTransforms: { + cache: number; + }[]; + }; + }; +}) | undefined; + // @public (undocumented) export function getApolloContext(): ReactTypes.Context; +// @internal +const getInMemoryCacheMemoryInternals: (() => { + addTypenameDocumentTransform: { + cache: number; + }[]; + inMemoryCache: { + executeSelectionSet: number | undefined; + executeSubSelectedArray: number | undefined; + maybeBroadcastWatch: number | undefined; + }; + fragmentRegistry: { + findFragmentSpreads: number | undefined; + lookup: number | undefined; + transform: number | undefined; + }; + cache: { + fragmentQueryDocuments: number | undefined; + }; +}) | undefined; + export { gql } // @public (undocumented) @@ -1159,6 +1242,10 @@ export class InMemoryCache extends ApolloCache { 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) diff --git a/.changeset/wet-forks-rhyme.md b/.changeset/wet-forks-rhyme.md new file mode 100644 index 00000000000..2fc57066943 --- /dev/null +++ b/.changeset/wet-forks-rhyme.md @@ -0,0 +1,5 @@ +--- +"@apollo/client": patch +--- + +Adds an experimental `ApolloClient.getMemoryInternals` helper diff --git a/.size-limits.json b/.size-limits.json index f6a846be06c..cffdc4320a2 100644 --- a/.size-limits.json +++ b/.size-limits.json @@ -1,4 +1,4 @@ { - "dist/apollo-client.min.cjs": 38831, - "import { ApolloClient, InMemoryCache, HttpLink } from \"dist/index.js\" (production)": 32603 + "dist/apollo-client.min.cjs": 38813, + "import { ApolloClient, InMemoryCache, HttpLink } from \"dist/index.js\" (production)": 32610 } diff --git a/src/cache/core/cache.ts b/src/cache/core/cache.ts index b90871cdd82..a0fd1778bdc 100644 --- a/src/cache/core/cache.ts +++ b/src/cache/core/cache.ts @@ -10,6 +10,7 @@ import { import type { DataProxy } from "./types/DataProxy.js"; import type { Cache } from "./types/Cache.js"; import { WeakCache } from "@wry/caches"; +import { getApolloCacheMemoryInternals } from "../../utilities/caching/getMemoryInternals.js"; export type Transaction = (c: ApolloCache) => void; @@ -219,4 +220,17 @@ export abstract class ApolloCache implements DataProxy { }, }); } + + /** + * @experimental + * @internal + * This is not a stable API - it is used in development builds to expose + * information to the DevTools. + * Use at your own risk! + */ + public getMemoryInternals?: typeof getApolloCacheMemoryInternals; +} + +if (__DEV__) { + ApolloCache.prototype.getMemoryInternals = getApolloCacheMemoryInternals; } diff --git a/src/cache/inmemory/inMemoryCache.ts b/src/cache/inmemory/inMemoryCache.ts index 6e001cd9137..fe62023f165 100644 --- a/src/cache/inmemory/inMemoryCache.ts +++ b/src/cache/inmemory/inMemoryCache.ts @@ -29,6 +29,7 @@ import { makeVar, forgetCache, recallCache } from "./reactiveVars.js"; import { Policies } from "./policies.js"; import { hasOwn, normalizeConfig, shouldCanonizeResults } from "./helpers.js"; import type { OperationVariables } from "../../core/index.js"; +import { getInMemoryCacheMemoryInternals } from "../../utilities/caching/getMemoryInternals.js"; type BroadcastOptions = Pick< Cache.BatchOptions, @@ -581,4 +582,17 @@ export class InMemoryCache extends ApolloCache { c.callback((c.lastDiff = diff), lastDiff); } } + + /** + * @experimental + * @internal + * This is not a stable API - it is used in development builds to expose + * information to the DevTools. + * Use at your own risk! + */ + public getMemoryInternals?: typeof getInMemoryCacheMemoryInternals; +} + +if (__DEV__) { + InMemoryCache.prototype.getMemoryInternals = getInMemoryCacheMemoryInternals; } diff --git a/src/core/ApolloClient.ts b/src/core/ApolloClient.ts index 050245e9d8b..a3216fdda34 100644 --- a/src/core/ApolloClient.ts +++ b/src/core/ApolloClient.ts @@ -122,6 +122,7 @@ export interface ApolloClientOptions { // @apollo/client/core. Since we need to preserve that API anyway, the easiest // solution is to reexport mergeOptions where it was previously declared (here). import { mergeOptions } from "../utilities/index.js"; +import { getApolloClientMemoryInternals } from "../utilities/caching/getMemoryInternals.js"; export { mergeOptions }; /** @@ -746,4 +747,17 @@ export class ApolloClient implements DataProxy { public get defaultContext() { return this.queryManager.defaultContext; } + + /** + * @experimental + * @internal + * This is not a stable API - it is used in development builds to expose + * information to the DevTools. + * Use at your own risk! + */ + public getMemoryInternals?: typeof getApolloClientMemoryInternals; +} + +if (__DEV__) { + ApolloClient.prototype.getMemoryInternals = getApolloClientMemoryInternals; } diff --git a/src/core/QueryInfo.ts b/src/core/QueryInfo.ts index 02e1768af17..b3dd4366cf2 100644 --- a/src/core/QueryInfo.ts +++ b/src/core/QueryInfo.ts @@ -7,7 +7,7 @@ import { mergeIncrementalData } from "../utilities/index.js"; import type { WatchQueryOptions, ErrorPolicy } from "./watchQueryOptions.js"; import type { ObservableQuery } from "./ObservableQuery.js"; import { reobserveCacheFirst } from "./ObservableQuery.js"; -import type { QueryListener, MethodKeys } from "./types.js"; +import type { QueryListener } from "./types.js"; import type { FetchResult } from "../link/core/index.js"; import { isNonEmptyArray, @@ -36,10 +36,11 @@ const destructiveMethodCounts = new (canUseWeakMap ? WeakMap : Map)< function wrapDestructiveCacheMethod( cache: ApolloCache, - methodName: MethodKeys> + methodName: "evict" | "modify" | "reset" ) { const original = cache[methodName]; if (typeof original === "function") { + // @ts-expect-error this is just too generic to be typed correctly cache[methodName] = function () { destructiveMethodCounts.set( cache, diff --git a/src/link/core/ApolloLink.ts b/src/link/core/ApolloLink.ts index ca9d2cfcd72..4f7759915d6 100644 --- a/src/link/core/ApolloLink.ts +++ b/src/link/core/ApolloLink.ts @@ -45,19 +45,21 @@ export class ApolloLink { const leftLink = toLink(left); const rightLink = toLink(right || new ApolloLink(passthrough)); + let ret: ApolloLink; if (isTerminating(leftLink) && isTerminating(rightLink)) { - return new ApolloLink((operation) => { + ret = new ApolloLink((operation) => { return test(operation) ? leftLink.request(operation) || Observable.of() : rightLink.request(operation) || Observable.of(); }); } else { - return new ApolloLink((operation, forward) => { + ret = new ApolloLink((operation, forward) => { return test(operation) ? leftLink.request(operation, forward) || Observable.of() : rightLink.request(operation, forward) || Observable.of(); }); } + return Object.assign(ret, { left: leftLink, right: rightLink }); } public static execute( @@ -88,8 +90,9 @@ export class ApolloLink { } const nextLink = toLink(second); + let ret: ApolloLink; if (isTerminating(nextLink)) { - return new ApolloLink( + ret = new ApolloLink( (operation) => firstLink.request( operation, @@ -97,7 +100,7 @@ export class ApolloLink { ) || Observable.of() ); } else { - return new ApolloLink((operation, forward) => { + ret = new ApolloLink((operation, forward) => { return ( firstLink.request(operation, (op) => { return nextLink.request(op, forward) || Observable.of(); @@ -105,6 +108,7 @@ export class ApolloLink { ); }); } + return Object.assign(ret, { left: firstLink, right: nextLink }); } constructor(request?: RequestHandler) { @@ -154,4 +158,21 @@ export class ApolloLink { this.onError = fn; return this; } + + /** + * @internal + * Used to iterate through all links that are concatenations or `split` links. + */ + readonly left?: ApolloLink; + /** + * @internal + * Used to iterate through all links that are concatenations or `split` links. + */ + readonly right?: ApolloLink; + + /** + * @internal + * Can be provided by a link that has an internal cache to report it's memory details. + */ + getMemoryInternals?: () => unknown; } diff --git a/src/link/persisted-queries/index.ts b/src/link/persisted-queries/index.ts index 400af11d6f5..920633bd7f3 100644 --- a/src/link/persisted-queries/index.ts +++ b/src/link/persisted-queries/index.ts @@ -301,6 +301,19 @@ export const createPersistedQueryLink = ( }; }); }), - { resetHashCache } + { + resetHashCache, + }, + __DEV__ ? + { + getMemoryInternals() { + return { + PersistedQueryLink: { + persistedQueryHashes: hashesByQuery?.size ?? 0, + }, + }; + }, + } + : {} ); }; diff --git a/src/link/remove-typename/removeTypenameFromVariables.ts b/src/link/remove-typename/removeTypenameFromVariables.ts index b713a5b4138..31ed9c58a9c 100644 --- a/src/link/remove-typename/removeTypenameFromVariables.ts +++ b/src/link/remove-typename/removeTypenameFromVariables.ts @@ -24,19 +24,32 @@ export interface RemoveTypenameFromVariablesOptions { export function removeTypenameFromVariables( options: RemoveTypenameFromVariablesOptions = Object.create(null) ) { - return new ApolloLink((operation, forward) => { - const { except } = options; - const { query, variables } = operation; - - if (variables) { - operation.variables = - except ? - maybeStripTypenameUsingConfig(query, variables, except) - : stripTypename(variables); - } - - return forward(operation); - }); + return Object.assign( + new ApolloLink((operation, forward) => { + const { except } = options; + const { query, variables } = operation; + + if (variables) { + operation.variables = + except ? + maybeStripTypenameUsingConfig(query, variables, except) + : stripTypename(variables); + } + + return forward(operation); + }), + __DEV__ ? + { + getMemoryInternals() { + return { + removeTypenameFromVariables: { + getVariableDefinitions: getVariableDefinitions?.size ?? 0, + }, + }; + }, + } + : {} + ); } function maybeStripTypenameUsingConfig( diff --git a/src/react/parser/index.ts b/src/react/parser/index.ts index 5cca2c066f8..6bcf2989989 100644 --- a/src/react/parser/index.ts +++ b/src/react/parser/index.ts @@ -11,6 +11,7 @@ import { cacheSizes, defaultCacheSizes, } from "../../utilities/index.js"; +import { registerGlobalCache } from "../../utilities/caching/getMemoryInternals.js"; export enum DocumentType { Query, @@ -153,6 +154,10 @@ parser.resetCache = () => { cache = undefined; }; +if (__DEV__) { + registerGlobalCache("parser", () => (cache ? cache.size : 0)); +} + export function verifyDocumentType(document: DocumentNode, type: DocumentType) { const operation = parser(document); const requiredOperationName = operationName(type); diff --git a/src/utilities/caching/__tests__/getMemoryInternals.ts b/src/utilities/caching/__tests__/getMemoryInternals.ts new file mode 100644 index 00000000000..c83f34da27f --- /dev/null +++ b/src/utilities/caching/__tests__/getMemoryInternals.ts @@ -0,0 +1,204 @@ +import { createFragmentRegistry } from "../../../cache"; +import { + ApolloClient, + ApolloLink, + DocumentTransform, + InMemoryCache, + gql, +} from "../../../core"; +import { createPersistedQueryLink } from "../../../link/persisted-queries"; +import { removeTypenameFromVariables } from "../../../link/remove-typename"; +import crypto from "crypto"; +// importing react so the `parser` cache initializes +import "../../../react"; +import { cacheSizes, defaultCacheSizes } from "../sizes"; + +function sha256(data: string) { + const hash = crypto.createHash("sha256"); + hash.update(data); + return hash.digest("hex"); +} + +const defaultCacheSizesAsObject = { + parser: defaultCacheSizes["parser"], + canonicalStringify: defaultCacheSizes["canonicalStringify"], + print: defaultCacheSizes["print"], + "documentTransform.cache": defaultCacheSizes["documentTransform.cache"], + "queryManager.getDocumentInfo": + defaultCacheSizes["queryManager.getDocumentInfo"], + "PersistedQueryLink.persistedQueryHashes": + defaultCacheSizes["PersistedQueryLink.persistedQueryHashes"], + "fragmentRegistry.transform": defaultCacheSizes["fragmentRegistry.transform"], + "fragmentRegistry.lookup": defaultCacheSizes["fragmentRegistry.lookup"], + "fragmentRegistry.findFragmentSpreads": + defaultCacheSizes["fragmentRegistry.findFragmentSpreads"], + "cache.fragmentQueryDocuments": + defaultCacheSizes["cache.fragmentQueryDocuments"], + "removeTypenameFromVariables.getVariableDefinitions": + defaultCacheSizes["removeTypenameFromVariables.getVariableDefinitions"], + "inMemoryCache.maybeBroadcastWatch": + defaultCacheSizes["inMemoryCache.maybeBroadcastWatch"], + "inMemoryCache.executeSelectionSet": + defaultCacheSizes["inMemoryCache.executeSelectionSet"], + "inMemoryCache.executeSubSelectedArray": + defaultCacheSizes["inMemoryCache.executeSubSelectedArray"], +}; + +it("returns information about cache usage (empty caches)", () => { + const client = new ApolloClient({ + documentTransform: new DocumentTransform((x) => x, { + cache: true, + }).concat( + new DocumentTransform((x) => x, { + cache: true, + }) + ), + cache: new InMemoryCache({ + fragments: createFragmentRegistry(), + }), + link: createPersistedQueryLink({ + sha256, + }) + .concat(removeTypenameFromVariables()) + .concat(ApolloLink.empty()), + }); + expect(client.getMemoryInternals?.()).toEqual({ + limits: defaultCacheSizesAsObject, + sizes: { + parser: 0, + canonicalStringify: 0, + print: 0, + addTypenameDocumentTransform: [ + { + cache: 0, + }, + ], + queryManager: { + getDocumentInfo: 0, + documentTransforms: [ + { + cache: 0, + }, + { + cache: 0, + }, + ], + }, + fragmentRegistry: { + findFragmentSpreads: 0, + lookup: 0, + transform: 0, + }, + cache: { + fragmentQueryDocuments: 0, + }, + inMemoryCache: { + executeSelectionSet: 0, + executeSubSelectedArray: 0, + maybeBroadcastWatch: 0, + }, + links: [ + { + PersistedQueryLink: { + persistedQueryHashes: 0, + }, + }, + { + removeTypenameFromVariables: { + getVariableDefinitions: 0, + }, + }, + ], + }, + }); +}); + +it("returns information about cache usage (some query triggered)", () => { + const client = new ApolloClient({ + documentTransform: new DocumentTransform((x) => x, { + cache: true, + }).concat( + new DocumentTransform((x) => x, { + cache: true, + }) + ), + cache: new InMemoryCache({ + fragments: createFragmentRegistry(), + }), + link: createPersistedQueryLink({ + sha256, + }) + .concat(removeTypenameFromVariables()) + .concat(ApolloLink.empty()), + }); + + client.query({ + query: gql` + query { + hello + } + `, + }); + expect(client.getMemoryInternals?.()).toStrictEqual({ + limits: defaultCacheSizesAsObject, + sizes: { + parser: 0, + canonicalStringify: 0, + print: 1, + addTypenameDocumentTransform: [ + { + cache: 1, + }, + ], + queryManager: { + getDocumentInfo: 1, + documentTransforms: [ + { + cache: 1, + }, + { + cache: 1, + }, + ], + }, + fragmentRegistry: { + findFragmentSpreads: 1, + lookup: 0, + transform: 1, + }, + cache: { + fragmentQueryDocuments: 0, + }, + inMemoryCache: { + executeSelectionSet: 1, + executeSubSelectedArray: 0, + maybeBroadcastWatch: 0, + }, + links: [ + { + PersistedQueryLink: { + persistedQueryHashes: 1, + }, + }, + { + removeTypenameFromVariables: { + getVariableDefinitions: 0, + }, + }, + ], + }, + }); +}); + +it("reports user-declared cacheSizes", () => { + const client = new ApolloClient({ + cache: new InMemoryCache({}), + }); + + cacheSizes["inMemoryCache.executeSubSelectedArray"] = 90; + + expect(client.getMemoryInternals?.().limits).toStrictEqual({ + ...defaultCacheSizesAsObject, + "inMemoryCache.executeSubSelectedArray": 90, + }); +}); diff --git a/src/utilities/caching/getMemoryInternals.ts b/src/utilities/caching/getMemoryInternals.ts new file mode 100644 index 00000000000..ac28989c37b --- /dev/null +++ b/src/utilities/caching/getMemoryInternals.ts @@ -0,0 +1,228 @@ +import type { OptimisticWrapperFunction } from "optimism"; +import type { + InMemoryCache, + DocumentTransform, + ApolloLink, + ApolloCache, +} from "../../core/index.js"; +import type { ApolloClient } from "../../core/index.js"; +import type { CacheSizes } from "./sizes.js"; +import { cacheSizes, defaultCacheSizes } from "./sizes.js"; + +const globalCaches: { + print?: () => number; + parser?: () => number; + canonicalStringify?: () => number; +} = {}; + +export function registerGlobalCache( + name: keyof typeof globalCaches, + getSize: () => number +) { + globalCaches[name] = getSize; +} + +/** + * Transformative helper type to turn a function of the form + * ```ts + * (this: any) => R + * ``` + * into a function of the form + * ```ts + * () => R + * ``` + * preserving the return type, but removing the `this` parameter. + * + * @remarks + * + * Further down in the definitions of `_getApolloClientMemoryInternals`, + * `_getApolloCacheMemoryInternals` and `_getInMemoryCacheMemoryInternals`, + * having the `this` parameter annotation is extremely useful for type checking + * inside the function. + * + * If this is preserved in the exported types, though, it leads to a situation + * where `ApolloCache.getMemoryInternals` is a function that requires a `this` + * of the type `ApolloCache`, while the extending class `InMemoryCache` has a + * `getMemoryInternals` function that requires a `this` of the type + * `InMemoryCache`. + * This is not compatible with TypeScript's inheritence system (although it is + * perfectly correct), and so TypeScript will complain loudly. + * + * We still want to define our functions with the `this` annotation, though, + * and have the return type inferred. + * (This requirement for return type inference here makes it impossible to use + * a function overload that is more explicit on the inner overload than it is + * on the external overload.) + * + * So in the end, we use this helper to remove the `this` annotation from the + * exported function types, while keeping it in the internal implementation. + * + */ +type RemoveThis = T extends (this: any) => infer R ? () => R : never; + +/** + * For internal purposes only - please call `ApolloClient.getMemoryInternals` instead + * @internal + */ +export const getApolloClientMemoryInternals = + __DEV__ ? + (_getApolloClientMemoryInternals as RemoveThis< + typeof _getApolloClientMemoryInternals + >) + : undefined; + +/** + * For internal purposes only - please call `ApolloClient.getMemoryInternals` instead + * @internal + */ +export const getInMemoryCacheMemoryInternals = + __DEV__ ? + (_getInMemoryCacheMemoryInternals as RemoveThis< + typeof _getInMemoryCacheMemoryInternals + >) + : undefined; + +/** + * For internal purposes only - please call `ApolloClient.getMemoryInternals` instead + * @internal + */ +export const getApolloCacheMemoryInternals = + __DEV__ ? + (_getApolloCacheMemoryInternals as RemoveThis< + typeof _getApolloCacheMemoryInternals + >) + : undefined; + +function getCurrentCacheSizes() { + // `defaultCacheSizes` is a `const enum` that will be inlined during build, so we have to reconstruct it's shape here + const defaults: Record = { + parser: defaultCacheSizes["parser"], + canonicalStringify: defaultCacheSizes["canonicalStringify"], + print: defaultCacheSizes["print"], + "documentTransform.cache": defaultCacheSizes["documentTransform.cache"], + "queryManager.getDocumentInfo": + defaultCacheSizes["queryManager.getDocumentInfo"], + "PersistedQueryLink.persistedQueryHashes": + defaultCacheSizes["PersistedQueryLink.persistedQueryHashes"], + "fragmentRegistry.transform": + defaultCacheSizes["fragmentRegistry.transform"], + "fragmentRegistry.lookup": defaultCacheSizes["fragmentRegistry.lookup"], + "fragmentRegistry.findFragmentSpreads": + defaultCacheSizes["fragmentRegistry.findFragmentSpreads"], + "cache.fragmentQueryDocuments": + defaultCacheSizes["cache.fragmentQueryDocuments"], + "removeTypenameFromVariables.getVariableDefinitions": + defaultCacheSizes["removeTypenameFromVariables.getVariableDefinitions"], + "inMemoryCache.maybeBroadcastWatch": + defaultCacheSizes["inMemoryCache.maybeBroadcastWatch"], + "inMemoryCache.executeSelectionSet": + defaultCacheSizes["inMemoryCache.executeSelectionSet"], + "inMemoryCache.executeSubSelectedArray": + defaultCacheSizes["inMemoryCache.executeSubSelectedArray"], + }; + return Object.fromEntries( + Object.entries(defaults).map(([k, v]) => [ + k, + cacheSizes[k as keyof CacheSizes] || v, + ]) + ); +} + +function _getApolloClientMemoryInternals(this: ApolloClient) { + if (!__DEV__) throw new Error("only supported in development mode"); + + return { + limits: getCurrentCacheSizes(), + sizes: { + print: globalCaches.print?.(), + parser: globalCaches.parser?.(), + canonicalStringify: globalCaches.canonicalStringify?.(), + links: linkInfo(this.link), + queryManager: { + getDocumentInfo: this["queryManager"]["transformCache"].size, + documentTransforms: transformInfo( + this["queryManager"].documentTransform + ), + }, + ...(this.cache.getMemoryInternals?.() as Partial< + ReturnType + > & + Partial>), + }, + }; +} + +function _getApolloCacheMemoryInternals(this: ApolloCache) { + return { + cache: { + fragmentQueryDocuments: getWrapperInformation(this["getFragmentDoc"]), + }, + }; +} + +function _getInMemoryCacheMemoryInternals(this: InMemoryCache) { + const fragments = this.config.fragments as + | undefined + | { + findFragmentSpreads?: Function; + transform?: Function; + lookup?: Function; + }; + + return { + ..._getApolloCacheMemoryInternals.apply(this as any), + addTypenameDocumentTransform: transformInfo(this["addTypenameTransform"]), + inMemoryCache: { + executeSelectionSet: getWrapperInformation( + this["storeReader"]["executeSelectionSet"] + ), + executeSubSelectedArray: getWrapperInformation( + this["storeReader"]["executeSubSelectedArray"] + ), + maybeBroadcastWatch: getWrapperInformation(this["maybeBroadcastWatch"]), + }, + fragmentRegistry: { + findFragmentSpreads: getWrapperInformation( + fragments?.findFragmentSpreads + ), + lookup: getWrapperInformation(fragments?.lookup), + transform: getWrapperInformation(fragments?.transform), + }, + }; +} + +function isWrapper(f?: Function): f is OptimisticWrapperFunction { + return !!f && "dirtyKey" in f; +} + +function getWrapperInformation(f?: Function) { + return isWrapper(f) ? f.size : undefined; +} + +function isDefined(value: T | undefined | null): value is T { + return value != null; +} + +function transformInfo(transform?: DocumentTransform) { + return recurseTransformInfo(transform).map((cache) => ({ cache })); +} + +function recurseTransformInfo(transform?: DocumentTransform): number[] { + return transform ? + [ + getWrapperInformation(transform?.["performWork"]), + ...recurseTransformInfo(transform?.["left"]), + ...recurseTransformInfo(transform?.["right"]), + ].filter(isDefined) + : []; +} + +function linkInfo(link?: ApolloLink): unknown[] { + return link ? + [ + link?.getMemoryInternals?.(), + ...linkInfo(link?.left), + ...linkInfo(link?.right), + ].filter(isDefined) + : []; +} diff --git a/src/utilities/common/canonicalStringify.ts b/src/utilities/common/canonicalStringify.ts index 7c037b0a680..adcc9898211 100644 --- a/src/utilities/common/canonicalStringify.ts +++ b/src/utilities/common/canonicalStringify.ts @@ -3,6 +3,7 @@ import { cacheSizes, defaultCacheSizes, } from "../../utilities/caching/index.js"; +import { registerGlobalCache } from "../caching/getMemoryInternals.js"; /** * Like JSON.stringify, but with object keys always sorted in the same order. @@ -37,6 +38,10 @@ export const canonicalStringify = Object.assign( } ); +if (__DEV__) { + registerGlobalCache("canonicalStringify", () => sortingMap.size); +} + // Values are JSON-serialized arrays of object keys (in any order), and values // are sorted arrays of the same keys. let sortingMap!: AutoCleanedStrongCache; diff --git a/src/utilities/graphql/DocumentTransform.ts b/src/utilities/graphql/DocumentTransform.ts index bf016aee0da..732c1c7d1a6 100644 --- a/src/utilities/graphql/DocumentTransform.ts +++ b/src/utilities/graphql/DocumentTransform.ts @@ -52,14 +52,17 @@ export class DocumentTransform { left: DocumentTransform, right: DocumentTransform = DocumentTransform.identity() ) { - return new DocumentTransform( - (document) => { - const documentTransform = predicate(document) ? left : right; - - return documentTransform.transformDocument(document); - }, - // Reasonably assume both `left` and `right` transforms handle their own caching - { cache: false } + return Object.assign( + new DocumentTransform( + (document) => { + const documentTransform = predicate(document) ? left : right; + + return documentTransform.transformDocument(document); + }, + // Reasonably assume both `left` and `right` transforms handle their own caching + { cache: false } + ), + { left, right } ); } @@ -123,15 +126,32 @@ export class DocumentTransform { return transformedDocument; } - concat(otherTransform: DocumentTransform) { - return new DocumentTransform( - (document) => { - return otherTransform.transformDocument( - this.transformDocument(document) - ); - }, - // Reasonably assume both transforms handle their own caching - { cache: false } + concat(otherTransform: DocumentTransform): DocumentTransform { + return Object.assign( + new DocumentTransform( + (document) => { + return otherTransform.transformDocument( + this.transformDocument(document) + ); + }, + // Reasonably assume both transforms handle their own caching + { cache: false } + ), + { + left: this, + right: otherTransform, + } ); } + + /** + * @internal + * Used to iterate through all transforms that are concatenations or `split` links. + */ + readonly left?: DocumentTransform; + /** + * @internal + * Used to iterate through all transforms that are concatenations or `split` links. + */ + readonly right?: DocumentTransform; } diff --git a/src/utilities/graphql/print.ts b/src/utilities/graphql/print.ts index e32a3f048df..20e779a9a55 100644 --- a/src/utilities/graphql/print.ts +++ b/src/utilities/graphql/print.ts @@ -5,6 +5,7 @@ import { cacheSizes, defaultCacheSizes, } from "../caching/index.js"; +import { registerGlobalCache } from "../caching/getMemoryInternals.js"; let printCache!: AutoCleanedWeakCache; export const print = Object.assign( @@ -25,5 +26,8 @@ export const print = Object.assign( }, } ); - print.reset(); + +if (__DEV__) { + registerGlobalCache("print", () => (printCache ? printCache.size : 0)); +}