From 07568d1e80032df726fa0e43ab3c8b68c7c675ce Mon Sep 17 00:00:00 2001 From: Alessia Bellisario Date: Fri, 5 Jan 2024 12:55:11 -0500 Subject: [PATCH 01/25] feat: extract watchFragment into separate method on ApolloCache --- .api-reports/api-report-cache.md | 74 ++++- .api-reports/api-report-core.md | 72 +++++ .api-reports/api-report-react.md | 37 ++- .api-reports/api-report-react_components.md | 74 ++++- .api-reports/api-report-react_context.md | 74 ++++- .api-reports/api-report-react_hoc.md | 74 ++++- .api-reports/api-report-react_hooks.md | 37 ++- .api-reports/api-report-react_internal.md | 37 ++- .api-reports/api-report-react_ssr.md | 74 ++++- .api-reports/api-report-testing.md | 74 ++++- .api-reports/api-report-testing_core.md | 74 ++++- .api-reports/api-report-utilities.md | 37 ++- .api-reports/api-report.md | 35 +++ .changeset/tasty-pillows-ring.md | 5 + .size-limits.json | 4 +- src/__tests__/ApolloClient.ts | 292 +++++++++++++++++++- src/cache/core/cache.ts | 90 +++++- src/core/ApolloClient.ts | 24 ++ src/react/hooks/useFragment.ts | 31 ++- 19 files changed, 1187 insertions(+), 32 deletions(-) create mode 100644 .changeset/tasty-pillows-ring.md diff --git a/.api-reports/api-report-cache.md b/.api-reports/api-report-cache.md index 7eed64d3052..10deafdae0e 100644 --- a/.api-reports/api-report-cache.md +++ b/.api-reports/api-report-cache.md @@ -8,9 +8,10 @@ import type { DocumentNode } from 'graphql'; import type { FieldNode } from 'graphql'; import type { FragmentDefinitionNode } from 'graphql'; import type { InlineFragmentNode } from 'graphql'; +import { Observable } from 'zen-observable-ts'; import type { SelectionSetNode } from 'graphql'; import { Trie } from '@wry/trie'; -import type { TypedDocumentNode } from '@graphql-typed-document-node/core'; +import { TypedDocumentNode } from '@graphql-typed-document-node/core'; // Warning: (ae-forgotten-export) The symbol "StoreObjectValueMaybeReference" needs to be exported by the entry point index.d.ts // @@ -63,6 +64,12 @@ export abstract class ApolloCache implements DataProxy { updateQuery(options: Cache_2.UpdateQueryOptions, update: (data: TData | null) => TData | null | void): TData | null; // (undocumented) abstract watch(watch: Cache_2.WatchOptions): () => void; + // Warning: (ae-forgotten-export) The symbol "OperationVariables" needs to be exported by the entry point index.d.ts + // Warning: (ae-forgotten-export) The symbol "WatchFragmentOptions" needs to be exported by the entry point index.d.ts + // Warning: (ae-forgotten-export) The symbol "WatchFragmentResult" needs to be exported by the entry point index.d.ts + // + // (undocumented) + watchFragment(options: WatchFragmentOptions): Observable>; // (undocumented) abstract write(write: Cache_2.WriteOptions): Reference | undefined; // (undocumented) @@ -274,6 +281,40 @@ export interface DataProxy { writeQuery(options: DataProxy.WriteQueryOptions): Reference | undefined; } +// Warning: (ae-forgotten-export) The symbol "DeepPartialPrimitive" needs to be exported by the entry point index.d.ts +// Warning: (ae-forgotten-export) The symbol "DeepPartialMap" needs to be exported by the entry point index.d.ts +// Warning: (ae-forgotten-export) The symbol "DeepPartialReadonlyMap" needs to be exported by the entry point index.d.ts +// Warning: (ae-forgotten-export) The symbol "DeepPartialSet" needs to be exported by the entry point index.d.ts +// Warning: (ae-forgotten-export) The symbol "DeepPartialReadonlySet" needs to be exported by the entry point index.d.ts +// Warning: (ae-forgotten-export) The symbol "DeepPartialObject" needs to be exported by the entry point index.d.ts +// +// @public (undocumented) +type DeepPartial = T extends DeepPartialPrimitive ? T : T extends Map ? DeepPartialMap : T extends ReadonlyMap ? DeepPartialReadonlyMap : T extends Set ? DeepPartialSet : T extends ReadonlySet ? DeepPartialReadonlySet : T extends (...args: any[]) => unknown ? T | undefined : T extends object ? T extends (ReadonlyArray) ? TItem[] extends (T) ? readonly TItem[] extends T ? ReadonlyArray> : Array> : DeepPartialObject : DeepPartialObject : unknown; + +// Warning: (ae-forgotten-export) The symbol "DeepPartial" needs to be exported by the entry point index.d.ts +// +// @public (undocumented) +type DeepPartialMap = {} & Map, DeepPartial>; + +// @public (undocumented) +type DeepPartialObject = { + [K in keyof T]?: DeepPartial; +}; + +// Warning: (ae-forgotten-export) The symbol "Primitive" needs to be exported by the entry point index.d.ts +// +// @public (undocumented) +type DeepPartialPrimitive = Primitive | Date | RegExp; + +// @public (undocumented) +type DeepPartialReadonlyMap = {} & ReadonlyMap, DeepPartial>; + +// @public (undocumented) +type DeepPartialReadonlySet = {} & ReadonlySet>; + +// @public (undocumented) +type DeepPartialSet = {} & Set>; + // Warning: (ae-forgotten-export) The symbol "KeyFieldsContext" needs to be exported by the entry point index.d.ts // // @public (undocumented) @@ -533,8 +574,6 @@ export class InMemoryCache extends ApolloCache { protected broadcastWatches(options?: BroadcastOptions): void; // (undocumented) protected config: InMemoryCacheConfig; - // Warning: (ae-forgotten-export) The symbol "OperationVariables" needs to be exported by the entry point index.d.ts - // // (undocumented) diff(options: Cache_2.DiffOptions): Cache_2.DiffResult; // (undocumented) @@ -824,6 +863,9 @@ export type PossibleTypesMap = { [supertype: string]: string[]; }; +// @public (undocumented) +type Primitive = null | undefined | string | number | boolean | symbol | bigint; + // @public (undocumented) type ReactiveListener = (value: T) => any; @@ -936,6 +978,32 @@ export type TypePolicy = { }; }; +// @public (undocumented) +interface WatchFragmentOptions { + // @deprecated (undocumented) + canonizeResults?: boolean; + // (undocumented) + fragment: DocumentNode | TypedDocumentNode; + // (undocumented) + fragmentName?: string; + // (undocumented) + from: StoreObject | Reference | string; + // (undocumented) + optimistic?: boolean; + variables?: TVars; +} + +// @public (undocumented) +type WatchFragmentResult = { + data: TData; + complete: true; + missing?: never; +} | { + data: DeepPartial; + complete: false; + missing: MissingTree; +}; + // @public (undocumented) interface WriteContext extends ReadMergeModifyContext { // (undocumented) diff --git a/.api-reports/api-report-core.md b/.api-reports/api-report-core.md index 1ebf61607a3..98d5c19e43b 100644 --- a/.api-reports/api-report-core.md +++ b/.api-reports/api-report-core.md @@ -79,6 +79,11 @@ export abstract class ApolloCache implements DataProxy { updateQuery(options: Cache_2.UpdateQueryOptions, update: (data: TData | null) => TData | null | void): TData | null; // (undocumented) abstract watch(watch: Cache_2.WatchOptions): () => void; + // Warning: (ae-forgotten-export) The symbol "WatchFragmentOptions" needs to be exported by the entry point index.d.ts + // Warning: (ae-forgotten-export) The symbol "WatchFragmentResult" needs to be exported by the entry point index.d.ts + // + // (undocumented) + watchFragment(options: WatchFragmentOptions): Observable>; // (undocumented) abstract write(write: Cache_2.WriteOptions): Reference | undefined; // (undocumented) @@ -136,6 +141,10 @@ export class ApolloClient implements DataProxy { readonly typeDefs: ApolloClientOptions["typeDefs"]; // (undocumented) version: string; + // Warning: (ae-unresolved-link) The @link reference could not be resolved: This type of declaration is not supported yet by the resolver + // Warning: (ae-unresolved-link) The @link reference could not be resolved: This type of declaration is not supported yet by the resolver + // Warning: (ae-unresolved-link) The @link reference could not be resolved: The package "@apollo/client" does not have an export "WatchFragmentOptions" + watchFragment(options: WatchFragmentOptions): Observable>; watchQuery(options: WatchQueryOptions): ObservableQuery; writeFragment(options: DataProxy.WriteFragmentOptions): Reference | undefined; writeQuery(options: DataProxy.WriteQueryOptions): Reference | undefined; @@ -523,6 +532,40 @@ export interface DataProxy { writeQuery(options: DataProxy.WriteQueryOptions): Reference | undefined; } +// Warning: (ae-forgotten-export) The symbol "DeepPartialPrimitive" needs to be exported by the entry point index.d.ts +// Warning: (ae-forgotten-export) The symbol "DeepPartialMap" needs to be exported by the entry point index.d.ts +// Warning: (ae-forgotten-export) The symbol "DeepPartialReadonlyMap" needs to be exported by the entry point index.d.ts +// Warning: (ae-forgotten-export) The symbol "DeepPartialSet" needs to be exported by the entry point index.d.ts +// Warning: (ae-forgotten-export) The symbol "DeepPartialReadonlySet" needs to be exported by the entry point index.d.ts +// Warning: (ae-forgotten-export) The symbol "DeepPartialObject" needs to be exported by the entry point index.d.ts +// +// @public (undocumented) +type DeepPartial = T extends DeepPartialPrimitive ? T : T extends Map ? DeepPartialMap : T extends ReadonlyMap ? DeepPartialReadonlyMap : T extends Set ? DeepPartialSet : T extends ReadonlySet ? DeepPartialReadonlySet : T extends (...args: any[]) => unknown ? T | undefined : T extends object ? T extends (ReadonlyArray) ? TItem[] extends (T) ? readonly TItem[] extends T ? ReadonlyArray> : Array> : DeepPartialObject : DeepPartialObject : unknown; + +// Warning: (ae-forgotten-export) The symbol "DeepPartial" needs to be exported by the entry point index.d.ts +// +// @public (undocumented) +type DeepPartialMap = {} & Map, DeepPartial>; + +// @public (undocumented) +type DeepPartialObject = { + [K in keyof T]?: DeepPartial; +}; + +// Warning: (ae-forgotten-export) The symbol "Primitive" needs to be exported by the entry point index.d.ts +// +// @public (undocumented) +type DeepPartialPrimitive = Primitive | Date | RegExp; + +// @public (undocumented) +type DeepPartialReadonlyMap = {} & ReadonlyMap, DeepPartial>; + +// @public (undocumented) +type DeepPartialReadonlySet = {} & ReadonlySet>; + +// @public (undocumented) +type DeepPartialSet = {} & Set>; + // @public (undocumented) export interface DefaultContext extends Record { } @@ -1636,6 +1679,9 @@ export type PossibleTypesMap = { [supertype: string]: string[]; }; +// @public (undocumented) +type Primitive = null | undefined | string | number | boolean | symbol | bigint; + // @public (undocumented) const print_2: ((ast: ASTNode) => string) & { reset(): void; @@ -2174,6 +2220,32 @@ export interface UriFunction { (operation: Operation): string; } +// @public (undocumented) +interface WatchFragmentOptions { + // @deprecated (undocumented) + canonizeResults?: boolean; + // (undocumented) + fragment: DocumentNode | TypedDocumentNode; + // (undocumented) + fragmentName?: string; + // (undocumented) + from: StoreObject | Reference | string; + // (undocumented) + optimistic?: boolean; + variables?: TVars; +} + +// @public (undocumented) +type WatchFragmentResult = { + data: TData; + complete: true; + missing?: never; +} | { + data: DeepPartial; + complete: false; + missing: MissingTree; +}; + // @public (undocumented) export type WatchQueryFetchPolicy = FetchPolicy | "cache-and-network"; diff --git a/.api-reports/api-report-react.md b/.api-reports/api-report-react.md index 0cdf3ce93bc..cde49cab950 100644 --- a/.api-reports/api-report-react.md +++ b/.api-reports/api-report-react.md @@ -80,6 +80,12 @@ abstract class ApolloCache implements DataProxy { updateQuery(options: Cache_2.UpdateQueryOptions, update: (data: TData | null) => TData | null | void): TData | null; // (undocumented) abstract watch(watch: Cache_2.WatchOptions): () => void; + // Warning: (ae-forgotten-export) The symbol "OperationVariables" needs to be exported by the entry point index.d.ts + // Warning: (ae-forgotten-export) The symbol "WatchFragmentOptions" needs to be exported by the entry point index.d.ts + // Warning: (ae-forgotten-export) The symbol "WatchFragmentResult" needs to be exported by the entry point index.d.ts + // + // (undocumented) + watchFragment(options: WatchFragmentOptions): Observable>; // Warning: (ae-forgotten-export) The symbol "Reference" needs to be exported by the entry point index.d.ts // // (undocumented) @@ -161,7 +167,10 @@ class ApolloClient implements DataProxy { readonly typeDefs: ApolloClientOptions["typeDefs"]; // (undocumented) version: string; - // Warning: (ae-forgotten-export) The symbol "OperationVariables" needs to be exported by the entry point index.d.ts + // Warning: (ae-unresolved-link) The @link reference could not be resolved: The package "@apollo/client" does not have an export "Observable" + // Warning: (ae-unresolved-link) The @link reference could not be resolved: The package "@apollo/client" does not have an export "Observable" + // Warning: (ae-unresolved-link) The @link reference could not be resolved: The package "@apollo/client" does not have an export "WatchFragmentOptions" + watchFragment(options: WatchFragmentOptions): Observable>; // Warning: (ae-forgotten-export) The symbol "WatchQueryOptions" needs to be exported by the entry point index.d.ts // Warning: (ae-forgotten-export) The symbol "ObservableQuery" needs to be exported by the entry point index.d.ts // Warning: (ae-unresolved-link) The @link reference could not be resolved: The package "@apollo/client" does not have an export "ObservableQuery" @@ -2372,6 +2381,32 @@ TVariables variables: TVariables; }; +// @public (undocumented) +interface WatchFragmentOptions { + // @deprecated (undocumented) + canonizeResults?: boolean; + // (undocumented) + fragment: DocumentNode | TypedDocumentNode; + // (undocumented) + fragmentName?: string; + // (undocumented) + from: StoreObject | Reference | string; + // (undocumented) + optimistic?: boolean; + variables?: TVars; +} + +// @public (undocumented) +type WatchFragmentResult = { + data: TData; + complete: true; + missing?: never; +} | { + data: DeepPartial; + complete: false; + missing: MissingTree; +}; + // @public (undocumented) type WatchQueryFetchPolicy = FetchPolicy | "cache-and-network"; diff --git a/.api-reports/api-report-react_components.md b/.api-reports/api-report-react_components.md index a4e212edb9f..04605103ccc 100644 --- a/.api-reports/api-report-react_components.md +++ b/.api-reports/api-report-react_components.md @@ -80,6 +80,12 @@ abstract class ApolloCache implements DataProxy { updateQuery(options: Cache_2.UpdateQueryOptions, update: (data: TData | null) => TData | null | void): TData | null; // (undocumented) abstract watch(watch: Cache_2.WatchOptions): () => void; + // Warning: (ae-forgotten-export) The symbol "OperationVariables" needs to be exported by the entry point index.d.ts + // Warning: (ae-forgotten-export) The symbol "WatchFragmentOptions" needs to be exported by the entry point index.d.ts + // Warning: (ae-forgotten-export) The symbol "WatchFragmentResult" needs to be exported by the entry point index.d.ts + // + // (undocumented) + watchFragment(options: WatchFragmentOptions): Observable>; // Warning: (ae-forgotten-export) The symbol "Reference" needs to be exported by the entry point index.d.ts // // (undocumented) @@ -162,7 +168,10 @@ class ApolloClient implements DataProxy { readonly typeDefs: ApolloClientOptions["typeDefs"]; // (undocumented) version: string; - // Warning: (ae-forgotten-export) The symbol "OperationVariables" needs to be exported by the entry point index.d.ts + // Warning: (ae-unresolved-link) The @link reference could not be resolved: The package "@apollo/client" does not have an export "Observable" + // Warning: (ae-unresolved-link) The @link reference could not be resolved: The package "@apollo/client" does not have an export "Observable" + // Warning: (ae-unresolved-link) The @link reference could not be resolved: The package "@apollo/client" does not have an export "WatchFragmentOptions" + watchFragment(options: WatchFragmentOptions): Observable>; // Warning: (ae-forgotten-export) The symbol "WatchQueryOptions" needs to be exported by the entry point index.d.ts // Warning: (ae-forgotten-export) The symbol "ObservableQuery" needs to be exported by the entry point index.d.ts // Warning: (ae-unresolved-link) The @link reference could not be resolved: The package "@apollo/client" does not have an export "ObservableQuery" @@ -565,6 +574,40 @@ interface DataProxy { writeQuery(options: DataProxy.WriteQueryOptions): Reference | undefined; } +// Warning: (ae-forgotten-export) The symbol "DeepPartialPrimitive" needs to be exported by the entry point index.d.ts +// Warning: (ae-forgotten-export) The symbol "DeepPartialMap" needs to be exported by the entry point index.d.ts +// Warning: (ae-forgotten-export) The symbol "DeepPartialReadonlyMap" needs to be exported by the entry point index.d.ts +// Warning: (ae-forgotten-export) The symbol "DeepPartialSet" needs to be exported by the entry point index.d.ts +// Warning: (ae-forgotten-export) The symbol "DeepPartialReadonlySet" needs to be exported by the entry point index.d.ts +// Warning: (ae-forgotten-export) The symbol "DeepPartialObject" needs to be exported by the entry point index.d.ts +// +// @public (undocumented) +type DeepPartial = T extends DeepPartialPrimitive ? T : T extends Map ? DeepPartialMap : T extends ReadonlyMap ? DeepPartialReadonlyMap : T extends Set ? DeepPartialSet : T extends ReadonlySet ? DeepPartialReadonlySet : T extends (...args: any[]) => unknown ? T | undefined : T extends object ? T extends (ReadonlyArray) ? TItem[] extends (T) ? readonly TItem[] extends T ? ReadonlyArray> : Array> : DeepPartialObject : DeepPartialObject : unknown; + +// Warning: (ae-forgotten-export) The symbol "DeepPartial" needs to be exported by the entry point index.d.ts +// +// @public (undocumented) +type DeepPartialMap = {} & Map, DeepPartial>; + +// @public (undocumented) +type DeepPartialObject = { + [K in keyof T]?: DeepPartial; +}; + +// Warning: (ae-forgotten-export) The symbol "Primitive" needs to be exported by the entry point index.d.ts +// +// @public (undocumented) +type DeepPartialPrimitive = Primitive | Date | RegExp; + +// @public (undocumented) +type DeepPartialReadonlyMap = {} & ReadonlyMap, DeepPartial>; + +// @public (undocumented) +type DeepPartialReadonlySet = {} & ReadonlySet>; + +// @public (undocumented) +type DeepPartialSet = {} & Set>; + // @public (undocumented) interface DefaultContext extends Record { } @@ -1203,6 +1246,9 @@ type OperationVariables = Record; // @public (undocumented) type Path = ReadonlyArray; +// @public (undocumented) +type Primitive = null | undefined | string | number | boolean | symbol | bigint; + // @public @deprecated (undocumented) export function Query(props: QueryComponentOptions): ReactTypes.JSX.Element | null; @@ -1712,6 +1758,32 @@ interface UriFunction { (operation: Operation): string; } +// @public (undocumented) +interface WatchFragmentOptions { + // @deprecated (undocumented) + canonizeResults?: boolean; + // (undocumented) + fragment: DocumentNode | TypedDocumentNode; + // (undocumented) + fragmentName?: string; + // (undocumented) + from: StoreObject | Reference | string; + // (undocumented) + optimistic?: boolean; + variables?: TVars; +} + +// @public (undocumented) +type WatchFragmentResult = { + data: TData; + complete: true; + missing?: never; +} | { + data: DeepPartial; + complete: false; + missing: MissingTree; +}; + // @public (undocumented) type WatchQueryFetchPolicy = FetchPolicy | "cache-and-network"; diff --git a/.api-reports/api-report-react_context.md b/.api-reports/api-report-react_context.md index 3ec73691a66..9a0ba096caf 100644 --- a/.api-reports/api-report-react_context.md +++ b/.api-reports/api-report-react_context.md @@ -79,6 +79,12 @@ abstract class ApolloCache implements DataProxy { updateQuery(options: Cache_2.UpdateQueryOptions, update: (data: TData | null) => TData | null | void): TData | null; // (undocumented) abstract watch(watch: Cache_2.WatchOptions): () => void; + // Warning: (ae-forgotten-export) The symbol "OperationVariables" needs to be exported by the entry point index.d.ts + // Warning: (ae-forgotten-export) The symbol "WatchFragmentOptions" needs to be exported by the entry point index.d.ts + // Warning: (ae-forgotten-export) The symbol "WatchFragmentResult" needs to be exported by the entry point index.d.ts + // + // (undocumented) + watchFragment(options: WatchFragmentOptions): Observable>; // Warning: (ae-forgotten-export) The symbol "Reference" needs to be exported by the entry point index.d.ts // // (undocumented) @@ -161,7 +167,10 @@ class ApolloClient implements DataProxy { readonly typeDefs: ApolloClientOptions["typeDefs"]; // (undocumented) version: string; - // Warning: (ae-forgotten-export) The symbol "OperationVariables" needs to be exported by the entry point index.d.ts + // Warning: (ae-unresolved-link) The @link reference could not be resolved: The package "@apollo/client" does not have an export "Observable" + // Warning: (ae-unresolved-link) The @link reference could not be resolved: The package "@apollo/client" does not have an export "Observable" + // Warning: (ae-unresolved-link) The @link reference could not be resolved: The package "@apollo/client" does not have an export "WatchFragmentOptions" + watchFragment(options: WatchFragmentOptions): Observable>; // Warning: (ae-forgotten-export) The symbol "WatchQueryOptions" needs to be exported by the entry point index.d.ts // Warning: (ae-forgotten-export) The symbol "ObservableQuery" needs to be exported by the entry point index.d.ts // Warning: (ae-unresolved-link) The @link reference could not be resolved: The package "@apollo/client" does not have an export "ObservableQuery" @@ -563,6 +572,40 @@ interface DataProxy { writeQuery(options: DataProxy.WriteQueryOptions): Reference | undefined; } +// Warning: (ae-forgotten-export) The symbol "DeepPartialPrimitive" needs to be exported by the entry point index.d.ts +// Warning: (ae-forgotten-export) The symbol "DeepPartialMap" needs to be exported by the entry point index.d.ts +// Warning: (ae-forgotten-export) The symbol "DeepPartialReadonlyMap" needs to be exported by the entry point index.d.ts +// Warning: (ae-forgotten-export) The symbol "DeepPartialSet" needs to be exported by the entry point index.d.ts +// Warning: (ae-forgotten-export) The symbol "DeepPartialReadonlySet" needs to be exported by the entry point index.d.ts +// Warning: (ae-forgotten-export) The symbol "DeepPartialObject" needs to be exported by the entry point index.d.ts +// +// @public (undocumented) +type DeepPartial = T extends DeepPartialPrimitive ? T : T extends Map ? DeepPartialMap : T extends ReadonlyMap ? DeepPartialReadonlyMap : T extends Set ? DeepPartialSet : T extends ReadonlySet ? DeepPartialReadonlySet : T extends (...args: any[]) => unknown ? T | undefined : T extends object ? T extends (ReadonlyArray) ? TItem[] extends (T) ? readonly TItem[] extends T ? ReadonlyArray> : Array> : DeepPartialObject : DeepPartialObject : unknown; + +// Warning: (ae-forgotten-export) The symbol "DeepPartial" needs to be exported by the entry point index.d.ts +// +// @public (undocumented) +type DeepPartialMap = {} & Map, DeepPartial>; + +// @public (undocumented) +type DeepPartialObject = { + [K in keyof T]?: DeepPartial; +}; + +// Warning: (ae-forgotten-export) The symbol "Primitive" needs to be exported by the entry point index.d.ts +// +// @public (undocumented) +type DeepPartialPrimitive = Primitive | Date | RegExp; + +// @public (undocumented) +type DeepPartialReadonlyMap = {} & ReadonlyMap, DeepPartial>; + +// @public (undocumented) +type DeepPartialReadonlySet = {} & ReadonlySet>; + +// @public (undocumented) +type DeepPartialSet = {} & Set>; + // @public (undocumented) interface DefaultContext extends Record { } @@ -1142,6 +1185,9 @@ type OperationVariables = Record; // @public (undocumented) type Path = ReadonlyArray; +// @public (undocumented) +type Primitive = null | undefined | string | number | boolean | symbol | bigint; + // @public (undocumented) interface QueryData { // (undocumented) @@ -1635,6 +1681,32 @@ interface UriFunction { (operation: Operation): string; } +// @public (undocumented) +interface WatchFragmentOptions { + // @deprecated (undocumented) + canonizeResults?: boolean; + // (undocumented) + fragment: DocumentNode | TypedDocumentNode; + // (undocumented) + fragmentName?: string; + // (undocumented) + from: StoreObject | Reference | string; + // (undocumented) + optimistic?: boolean; + variables?: TVars; +} + +// @public (undocumented) +type WatchFragmentResult = { + data: TData; + complete: true; + missing?: never; +} | { + data: DeepPartial; + complete: false; + missing: MissingTree; +}; + // @public (undocumented) type WatchQueryFetchPolicy = FetchPolicy | "cache-and-network"; diff --git a/.api-reports/api-report-react_hoc.md b/.api-reports/api-report-react_hoc.md index 107a19b3bbd..95b584052f0 100644 --- a/.api-reports/api-report-react_hoc.md +++ b/.api-reports/api-report-react_hoc.md @@ -79,6 +79,12 @@ abstract class ApolloCache implements DataProxy { updateQuery(options: Cache_2.UpdateQueryOptions, update: (data: TData | null) => TData | null | void): TData | null; // (undocumented) abstract watch(watch: Cache_2.WatchOptions): () => void; + // Warning: (ae-forgotten-export) The symbol "OperationVariables" needs to be exported by the entry point index.d.ts + // Warning: (ae-forgotten-export) The symbol "WatchFragmentOptions" needs to be exported by the entry point index.d.ts + // Warning: (ae-forgotten-export) The symbol "WatchFragmentResult" needs to be exported by the entry point index.d.ts + // + // (undocumented) + watchFragment(options: WatchFragmentOptions): Observable>; // Warning: (ae-forgotten-export) The symbol "Reference" needs to be exported by the entry point index.d.ts // // (undocumented) @@ -161,7 +167,10 @@ class ApolloClient implements DataProxy { readonly typeDefs: ApolloClientOptions["typeDefs"]; // (undocumented) version: string; - // Warning: (ae-forgotten-export) The symbol "OperationVariables" needs to be exported by the entry point index.d.ts + // Warning: (ae-unresolved-link) The @link reference could not be resolved: The package "@apollo/client" does not have an export "Observable" + // Warning: (ae-unresolved-link) The @link reference could not be resolved: The package "@apollo/client" does not have an export "Observable" + // Warning: (ae-unresolved-link) The @link reference could not be resolved: The package "@apollo/client" does not have an export "WatchFragmentOptions" + watchFragment(options: WatchFragmentOptions): Observable>; // Warning: (ae-forgotten-export) The symbol "WatchQueryOptions" needs to be exported by the entry point index.d.ts // Warning: (ae-forgotten-export) The symbol "ObservableQuery" needs to be exported by the entry point index.d.ts // Warning: (ae-unresolved-link) The @link reference could not be resolved: The package "@apollo/client" does not have an export "ObservableQuery" @@ -561,6 +570,40 @@ interface DataProxy { // @public (undocumented) export type DataValue = QueryControls & Partial; +// Warning: (ae-forgotten-export) The symbol "DeepPartialPrimitive" needs to be exported by the entry point index.d.ts +// Warning: (ae-forgotten-export) The symbol "DeepPartialMap" needs to be exported by the entry point index.d.ts +// Warning: (ae-forgotten-export) The symbol "DeepPartialReadonlyMap" needs to be exported by the entry point index.d.ts +// Warning: (ae-forgotten-export) The symbol "DeepPartialSet" needs to be exported by the entry point index.d.ts +// Warning: (ae-forgotten-export) The symbol "DeepPartialReadonlySet" needs to be exported by the entry point index.d.ts +// Warning: (ae-forgotten-export) The symbol "DeepPartialObject" needs to be exported by the entry point index.d.ts +// +// @public (undocumented) +type DeepPartial = T extends DeepPartialPrimitive ? T : T extends Map ? DeepPartialMap : T extends ReadonlyMap ? DeepPartialReadonlyMap : T extends Set ? DeepPartialSet : T extends ReadonlySet ? DeepPartialReadonlySet : T extends (...args: any[]) => unknown ? T | undefined : T extends object ? T extends (ReadonlyArray) ? TItem[] extends (T) ? readonly TItem[] extends T ? ReadonlyArray> : Array> : DeepPartialObject : DeepPartialObject : unknown; + +// Warning: (ae-forgotten-export) The symbol "DeepPartial" needs to be exported by the entry point index.d.ts +// +// @public (undocumented) +type DeepPartialMap = {} & Map, DeepPartial>; + +// @public (undocumented) +type DeepPartialObject = { + [K in keyof T]?: DeepPartial; +}; + +// Warning: (ae-forgotten-export) The symbol "Primitive" needs to be exported by the entry point index.d.ts +// +// @public (undocumented) +type DeepPartialPrimitive = Primitive | Date | RegExp; + +// @public (undocumented) +type DeepPartialReadonlyMap = {} & ReadonlyMap, DeepPartial>; + +// @public (undocumented) +type DeepPartialReadonlySet = {} & ReadonlySet>; + +// @public (undocumented) +type DeepPartialSet = {} & Set>; + // @public (undocumented) interface DefaultContext extends Record { } @@ -1189,6 +1232,9 @@ export interface OptionProps; +// @public (undocumented) +type Primitive = null | undefined | string | number | boolean | symbol | bigint; + // @public (undocumented) export interface QueryControls { // (undocumented) @@ -1647,6 +1693,32 @@ interface UriFunction { (operation: Operation): string; } +// @public (undocumented) +interface WatchFragmentOptions { + // @deprecated (undocumented) + canonizeResults?: boolean; + // (undocumented) + fragment: DocumentNode | TypedDocumentNode; + // (undocumented) + fragmentName?: string; + // (undocumented) + from: StoreObject | Reference | string; + // (undocumented) + optimistic?: boolean; + variables?: TVars; +} + +// @public (undocumented) +type WatchFragmentResult = { + data: TData; + complete: true; + missing?: never; +} | { + data: DeepPartial; + complete: false; + missing: MissingTree; +}; + // @public (undocumented) type WatchQueryFetchPolicy = FetchPolicy | "cache-and-network"; diff --git a/.api-reports/api-report-react_hooks.md b/.api-reports/api-report-react_hooks.md index 4abfa6b4bd0..05aa2224c13 100644 --- a/.api-reports/api-report-react_hooks.md +++ b/.api-reports/api-report-react_hooks.md @@ -78,6 +78,12 @@ abstract class ApolloCache implements DataProxy { updateQuery(options: Cache_2.UpdateQueryOptions, update: (data: TData | null) => TData | null | void): TData | null; // (undocumented) abstract watch(watch: Cache_2.WatchOptions): () => void; + // Warning: (ae-forgotten-export) The symbol "OperationVariables" needs to be exported by the entry point index.d.ts + // Warning: (ae-forgotten-export) The symbol "WatchFragmentOptions" needs to be exported by the entry point index.d.ts + // Warning: (ae-forgotten-export) The symbol "WatchFragmentResult" needs to be exported by the entry point index.d.ts + // + // (undocumented) + watchFragment(options: WatchFragmentOptions): Observable>; // Warning: (ae-forgotten-export) The symbol "Reference" needs to be exported by the entry point index.d.ts // // (undocumented) @@ -160,7 +166,10 @@ class ApolloClient implements DataProxy { readonly typeDefs: ApolloClientOptions["typeDefs"]; // (undocumented) version: string; - // Warning: (ae-forgotten-export) The symbol "OperationVariables" needs to be exported by the entry point index.d.ts + // Warning: (ae-unresolved-link) The @link reference could not be resolved: The package "@apollo/client" does not have an export "Observable" + // Warning: (ae-unresolved-link) The @link reference could not be resolved: The package "@apollo/client" does not have an export "Observable" + // Warning: (ae-unresolved-link) The @link reference could not be resolved: The package "@apollo/client" does not have an export "WatchFragmentOptions" + watchFragment(options: WatchFragmentOptions): Observable>; // Warning: (ae-forgotten-export) The symbol "WatchQueryOptions" needs to be exported by the entry point index.d.ts // Warning: (ae-forgotten-export) The symbol "ObservableQuery" needs to be exported by the entry point index.d.ts // Warning: (ae-unresolved-link) The @link reference could not be resolved: The package "@apollo/client" does not have an export "ObservableQuery" @@ -2208,6 +2217,32 @@ export interface UseSuspenseQueryResult; } +// @public (undocumented) +interface WatchFragmentOptions { + // @deprecated (undocumented) + canonizeResults?: boolean; + // (undocumented) + fragment: DocumentNode | TypedDocumentNode; + // (undocumented) + fragmentName?: string; + // (undocumented) + from: StoreObject | Reference | string; + // (undocumented) + optimistic?: boolean; + variables?: TVars; +} + +// @public (undocumented) +type WatchFragmentResult = { + data: TData; + complete: true; + missing?: never; +} | { + data: DeepPartial; + complete: false; + missing: MissingTree; +}; + // @public (undocumented) type WatchQueryFetchPolicy = FetchPolicy | "cache-and-network"; diff --git a/.api-reports/api-report-react_internal.md b/.api-reports/api-report-react_internal.md index 9b76bda9bbc..ba8370d5371 100644 --- a/.api-reports/api-report-react_internal.md +++ b/.api-reports/api-report-react_internal.md @@ -78,6 +78,12 @@ abstract class ApolloCache implements DataProxy { updateQuery(options: Cache_2.UpdateQueryOptions, update: (data: TData | null) => TData | null | void): TData | null; // (undocumented) abstract watch(watch: Cache_2.WatchOptions): () => void; + // Warning: (ae-forgotten-export) The symbol "OperationVariables" needs to be exported by the entry point index.d.ts + // Warning: (ae-forgotten-export) The symbol "WatchFragmentOptions" needs to be exported by the entry point index.d.ts + // Warning: (ae-forgotten-export) The symbol "WatchFragmentResult" needs to be exported by the entry point index.d.ts + // + // (undocumented) + watchFragment(options: WatchFragmentOptions): Observable>; // Warning: (ae-forgotten-export) The symbol "Reference" needs to be exported by the entry point index.d.ts // // (undocumented) @@ -160,7 +166,10 @@ class ApolloClient implements DataProxy { readonly typeDefs: ApolloClientOptions["typeDefs"]; // (undocumented) version: string; - // Warning: (ae-forgotten-export) The symbol "OperationVariables" needs to be exported by the entry point index.d.ts + // Warning: (ae-unresolved-link) The @link reference could not be resolved: The package "@apollo/client" does not have an export "Observable" + // Warning: (ae-unresolved-link) The @link reference could not be resolved: The package "@apollo/client" does not have an export "Observable" + // Warning: (ae-unresolved-link) The @link reference could not be resolved: The package "@apollo/client" does not have an export "WatchFragmentOptions" + watchFragment(options: WatchFragmentOptions): Observable>; // Warning: (ae-forgotten-export) The symbol "WatchQueryOptions" needs to be exported by the entry point index.d.ts // Warning: (ae-forgotten-export) The symbol "ObservableQuery" needs to be exported by the entry point index.d.ts // Warning: (ae-unresolved-link) The @link reference could not be resolved: The package "@apollo/client" does not have an export "ObservableQuery" @@ -2023,6 +2032,32 @@ interface UseSuspenseQueryResult; } +// @public (undocumented) +interface WatchFragmentOptions { + // @deprecated (undocumented) + canonizeResults?: boolean; + // (undocumented) + fragment: DocumentNode | TypedDocumentNode; + // (undocumented) + fragmentName?: string; + // (undocumented) + from: StoreObject | Reference | string; + // (undocumented) + optimistic?: boolean; + variables?: TVars; +} + +// @public (undocumented) +type WatchFragmentResult = { + data: TData; + complete: true; + missing?: never; +} | { + data: DeepPartial; + complete: false; + missing: MissingTree; +}; + // @public (undocumented) type WatchQueryFetchPolicy = FetchPolicy | "cache-and-network"; diff --git a/.api-reports/api-report-react_ssr.md b/.api-reports/api-report-react_ssr.md index 3747959ed85..26da1d70ac7 100644 --- a/.api-reports/api-report-react_ssr.md +++ b/.api-reports/api-report-react_ssr.md @@ -79,6 +79,12 @@ abstract class ApolloCache implements DataProxy { updateQuery(options: Cache_2.UpdateQueryOptions, update: (data: TData | null) => TData | null | void): TData | null; // (undocumented) abstract watch(watch: Cache_2.WatchOptions): () => void; + // Warning: (ae-forgotten-export) The symbol "OperationVariables" needs to be exported by the entry point index.d.ts + // Warning: (ae-forgotten-export) The symbol "WatchFragmentOptions" needs to be exported by the entry point index.d.ts + // Warning: (ae-forgotten-export) The symbol "WatchFragmentResult" needs to be exported by the entry point index.d.ts + // + // (undocumented) + watchFragment(options: WatchFragmentOptions): Observable>; // Warning: (ae-forgotten-export) The symbol "Reference" needs to be exported by the entry point index.d.ts // // (undocumented) @@ -161,7 +167,10 @@ class ApolloClient implements DataProxy { readonly typeDefs: ApolloClientOptions["typeDefs"]; // (undocumented) version: string; - // Warning: (ae-forgotten-export) The symbol "OperationVariables" needs to be exported by the entry point index.d.ts + // Warning: (ae-unresolved-link) The @link reference could not be resolved: The package "@apollo/client" does not have an export "Observable" + // Warning: (ae-unresolved-link) The @link reference could not be resolved: The package "@apollo/client" does not have an export "Observable" + // Warning: (ae-unresolved-link) The @link reference could not be resolved: The package "@apollo/client" does not have an export "WatchFragmentOptions" + watchFragment(options: WatchFragmentOptions): Observable>; // Warning: (ae-forgotten-export) The symbol "WatchQueryOptions" needs to be exported by the entry point index.d.ts // Warning: (ae-forgotten-export) The symbol "ObservableQuery" needs to be exported by the entry point index.d.ts // Warning: (ae-unresolved-link) The @link reference could not be resolved: The package "@apollo/client" does not have an export "ObservableQuery" @@ -532,6 +541,40 @@ interface DataProxy { writeQuery(options: DataProxy.WriteQueryOptions): Reference | undefined; } +// Warning: (ae-forgotten-export) The symbol "DeepPartialPrimitive" needs to be exported by the entry point index.d.ts +// Warning: (ae-forgotten-export) The symbol "DeepPartialMap" needs to be exported by the entry point index.d.ts +// Warning: (ae-forgotten-export) The symbol "DeepPartialReadonlyMap" needs to be exported by the entry point index.d.ts +// Warning: (ae-forgotten-export) The symbol "DeepPartialSet" needs to be exported by the entry point index.d.ts +// Warning: (ae-forgotten-export) The symbol "DeepPartialReadonlySet" needs to be exported by the entry point index.d.ts +// Warning: (ae-forgotten-export) The symbol "DeepPartialObject" needs to be exported by the entry point index.d.ts +// +// @public (undocumented) +type DeepPartial = T extends DeepPartialPrimitive ? T : T extends Map ? DeepPartialMap : T extends ReadonlyMap ? DeepPartialReadonlyMap : T extends Set ? DeepPartialSet : T extends ReadonlySet ? DeepPartialReadonlySet : T extends (...args: any[]) => unknown ? T | undefined : T extends object ? T extends (ReadonlyArray) ? TItem[] extends (T) ? readonly TItem[] extends T ? ReadonlyArray> : Array> : DeepPartialObject : DeepPartialObject : unknown; + +// Warning: (ae-forgotten-export) The symbol "DeepPartial" needs to be exported by the entry point index.d.ts +// +// @public (undocumented) +type DeepPartialMap = {} & Map, DeepPartial>; + +// @public (undocumented) +type DeepPartialObject = { + [K in keyof T]?: DeepPartial; +}; + +// Warning: (ae-forgotten-export) The symbol "Primitive" needs to be exported by the entry point index.d.ts +// +// @public (undocumented) +type DeepPartialPrimitive = Primitive | Date | RegExp; + +// @public (undocumented) +type DeepPartialReadonlyMap = {} & ReadonlyMap, DeepPartial>; + +// @public (undocumented) +type DeepPartialReadonlySet = {} & ReadonlySet>; + +// @public (undocumented) +type DeepPartialSet = {} & Set>; + // @public (undocumented) interface DefaultContext extends Record { } @@ -1127,6 +1170,9 @@ type OperationVariables = Record; // @public (undocumented) type Path = ReadonlyArray; +// @public (undocumented) +type Primitive = null | undefined | string | number | boolean | symbol | bigint; + // @public (undocumented) interface QueryData { // (undocumented) @@ -1620,6 +1666,32 @@ interface UriFunction { (operation: Operation): string; } +// @public (undocumented) +interface WatchFragmentOptions { + // @deprecated (undocumented) + canonizeResults?: boolean; + // (undocumented) + fragment: DocumentNode | TypedDocumentNode; + // (undocumented) + fragmentName?: string; + // (undocumented) + from: StoreObject | Reference | string; + // (undocumented) + optimistic?: boolean; + variables?: TVars; +} + +// @public (undocumented) +type WatchFragmentResult = { + data: TData; + complete: true; + missing?: never; +} | { + data: DeepPartial; + complete: false; + missing: MissingTree; +}; + // @public (undocumented) type WatchQueryFetchPolicy = FetchPolicy | "cache-and-network"; diff --git a/.api-reports/api-report-testing.md b/.api-reports/api-report-testing.md index 343bb599d38..b185b0a9081 100644 --- a/.api-reports/api-report-testing.md +++ b/.api-reports/api-report-testing.md @@ -79,6 +79,12 @@ abstract class ApolloCache implements DataProxy { updateQuery(options: Cache_2.UpdateQueryOptions, update: (data: TData | null) => TData | null | void): TData | null; // (undocumented) abstract watch(watch: Cache_2.WatchOptions): () => void; + // Warning: (ae-forgotten-export) The symbol "OperationVariables" needs to be exported by the entry point index.d.ts + // Warning: (ae-forgotten-export) The symbol "WatchFragmentOptions" needs to be exported by the entry point index.d.ts + // Warning: (ae-forgotten-export) The symbol "WatchFragmentResult" needs to be exported by the entry point index.d.ts + // + // (undocumented) + watchFragment(options: WatchFragmentOptions): Observable>; // Warning: (ae-forgotten-export) The symbol "Reference" needs to be exported by the entry point index.d.ts // // (undocumented) @@ -161,7 +167,10 @@ class ApolloClient implements DataProxy { readonly typeDefs: ApolloClientOptions["typeDefs"]; // (undocumented) version: string; - // Warning: (ae-forgotten-export) The symbol "OperationVariables" needs to be exported by the entry point index.d.ts + // Warning: (ae-unresolved-link) The @link reference could not be resolved: The package "@apollo/client" does not have an export "Observable" + // Warning: (ae-unresolved-link) The @link reference could not be resolved: The package "@apollo/client" does not have an export "Observable" + // Warning: (ae-unresolved-link) The @link reference could not be resolved: The package "@apollo/client" does not have an export "WatchFragmentOptions" + watchFragment(options: WatchFragmentOptions): Observable>; // Warning: (ae-forgotten-export) The symbol "WatchQueryOptions" needs to be exported by the entry point index.d.ts // Warning: (ae-forgotten-export) The symbol "ObservableQuery" needs to be exported by the entry point index.d.ts // Warning: (ae-unresolved-link) The @link reference could not be resolved: The package "@apollo/client" does not have an export "ObservableQuery" @@ -527,6 +536,40 @@ interface DataProxy { writeQuery(options: DataProxy.WriteQueryOptions): Reference | undefined; } +// Warning: (ae-forgotten-export) The symbol "DeepPartialPrimitive" needs to be exported by the entry point index.d.ts +// Warning: (ae-forgotten-export) The symbol "DeepPartialMap" needs to be exported by the entry point index.d.ts +// Warning: (ae-forgotten-export) The symbol "DeepPartialReadonlyMap" needs to be exported by the entry point index.d.ts +// Warning: (ae-forgotten-export) The symbol "DeepPartialSet" needs to be exported by the entry point index.d.ts +// Warning: (ae-forgotten-export) The symbol "DeepPartialReadonlySet" needs to be exported by the entry point index.d.ts +// Warning: (ae-forgotten-export) The symbol "DeepPartialObject" needs to be exported by the entry point index.d.ts +// +// @public (undocumented) +type DeepPartial = T extends DeepPartialPrimitive ? T : T extends Map ? DeepPartialMap : T extends ReadonlyMap ? DeepPartialReadonlyMap : T extends Set ? DeepPartialSet : T extends ReadonlySet ? DeepPartialReadonlySet : T extends (...args: any[]) => unknown ? T | undefined : T extends object ? T extends (ReadonlyArray) ? TItem[] extends (T) ? readonly TItem[] extends T ? ReadonlyArray> : Array> : DeepPartialObject : DeepPartialObject : unknown; + +// Warning: (ae-forgotten-export) The symbol "DeepPartial" needs to be exported by the entry point index.d.ts +// +// @public (undocumented) +type DeepPartialMap = {} & Map, DeepPartial>; + +// @public (undocumented) +type DeepPartialObject = { + [K in keyof T]?: DeepPartial; +}; + +// Warning: (ae-forgotten-export) The symbol "Primitive" needs to be exported by the entry point index.d.ts +// +// @public (undocumented) +type DeepPartialPrimitive = Primitive | Date | RegExp; + +// @public (undocumented) +type DeepPartialReadonlyMap = {} & ReadonlyMap, DeepPartial>; + +// @public (undocumented) +type DeepPartialReadonlySet = {} & ReadonlySet>; + +// @public (undocumented) +type DeepPartialSet = {} & Set>; + // @public (undocumented) interface DefaultContext extends Record { } @@ -1234,6 +1277,9 @@ type OperationVariables = Record; // @public (undocumented) type Path = ReadonlyArray; +// @public (undocumented) +type Primitive = null | undefined | string | number | boolean | symbol | bigint; + // @public (undocumented) class QueryInfo { constructor(queryManager: QueryManager, queryId?: string); @@ -1671,6 +1717,32 @@ type VariableMatcher> = (variables: V) => boolean; // @public (undocumented) export function wait(ms: number): Promise; +// @public (undocumented) +interface WatchFragmentOptions { + // @deprecated (undocumented) + canonizeResults?: boolean; + // (undocumented) + fragment: DocumentNode | TypedDocumentNode; + // (undocumented) + fragmentName?: string; + // (undocumented) + from: StoreObject | Reference | string; + // (undocumented) + optimistic?: boolean; + variables?: TVars; +} + +// @public (undocumented) +type WatchFragmentResult = { + data: TData; + complete: true; + missing?: never; +} | { + data: DeepPartial; + complete: false; + missing: MissingTree; +}; + // @public (undocumented) type WatchQueryFetchPolicy = FetchPolicy | "cache-and-network"; diff --git a/.api-reports/api-report-testing_core.md b/.api-reports/api-report-testing_core.md index c8121f60b5b..aca90c131c6 100644 --- a/.api-reports/api-report-testing_core.md +++ b/.api-reports/api-report-testing_core.md @@ -78,6 +78,12 @@ abstract class ApolloCache implements DataProxy { updateQuery(options: Cache_2.UpdateQueryOptions, update: (data: TData | null) => TData | null | void): TData | null; // (undocumented) abstract watch(watch: Cache_2.WatchOptions): () => void; + // Warning: (ae-forgotten-export) The symbol "OperationVariables" needs to be exported by the entry point index.d.ts + // Warning: (ae-forgotten-export) The symbol "WatchFragmentOptions" needs to be exported by the entry point index.d.ts + // Warning: (ae-forgotten-export) The symbol "WatchFragmentResult" needs to be exported by the entry point index.d.ts + // + // (undocumented) + watchFragment(options: WatchFragmentOptions): Observable>; // Warning: (ae-forgotten-export) The symbol "Reference" needs to be exported by the entry point index.d.ts // // (undocumented) @@ -160,7 +166,10 @@ class ApolloClient implements DataProxy { readonly typeDefs: ApolloClientOptions["typeDefs"]; // (undocumented) version: string; - // Warning: (ae-forgotten-export) The symbol "OperationVariables" needs to be exported by the entry point index.d.ts + // Warning: (ae-unresolved-link) The @link reference could not be resolved: The package "@apollo/client" does not have an export "Observable" + // Warning: (ae-unresolved-link) The @link reference could not be resolved: The package "@apollo/client" does not have an export "Observable" + // Warning: (ae-unresolved-link) The @link reference could not be resolved: The package "@apollo/client" does not have an export "WatchFragmentOptions" + watchFragment(options: WatchFragmentOptions): Observable>; // Warning: (ae-forgotten-export) The symbol "WatchQueryOptions" needs to be exported by the entry point index.d.ts // Warning: (ae-forgotten-export) The symbol "ObservableQuery" needs to be exported by the entry point index.d.ts // Warning: (ae-unresolved-link) The @link reference could not be resolved: The package "@apollo/client" does not have an export "ObservableQuery" @@ -526,6 +535,40 @@ interface DataProxy { writeQuery(options: DataProxy.WriteQueryOptions): Reference | undefined; } +// Warning: (ae-forgotten-export) The symbol "DeepPartialPrimitive" needs to be exported by the entry point index.d.ts +// Warning: (ae-forgotten-export) The symbol "DeepPartialMap" needs to be exported by the entry point index.d.ts +// Warning: (ae-forgotten-export) The symbol "DeepPartialReadonlyMap" needs to be exported by the entry point index.d.ts +// Warning: (ae-forgotten-export) The symbol "DeepPartialSet" needs to be exported by the entry point index.d.ts +// Warning: (ae-forgotten-export) The symbol "DeepPartialReadonlySet" needs to be exported by the entry point index.d.ts +// Warning: (ae-forgotten-export) The symbol "DeepPartialObject" needs to be exported by the entry point index.d.ts +// +// @public (undocumented) +type DeepPartial = T extends DeepPartialPrimitive ? T : T extends Map ? DeepPartialMap : T extends ReadonlyMap ? DeepPartialReadonlyMap : T extends Set ? DeepPartialSet : T extends ReadonlySet ? DeepPartialReadonlySet : T extends (...args: any[]) => unknown ? T | undefined : T extends object ? T extends (ReadonlyArray) ? TItem[] extends (T) ? readonly TItem[] extends T ? ReadonlyArray> : Array> : DeepPartialObject : DeepPartialObject : unknown; + +// Warning: (ae-forgotten-export) The symbol "DeepPartial" needs to be exported by the entry point index.d.ts +// +// @public (undocumented) +type DeepPartialMap = {} & Map, DeepPartial>; + +// @public (undocumented) +type DeepPartialObject = { + [K in keyof T]?: DeepPartial; +}; + +// Warning: (ae-forgotten-export) The symbol "Primitive" needs to be exported by the entry point index.d.ts +// +// @public (undocumented) +type DeepPartialPrimitive = Primitive | Date | RegExp; + +// @public (undocumented) +type DeepPartialReadonlyMap = {} & ReadonlyMap, DeepPartial>; + +// @public (undocumented) +type DeepPartialReadonlySet = {} & ReadonlySet>; + +// @public (undocumented) +type DeepPartialSet = {} & Set>; + // @public (undocumented) interface DefaultContext extends Record { } @@ -1189,6 +1232,9 @@ type OperationVariables = Record; // @public (undocumented) type Path = ReadonlyArray; +// @public (undocumented) +type Primitive = null | undefined | string | number | boolean | symbol | bigint; + // @public (undocumented) class QueryInfo { constructor(queryManager: QueryManager, queryId?: string); @@ -1628,6 +1674,32 @@ type VariableMatcher> = (variables: V) => boolean; // @public (undocumented) export function wait(ms: number): Promise; +// @public (undocumented) +interface WatchFragmentOptions { + // @deprecated (undocumented) + canonizeResults?: boolean; + // (undocumented) + fragment: DocumentNode | TypedDocumentNode; + // (undocumented) + fragmentName?: string; + // (undocumented) + from: StoreObject | Reference | string; + // (undocumented) + optimistic?: boolean; + variables?: TVars; +} + +// @public (undocumented) +type WatchFragmentResult = { + data: TData; + complete: true; + missing?: never; +} | { + data: DeepPartial; + complete: false; + missing: MissingTree; +}; + // @public (undocumented) type WatchQueryFetchPolicy = FetchPolicy | "cache-and-network"; diff --git a/.api-reports/api-report-utilities.md b/.api-reports/api-report-utilities.md index b47dd5550a0..984843a9dcf 100644 --- a/.api-reports/api-report-utilities.md +++ b/.api-reports/api-report-utilities.md @@ -94,6 +94,12 @@ abstract class ApolloCache implements DataProxy { updateQuery(options: Cache_2.UpdateQueryOptions, update: (data: TData | null) => TData | null | void): TData | null; // (undocumented) abstract watch(watch: Cache_2.WatchOptions): () => void; + // Warning: (ae-forgotten-export) The symbol "OperationVariables" needs to be exported by the entry point index.d.ts + // Warning: (ae-forgotten-export) The symbol "WatchFragmentOptions" needs to be exported by the entry point index.d.ts + // Warning: (ae-forgotten-export) The symbol "WatchFragmentResult" needs to be exported by the entry point index.d.ts + // + // (undocumented) + watchFragment(options: WatchFragmentOptions): Observable>; // (undocumented) abstract write(write: Cache_2.WriteOptions): Reference | undefined; // (undocumented) @@ -173,7 +179,10 @@ class ApolloClient implements DataProxy { readonly typeDefs: ApolloClientOptions["typeDefs"]; // (undocumented) version: string; - // Warning: (ae-forgotten-export) The symbol "OperationVariables" needs to be exported by the entry point index.d.ts + // Warning: (ae-unresolved-link) The @link reference could not be resolved: This type of declaration is not supported yet by the resolver + // Warning: (ae-unresolved-link) The @link reference could not be resolved: This type of declaration is not supported yet by the resolver + // Warning: (ae-unresolved-link) The @link reference could not be resolved: The package "@apollo/client" does not have an export "WatchFragmentOptions" + watchFragment(options: WatchFragmentOptions): Observable>; // Warning: (ae-forgotten-export) The symbol "WatchQueryOptions" needs to be exported by the entry point index.d.ts // Warning: (ae-forgotten-export) The symbol "ObservableQuery" needs to be exported by the entry point index.d.ts // Warning: (ae-unresolved-link) The @link reference could not be resolved: The package "@apollo/client" does not have an export "ObservableQuery" @@ -2577,6 +2586,32 @@ export function valueToObjectRepresentation(argObj: any, name: NameNode, value: // @public (undocumented) export type VariableValue = (node: VariableNode) => any; +// @public (undocumented) +interface WatchFragmentOptions { + // @deprecated (undocumented) + canonizeResults?: boolean; + // (undocumented) + fragment: DocumentNode | TypedDocumentNode; + // (undocumented) + fragmentName?: string; + // (undocumented) + from: StoreObject | Reference | string; + // (undocumented) + optimistic?: boolean; + variables?: TVars; +} + +// @public (undocumented) +type WatchFragmentResult = { + data: TData; + complete: true; + missing?: never; +} | { + data: DeepPartial; + complete: false; + missing: MissingTree; +}; + // @public (undocumented) type WatchQueryFetchPolicy = FetchPolicy | "cache-and-network"; diff --git a/.api-reports/api-report.md b/.api-reports/api-report.md index 1d09c28f12b..10370a4d61d 100644 --- a/.api-reports/api-report.md +++ b/.api-reports/api-report.md @@ -81,6 +81,11 @@ export abstract class ApolloCache implements DataProxy { updateQuery(options: Cache_2.UpdateQueryOptions, update: (data: TData | null) => TData | null | void): TData | null; // (undocumented) abstract watch(watch: Cache_2.WatchOptions): () => void; + // Warning: (ae-forgotten-export) The symbol "WatchFragmentOptions" needs to be exported by the entry point index.d.ts + // Warning: (ae-forgotten-export) The symbol "WatchFragmentResult" needs to be exported by the entry point index.d.ts + // + // (undocumented) + watchFragment(options: WatchFragmentOptions): Observable>; // (undocumented) abstract write(write: Cache_2.WriteOptions): Reference | undefined; // (undocumented) @@ -138,6 +143,10 @@ export class ApolloClient implements DataProxy { readonly typeDefs: ApolloClientOptions["typeDefs"]; // (undocumented) version: string; + // Warning: (ae-unresolved-link) The @link reference could not be resolved: This type of declaration is not supported yet by the resolver + // Warning: (ae-unresolved-link) The @link reference could not be resolved: This type of declaration is not supported yet by the resolver + // Warning: (ae-unresolved-link) The @link reference could not be resolved: The package "@apollo/client" does not have an export "WatchFragmentOptions" + watchFragment(options: WatchFragmentOptions): Observable>; watchQuery(options: WatchQueryOptions): ObservableQuery; writeFragment(options: DataProxy.WriteFragmentOptions): Reference | undefined; writeQuery(options: DataProxy.WriteQueryOptions): Reference | undefined; @@ -3022,6 +3031,32 @@ TVariables variables: TVariables; }; +// @public (undocumented) +interface WatchFragmentOptions { + // @deprecated (undocumented) + canonizeResults?: boolean; + // (undocumented) + fragment: DocumentNode | TypedDocumentNode; + // (undocumented) + fragmentName?: string; + // (undocumented) + from: StoreObject | Reference | string; + // (undocumented) + optimistic?: boolean; + variables?: TVars; +} + +// @public (undocumented) +type WatchFragmentResult = { + data: TData; + complete: true; + missing?: never; +} | { + data: DeepPartial; + complete: false; + missing: MissingTree; +}; + // @public (undocumented) export type WatchQueryFetchPolicy = FetchPolicy | "cache-and-network"; diff --git a/.changeset/tasty-pillows-ring.md b/.changeset/tasty-pillows-ring.md new file mode 100644 index 00000000000..5c0f9643bb5 --- /dev/null +++ b/.changeset/tasty-pillows-ring.md @@ -0,0 +1,5 @@ +--- +"@apollo/client": minor +--- + +Add `watchFragment` method to the cache and expose it on ApolloClient, refactor `useFragment` using `watchFragment`. diff --git a/.size-limits.json b/.size-limits.json index cdae2c9cd42..26e6a5c9660 100644 --- a/.size-limits.json +++ b/.size-limits.json @@ -1,4 +1,4 @@ { - "dist/apollo-client.min.cjs": 39247, - "import { ApolloClient, InMemoryCache, HttpLink } from \"dist/index.js\" (production)": 32630 + "dist/apollo-client.min.cjs": 39286, + "import { ApolloClient, InMemoryCache, HttpLink } from \"dist/index.js\" (production)": 32838 } diff --git a/src/__tests__/ApolloClient.ts b/src/__tests__/ApolloClient.ts index 993691abe0c..35511eda9b9 100644 --- a/src/__tests__/ApolloClient.ts +++ b/src/__tests__/ApolloClient.ts @@ -13,7 +13,8 @@ import { Observable } from "../utilities"; import { ApolloLink } from "../link/core"; import { HttpLink } from "../link/http"; import { InMemoryCache } from "../cache"; -import { itAsync } from "../testing"; +import { concatPagination } from "../utilities"; +import { itAsync, wait } from "../testing"; import { spyOnConsole } from "../testing/internal"; import { TypedDocumentNode } from "@graphql-typed-document-node/core"; import { invariant } from "../utilities/globals"; @@ -2174,6 +2175,295 @@ describe("ApolloClient", () => { ); }); + describe.only("watchFragment", () => { + type Item = { + __typename: string; + id: number; + text?: string; + }; + + it.only("if all data is available, `complete` is `true`", async () => { + const cache = new InMemoryCache(); + const client = new ApolloClient({ + cache, + link: ApolloLink.empty(), + }); + const ItemFragment = gql` + fragment ItemFragment on Item { + id + text + } + `; + + cache.writeFragment({ + fragment: ItemFragment, + data: { + __typename: "Item", + id: 5, + text: "Item #5", + }, + }); + + const observable = client.watchFragment({ + fragment: ItemFragment, + from: { __typename: "Item", id: 5 }, + }); + + const handleNext = jest.fn(); + + observable.subscribe(handleNext); + + await wait(0); // need to wait a tick + + expect(handleNext).toHaveBeenCalledTimes(1); + + expect(handleNext).toHaveBeenLastCalledWith({ + data: { + __typename: "Item", + id: 5, + text: "Item #5", + }, + complete: true, + }); + }); + it("if only partial data is available, `complete` is `false`", async () => { + const cache = new InMemoryCache(); + const client = new ApolloClient({ + cache, + link: ApolloLink.empty(), + }); + const ItemFragment = gql` + fragment ItemFragment on Item { + id + text + } + `; + + const observable = client.watchFragment({ + fragment: ItemFragment, + from: { __typename: "Item", id: 5 }, + }); + + const handleNext = jest.fn(); + + observable.subscribe(handleNext); + + { + // we expect a "Missing field 'text' while writing result..." error + // when writing item to the cache, so we'll silence the console.error + using _consoleSpy = spyOnConsole("error"); + cache.writeFragment({ + fragment: ItemFragment, + data: { + __typename: "Item", + id: 5, + }, + }); + } + + expect(handleNext).toHaveBeenCalledTimes(1); + + expect(handleNext).toHaveBeenLastCalledWith({ + data: { + __typename: "Item", + id: 5, + }, + complete: false, + missing: { + text: "Can't find field 'text' on Item:5 object", + }, + }); + }); + it("if no data is written after observable is subscribed to, next is never called", async () => { + const cache = new InMemoryCache(); + const client = new ApolloClient({ + cache, + link: ApolloLink.empty(), + }); + const ItemFragment = gql` + fragment ItemFragment on Item { + id + text + } + `; + + const observable = client.watchFragment({ + fragment: ItemFragment, + from: { __typename: "Item", id: 5 }, + }); + + const handleNext = jest.fn(); + + observable.subscribe(handleNext); + + expect(handleNext).toHaveBeenCalledTimes(0); + }); + // it.only("does not react to updates to @nonreactive fields", async () => { + // const cache = new InMemoryCache(); + // const client = new ApolloClient({ + // cache, + // link: ApolloLink.empty(), + // }); + // const ItemFragment = gql` + // fragment ItemFragment on Item { + // id + // text @nonreactive + // } + // `; + + // const observable = client.watchFragment({ + // fragment: ItemFragment, + // from: { __typename: "Item", id: 5 }, + // }); + + // const handleNext = jest.fn(); + + // observable.subscribe(handleNext); + + // cache.writeFragment({ + // fragment: ItemFragment, + // data: { + // __typename: "Item", + // id: 5, + // text: "Item #5", + // }, + // }); + + // expect(handleNext).toHaveBeenCalledTimes(1); + // expect(handleNext).toHaveBeenLastCalledWith({ + // data: { + // __typename: "Item", + // id: 5, + // text: "Item #5", + // }, + // complete: true, + // }); + // }); + it.each>([ + // This query uses a basic field-level @nonreactive directive. + gql` + query GetItems { + list { + id + text @nonreactive + } + } + `, + // This query uses @nonreactive on an anonymous/inline ...spread directive. + gql` + query GetItems { + list { + id + ... @nonreactive { + text + } + } + } + `, + // This query uses @nonreactive on a ...spread with a type condition. + gql` + query GetItems { + list { + id + ... on Item @nonreactive { + text + } + } + } + `, + // This query uses @nonreactive directive on a named fragment ...spread. + gql` + query GetItems { + list { + id + ...ItemText @nonreactive + } + } + fragment ItemText on Item { + text + } + `, + ])( + "watchQuery can use @nonreactive to avoid rerendering", + async (query) => { + const cache = new InMemoryCache({ + typePolicies: { + Query: { + fields: { + list: concatPagination(), + }, + }, + Item: { + keyFields: ["id"], + // Configuring keyArgs:false for Item.text is one way to prevent field + // keys like text@nonreactive, but it's not the only way. Since + // @nonreactive is now in the KNOWN_DIRECTIVES array defined in + // utilities/graphql/storeUtils.ts, the '@nonreactive' suffix won't be + // automatically appended to field keys by default. + // fields: { + // text: { + // keyArgs: false, + // }, + // }, + }, + }, + }); + + const client = new ApolloClient({ + cache, + link: ApolloLink.empty(), + }); + + const queryObs = client.watchQuery({ + query, + }); + + const handleNext = jest.fn(); + + queryObs.subscribe(handleNext); + + cache.writeQuery({ + query, + data: { + list: [ + { __typename: "Item", id: 1, text: "first" }, + { __typename: "Item", id: 2, text: "second" }, + { __typename: "Item", id: 3, text: "third" }, + ], + }, + }); + + expect(cache.extract()).toEqual({ + ROOT_QUERY: { + __typename: "Query", + list: [ + { __ref: 'Item:{"id":1}' }, + { __ref: 'Item:{"id":2}' }, + { __ref: 'Item:{"id":3}' }, + ], + }, + 'Item:{"id":1}': { + __typename: "Item", + id: 1, + text: "first", + }, + 'Item:{"id":2}': { + __typename: "Item", + id: 2, + text: "second", + }, + 'Item:{"id":3}': { + __typename: "Item", + id: 3, + text: "third", + }, + }); + } + ); + it.todo("always returns partial data"); + it.todo("missing is a tree describing missing fields"); + }); + describe("defaultOptions", () => { it( "should set `defaultOptions` to an empty object if not provided in " + diff --git a/src/cache/core/cache.ts b/src/cache/core/cache.ts index a0fd1778bdc..68b4a67f92c 100644 --- a/src/cache/core/cache.ts +++ b/src/cache/core/cache.ts @@ -1,19 +1,67 @@ import type { DocumentNode } from "graphql"; import { wrap } from "optimism"; -import type { StoreObject, Reference } from "../../utilities/index.js"; +import type { + StoreObject, + Reference, + DeepPartial, +} from "../../utilities/index.js"; import { + Observable, cacheSizes, defaultCacheSizes, getFragmentQueryDocument, + mergeDeepArray, } from "../../utilities/index.js"; 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"; +import type { + OperationVariables, + TypedDocumentNode, +} from "../../core/types.js"; +import { equal } from "@wry/equality"; +import type { MissingTree } from "./types/common.js"; export type Transaction = (c: ApolloCache) => void; +// todo: confirm we can start with this limited set of options +export interface WatchFragmentOptions { + fragment: DocumentNode | TypedDocumentNode; + from: StoreObject | Reference | string; + /** + * Any variables that the GraphQL query may depend on. + */ + variables?: TVars; + fragmentName?: string; + optimistic?: boolean; + /** + * @deprecated + * Using `canonizeResults` can result in memory leaks so we generally do not + * recommend using this option anymore. + * A future version of Apollo Client will contain a similar feature. + * + * Whether to canonize cache results before returning them. Canonization + * takes some extra time, but it speeds up future deep equality comparisons. + * Defaults to false. + */ + canonizeResults?: boolean; +} + +// todo: refactor duplicated type, see UseFragmentResult +export type WatchFragmentResult = + | { + data: TData; + complete: true; + missing?: never; + } + | { + data: DeepPartial; + complete: false; + missing: MissingTree; + }; + export abstract class ApolloCache implements DataProxy { public readonly assumeImmutableResults: boolean = false; @@ -141,6 +189,46 @@ export abstract class ApolloCache implements DataProxy { }); } + public watchFragment( + options: WatchFragmentOptions + ): Observable> { + const { fragment, fragmentName, from, optimistic = true } = options; + + const diffOptions: Cache.DiffOptions = { + returnPartialData: true, + id: typeof from === "string" ? from : this.identify(from), + query: this.getFragmentDoc(fragment, fragmentName), + optimistic, + }; + + // let latestDiff: DataProxy.DiffResult | undefined = undefined; + let latestDiff: DataProxy.DiffResult = this.diff(diffOptions); + + return new Observable((observer) => { + return this.watch({ + ...diffOptions, + immediate: true, // is this necessary? tests pass without it + query: this.getFragmentDoc(fragment, fragmentName), + callback(diff) { + const result = { + data: diff.result as DeepPartial, + complete: !!diff.complete, + } as WatchFragmentResult; + + if (diff.missing) { + result.missing = mergeDeepArray( + diff.missing.map((error) => error.missing) + ); + } + if (!equal(diff, latestDiff)) { + latestDiff = diff; + observer.next(result); + } + }, + }); + }); + } + // Make sure we compute the same (===) fragment query document every // time we receive the same fragment in readFragment. private getFragmentDoc = wrap(getFragmentQueryDocument, { diff --git a/src/core/ApolloClient.ts b/src/core/ApolloClient.ts index e564a249c10..49605a490c7 100644 --- a/src/core/ApolloClient.ts +++ b/src/core/ApolloClient.ts @@ -128,6 +128,7 @@ export interface ApolloClientOptions { // solution is to reexport mergeOptions where it was previously declared (here). import { mergeOptions } from "../utilities/index.js"; import { getApolloClientMemoryInternals } from "../utilities/caching/getMemoryInternals.js"; +import type { WatchFragmentOptions } from "../cache/core/cache.js"; export { mergeOptions }; /** @@ -474,6 +475,29 @@ export class ApolloClient implements DataProxy { return this.cache.readQuery(options, optimistic); } + /** + * Watches the cache store of the fragment according to the options specified + * and returns an {@link Observable}. We can subscribe to this + * {@link Observable} and receive updated results through a GraphQL + * observer when the cache store changes. + * + * You must pass in a GraphQL document with a single fragment or a document + * with multiple fragments that represent what you are reading. If you pass + * in a document with multiple fragments then you must also specify a + * `fragmentName`. + * + * @param options - An object of type {@link WatchFragmentOptions} that allows + * the cache to identify the fragment and optionally specify whether to react + * to optimistic updates. + */ + + public watchFragment< + TFragmentData = unknown, + TVariables = OperationVariables, + >(options: WatchFragmentOptions) { + return this.cache.watchFragment(options); + } + /** * Tries to read some data from the store in the shape of the provided * GraphQL fragment without making a network request. This method will read a diff --git a/src/react/hooks/useFragment.ts b/src/react/hooks/useFragment.ts index 96e2a1c014a..4c39a03db0d 100644 --- a/src/react/hooks/useFragment.ts +++ b/src/react/hooks/useFragment.ts @@ -1,5 +1,4 @@ import * as React from "rehackt"; -import { equal } from "@wry/equality"; import type { DeepPartial } from "../../utilities/index.js"; import { mergeDeepArray } from "../../utilities/index.js"; @@ -84,9 +83,15 @@ function _useFragment( }; }, [options]); + // TODO: use regular useRef here and set the value inside of useMemo const resultRef = useLazyRef>(() => diffToResult(cache.diff(diffOptions)) ); + // explain the timing issue: since next is async, we need to make sure that we + // get the correct diff on next render given new diffOptions + React.useMemo(() => { + resultRef.current = diffToResult(cache.diff(diffOptions)); + }, [diffOptions, cache]); // Used for both getSnapshot and getServerSnapshot const getSnapshot = React.useCallback(() => resultRef.current, []); @@ -95,23 +100,19 @@ function _useFragment( React.useCallback( (forceUpdate) => { let lastTimeout = 0; - const unsubscribe = cache.watch({ - ...diffOptions, - immediate: true, - callback(diff) { - if (!equal(diff.result, resultRef.current.data)) { - resultRef.current = diffToResult(diff); - // If we get another update before we've re-rendered, bail out of - // the update and try again. This ensures that the relative timing - // between useQuery and useFragment stays roughly the same as - // fixed in https://github.com/apollographql/apollo-client/pull/11083 - clearTimeout(lastTimeout); - lastTimeout = setTimeout(forceUpdate) as any; - } + const subscription = cache.watchFragment(options).subscribe({ + next: (result) => { + resultRef.current = result; + // If we get another update before we've re-rendered, bail out of + // the update and try again. This ensures that the relative timing + // between useQuery and useFragment stays roughly the same as + // fixed in https://github.com/apollographql/apollo-client/pull/11083 + clearTimeout(lastTimeout); + lastTimeout = setTimeout(forceUpdate) as any; }, }); return () => { - unsubscribe(); + subscription.unsubscribe(); clearTimeout(lastTimeout); }; }, From 3018643448a5aaf0a82da748ea6702ad8a59f5fa Mon Sep 17 00:00:00 2001 From: alessbell Date: Tue, 12 Mar 2024 19:24:31 +0000 Subject: [PATCH 02/25] Clean up Prettier, Size-limit, and Api-Extractor --- .size-limits.json | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.size-limits.json b/.size-limits.json index 26e6a5c9660..794611fa35e 100644 --- a/.size-limits.json +++ b/.size-limits.json @@ -1,4 +1,4 @@ { - "dist/apollo-client.min.cjs": 39286, - "import { ApolloClient, InMemoryCache, HttpLink } from \"dist/index.js\" (production)": 32838 + "dist/apollo-client.min.cjs": 39402, + "import { ApolloClient, InMemoryCache, HttpLink } from \"dist/index.js\" (production)": 32793 } From 58808c7a725d6156d9efdbe18fcd4e99981e8643 Mon Sep 17 00:00:00 2001 From: Alessia Bellisario Date: Tue, 12 Mar 2024 16:28:37 -0400 Subject: [PATCH 03/25] chore: add docs and pr fixes --- docs/source/caching/cache-interaction.mdx | 8 +++ src/__tests__/ApolloClient.ts | 86 +++++++++++------------ src/cache/core/cache.ts | 6 +- src/react/hooks/useFragment.ts | 10 ++- 4 files changed, 57 insertions(+), 53 deletions(-) diff --git a/docs/source/caching/cache-interaction.mdx b/docs/source/caching/cache-interaction.mdx index 33baca6a11a..1c750f84b5e 100644 --- a/docs/source/caching/cache-interaction.mdx +++ b/docs/source/caching/cache-interaction.mdx @@ -213,6 +213,14 @@ All subscribers to the Apollo Client cache (including all active queries) see th +### `watchFragment` + + + +You can watch a fragment for changes using the `watchFragment` method. This method returns an `Observable` that emits the current value of the fragment and emits new values whenever cache data selected by the fragment changes. [See the API reference.](../api/cache/InMemoryCache/#watchfragment) + + + ### `useFragment` diff --git a/src/__tests__/ApolloClient.ts b/src/__tests__/ApolloClient.ts index 35511eda9b9..46f0bdc0745 100644 --- a/src/__tests__/ApolloClient.ts +++ b/src/__tests__/ApolloClient.ts @@ -2175,14 +2175,14 @@ describe("ApolloClient", () => { ); }); - describe.only("watchFragment", () => { + describe("watchFragment", () => { type Item = { __typename: string; id: number; text?: string; }; - it.only("if all data is available, `complete` is `true`", async () => { + it("if all data is available, `complete` is `true`", async () => { const cache = new InMemoryCache(); const client = new ApolloClient({ cache, @@ -2298,47 +2298,47 @@ describe("ApolloClient", () => { expect(handleNext).toHaveBeenCalledTimes(0); }); - // it.only("does not react to updates to @nonreactive fields", async () => { - // const cache = new InMemoryCache(); - // const client = new ApolloClient({ - // cache, - // link: ApolloLink.empty(), - // }); - // const ItemFragment = gql` - // fragment ItemFragment on Item { - // id - // text @nonreactive - // } - // `; - - // const observable = client.watchFragment({ - // fragment: ItemFragment, - // from: { __typename: "Item", id: 5 }, - // }); - - // const handleNext = jest.fn(); - - // observable.subscribe(handleNext); - - // cache.writeFragment({ - // fragment: ItemFragment, - // data: { - // __typename: "Item", - // id: 5, - // text: "Item #5", - // }, - // }); - - // expect(handleNext).toHaveBeenCalledTimes(1); - // expect(handleNext).toHaveBeenLastCalledWith({ - // data: { - // __typename: "Item", - // id: 5, - // text: "Item #5", - // }, - // complete: true, - // }); - // }); + it("does not react to updates to @nonreactive fields", async () => { + const cache = new InMemoryCache(); + const client = new ApolloClient({ + cache, + link: ApolloLink.empty(), + }); + const ItemFragment = gql` + fragment ItemFragment on Item { + id + text @nonreactive + } + `; + + const observable = client.watchFragment({ + fragment: ItemFragment, + from: { __typename: "Item", id: 5 }, + }); + + const handleNext = jest.fn(); + + observable.subscribe(handleNext); + + cache.writeFragment({ + fragment: ItemFragment, + data: { + __typename: "Item", + id: 5, + text: "Item #5", + }, + }); + + expect(handleNext).toHaveBeenCalledTimes(1); + expect(handleNext).toHaveBeenLastCalledWith({ + data: { + __typename: "Item", + id: 5, + text: "Item #5", + }, + complete: true, + }); + }); it.each>([ // This query uses a basic field-level @nonreactive directive. gql` diff --git a/src/cache/core/cache.ts b/src/cache/core/cache.ts index 68b4a67f92c..f22cdc348cd 100644 --- a/src/cache/core/cache.ts +++ b/src/cache/core/cache.ts @@ -26,7 +26,6 @@ import type { MissingTree } from "./types/common.js"; export type Transaction = (c: ApolloCache) => void; -// todo: confirm we can start with this limited set of options export interface WatchFragmentOptions { fragment: DocumentNode | TypedDocumentNode; from: StoreObject | Reference | string; @@ -201,13 +200,12 @@ export abstract class ApolloCache implements DataProxy { optimistic, }; - // let latestDiff: DataProxy.DiffResult | undefined = undefined; - let latestDiff: DataProxy.DiffResult = this.diff(diffOptions); + let latestDiff = this.diff(diffOptions); return new Observable((observer) => { return this.watch({ ...diffOptions, - immediate: true, // is this necessary? tests pass without it + immediate: true, query: this.getFragmentDoc(fragment, fragmentName), callback(diff) { const result = { diff --git a/src/react/hooks/useFragment.ts b/src/react/hooks/useFragment.ts index 4c39a03db0d..47ec2d2bca0 100644 --- a/src/react/hooks/useFragment.ts +++ b/src/react/hooks/useFragment.ts @@ -1,5 +1,4 @@ import * as React from "rehackt"; - import type { DeepPartial } from "../../utilities/index.js"; import { mergeDeepArray } from "../../utilities/index.js"; import type { @@ -13,7 +12,7 @@ import { useApolloClient } from "./useApolloClient.js"; import { useSyncExternalStore } from "./useSyncExternalStore.js"; import type { ApolloClient, OperationVariables } from "../../core/index.js"; import type { NoInfer } from "../types/types.js"; -import { useDeepMemo, useLazyRef, wrapHook } from "./internal/index.js"; +import { useDeepMemo, wrapHook } from "./internal/index.js"; export interface UseFragmentOptions extends Omit< @@ -83,12 +82,11 @@ function _useFragment( }; }, [options]); - // TODO: use regular useRef here and set the value inside of useMemo - const resultRef = useLazyRef>(() => + const resultRef = React.useRef>( diffToResult(cache.diff(diffOptions)) ); - // explain the timing issue: since next is async, we need to make sure that we - // get the correct diff on next render given new diffOptions + // Since .next is async, we need to make sure that we + // get the correct diff on the next render given new diffOptions React.useMemo(() => { resultRef.current = diffToResult(cache.diff(diffOptions)); }, [diffOptions, cache]); From 9897f51cad61c9326fe6190cb62c6e4f3484952e Mon Sep 17 00:00:00 2001 From: alessbell Date: Tue, 12 Mar 2024 20:30:58 +0000 Subject: [PATCH 04/25] Clean up Prettier, Size-limit, and Api-Extractor --- .size-limits.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.size-limits.json b/.size-limits.json index 794611fa35e..9e2f6b3d09f 100644 --- a/.size-limits.json +++ b/.size-limits.json @@ -1,4 +1,4 @@ { - "dist/apollo-client.min.cjs": 39402, + "dist/apollo-client.min.cjs": 39376, "import { ApolloClient, InMemoryCache, HttpLink } from \"dist/index.js\" (production)": 32793 } From ea48ea3c6dea5dfce34d50e0e8505c0e8badfa09 Mon Sep 17 00:00:00 2001 From: Alessia Bellisario Date: Tue, 12 Mar 2024 17:00:53 -0400 Subject: [PATCH 05/25] small refactor --- src/cache/core/cache.ts | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/src/cache/core/cache.ts b/src/cache/core/cache.ts index f22cdc348cd..15e4483688b 100644 --- a/src/cache/core/cache.ts +++ b/src/cache/core/cache.ts @@ -208,6 +208,10 @@ export abstract class ApolloCache implements DataProxy { immediate: true, query: this.getFragmentDoc(fragment, fragmentName), callback(diff) { + if (equal(diff, latestDiff)) { + return; + } + const result = { data: diff.result as DeepPartial, complete: !!diff.complete, @@ -218,10 +222,9 @@ export abstract class ApolloCache implements DataProxy { diff.missing.map((error) => error.missing) ); } - if (!equal(diff, latestDiff)) { - latestDiff = diff; - observer.next(result); - } + + latestDiff = diff; + observer.next(result); }, }); }); From 64b61397f753c14501b2a4128a90ab59e0cb9355 Mon Sep 17 00:00:00 2001 From: alessbell Date: Tue, 12 Mar 2024 21:03:08 +0000 Subject: [PATCH 06/25] Clean up Prettier, Size-limit, and Api-Extractor --- .size-limits.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.size-limits.json b/.size-limits.json index 9e2f6b3d09f..1332ae918c5 100644 --- a/.size-limits.json +++ b/.size-limits.json @@ -1,4 +1,4 @@ { - "dist/apollo-client.min.cjs": 39376, + "dist/apollo-client.min.cjs": 39374, "import { ApolloClient, InMemoryCache, HttpLink } from \"dist/index.js\" (production)": 32793 } From 397b3b3df6a0c4e8b1b2c4dc014da5eb92d32df8 Mon Sep 17 00:00:00 2001 From: Alessia Bellisario Date: Thu, 14 Mar 2024 15:34:44 -0400 Subject: [PATCH 07/25] docs: adds doc block annotations for generated docs --- config/inlineInheritDoc.ts | 1 + docs/README.md | 11 ++++++++- docs/source/api/cache/InMemoryCache.mdx | 7 ++++++ docs/source/api/core/ApolloClient.mdx | 1 + docs/source/api/core/ObservableQuery.mdx | 1 + docs/source/caching/cache-interaction.mdx | 8 ++++-- src/cache/core/cache.ts | 1 + src/core/ApolloClient.ts | 30 ++++++++++++++--------- 8 files changed, 45 insertions(+), 15 deletions(-) diff --git a/config/inlineInheritDoc.ts b/config/inlineInheritDoc.ts index 704054f28ec..0bb126629ae 100644 --- a/config/inlineInheritDoc.ts +++ b/config/inlineInheritDoc.ts @@ -143,6 +143,7 @@ function processComments() { if ( Node.isPropertySignature(node) || Node.isMethodSignature(node) || + Node.isMethodDeclaration(node) || Node.isCallSignatureDeclaration(node) ) { const docsNode = node.getJsDocs()[0]; diff --git a/docs/README.md b/docs/README.md index cb9d3ba95d3..9410556e966 100644 --- a/docs/README.md +++ b/docs/README.md @@ -6,4 +6,13 @@ The **deployed** version of the documentation for this repository is available a * https://www.apollographql.com/docs/react/ -See the [docs site README](https://github.com/apollographql/docs) for local installation and development. +For general local installation and development instructions, see the [docs site README](https://github.com/apollographql/docs). + +In order to build and develop the Apollo Client docs locally, you will need to follow these additional steps: + +1. Clone the docs site repository ([https://github.com/apollographql/docs](https://github.com/apollographql/docs)) in a sibling directory to your local copy of the [`apollo-client`](https://github.com/apollographql/apollo-client) repository. +2. `cd docs && npm i` +3. Open a new terminal, `cd apollo-client`, make changes to the docs and run `npm run docmodel` +4. Back in the terminal window where you've checked out and cd'd into the `docs` repository, run `DOCS_MODE='local' npm run start:local -- ../apollo-client` +5. Open a browser and visit `http://localhost:3000` +6. Note: you'll need to manually remove the `/react` segment of the URL from the path inside the browser diff --git a/docs/source/api/cache/InMemoryCache.mdx b/docs/source/api/cache/InMemoryCache.mdx index 7bcc362d9ea..4891eef7b01 100644 --- a/docs/source/api/cache/InMemoryCache.mdx +++ b/docs/source/api/cache/InMemoryCache.mdx @@ -2,8 +2,12 @@ title: class InMemoryCache description: API reference api_reference: true +api_doc: + - "@apollo/client!ApolloClient#watchFragment:member(1)" --- +import { FunctionDetails, DocBlock, Example } from '../../../shared/ApiDoc'; + Methods of the `InMemoryCache` class (the cache used by almost every instance of [`ApolloClient`](../core/ApolloClient/)) are documented here. > Before reading about individual methods, see [Caching in Apollo Client](../../caching/overview/). @@ -768,6 +772,9 @@ writeFragment( options: Cache.WriteFragmentOptions, ): Reference | undefined ``` + + + ## `updateFragment` diff --git a/docs/source/api/core/ApolloClient.mdx b/docs/source/api/core/ApolloClient.mdx index 752f6633d9e..0294973a18e 100644 --- a/docs/source/api/core/ApolloClient.mdx +++ b/docs/source/api/core/ApolloClient.mdx @@ -36,6 +36,7 @@ For more information on the `defaultOptions` object, see the [Default Options](# + diff --git a/docs/source/api/core/ObservableQuery.mdx b/docs/source/api/core/ObservableQuery.mdx index 806091f8b28..89c5448be7e 100644 --- a/docs/source/api/core/ObservableQuery.mdx +++ b/docs/source/api/core/ObservableQuery.mdx @@ -1,6 +1,7 @@ --- title: ObservableQuery description: API reference +api_reference: true api_doc: - "@apollo/client!ObservableQuery:class" - "@apollo/client!ApolloQueryResult:interface" diff --git a/docs/source/caching/cache-interaction.mdx b/docs/source/caching/cache-interaction.mdx index 1c750f84b5e..4331a5da14f 100644 --- a/docs/source/caching/cache-interaction.mdx +++ b/docs/source/caching/cache-interaction.mdx @@ -1,7 +1,11 @@ --- title: Reading and writing data to the cache +api_doc: + - "@apollo/client!ApolloClient#watchFragment:member(1)" --- +import { DocBlock } from '../../shared/ApiDoc'; + You can read and write data directly to the Apollo Client cache, _without_ communicating with your GraphQL server. You can interact with data that you previously fetched from your server, _and_ with data that's only available [locally](../local-state/local-state-management/). Apollo Client supports multiple strategies for interacting with cached data: @@ -211,13 +215,13 @@ client.writeFragment({ All subscribers to the Apollo Client cache (including all active queries) see this change and update your application's UI accordingly. - + ### `watchFragment` -You can watch a fragment for changes using the `watchFragment` method. This method returns an `Observable` that emits the current value of the fragment and emits new values whenever cache data selected by the fragment changes. [See the API reference.](../api/cache/InMemoryCache/#watchfragment) + diff --git a/src/cache/core/cache.ts b/src/cache/core/cache.ts index 15e4483688b..8e018ac900f 100644 --- a/src/cache/core/cache.ts +++ b/src/cache/core/cache.ts @@ -188,6 +188,7 @@ export abstract class ApolloCache implements DataProxy { }); } + /** {@inheritDoc @apollo/client!ApolloClient#watchFragment:member(1)} */ public watchFragment( options: WatchFragmentOptions ): Observable> { diff --git a/src/core/ApolloClient.ts b/src/core/ApolloClient.ts index 49605a490c7..3de11723a3b 100644 --- a/src/core/ApolloClient.ts +++ b/src/core/ApolloClient.ts @@ -58,7 +58,7 @@ export interface ApolloClientOptions { */ headers?: Record; /** - * You can provide an {@link ApolloLink} instance to serve as Apollo Client's network layer. For more information, see [Advanced HTTP networking](https://www.apollographql.com/docs/react/networking/advanced-http-networking/). + * You can provide an `ApolloLink` instance to serve as Apollo Client's network layer. For more information, see [Advanced HTTP networking](https://www.apollographql.com/docs/react/networking/advanced-http-networking/). * * One of `uri` or `link` is **required**. If you provide both, `link` takes precedence. */ @@ -128,14 +128,17 @@ export interface ApolloClientOptions { // solution is to reexport mergeOptions where it was previously declared (here). import { mergeOptions } from "../utilities/index.js"; import { getApolloClientMemoryInternals } from "../utilities/caching/getMemoryInternals.js"; -import type { WatchFragmentOptions } from "../cache/core/cache.js"; +import type { + WatchFragmentOptions, + WatchFragmentResult, +} from "../cache/core/cache.js"; export { mergeOptions }; /** * This is the primary Apollo Client class. It is used to send GraphQL documents (i.e. queries - * and mutations) to a GraphQL spec-compliant server over an {@link ApolloLink} instance, + * and mutations) to a GraphQL spec-compliant server over an `ApolloLink` instance, * receive results from the server and cache the results in a store. It also delivers updates - * to GraphQL queries through {@link Observable} instances. + * to GraphQL queries through `Observable` instances. */ export class ApolloClient implements DataProxy { public link: ApolloLink; @@ -153,7 +156,7 @@ export class ApolloClient implements DataProxy { private localState: LocalState; /** - * Constructs an instance of {@link ApolloClient}. + * Constructs an instance of `ApolloClient`. * * @example * ```js @@ -355,7 +358,7 @@ export class ApolloClient implements DataProxy { /** * This watches the cache store of the query according to the options specified and - * returns an {@link ObservableQuery}. We can subscribe to this {@link ObservableQuery} and + * returns an `ObservableQuery`. We can subscribe to this `ObservableQuery` and * receive updated results through a GraphQL observer when the cache store changes. * * Note that this method is not an implementation of GraphQL subscriptions. Rather, @@ -397,7 +400,7 @@ export class ApolloClient implements DataProxy { * returns a `Promise` which is either resolved with the resulting data * or rejected with an error. * - * @param options - An object of type {@link QueryOptions} that allows us to + * @param options - An object of type `QueryOptions` that allows us to * describe how this query should be treated e.g. whether it should hit the * server at all or just resolve from the cache, etc. */ @@ -450,7 +453,7 @@ export class ApolloClient implements DataProxy { /** * This subscribes to a graphql subscription according to the options specified and returns an - * {@link Observable} which either emits received data or an error. + * `Observable` which either emits received data or an error. */ public subscribe< T = any, @@ -477,8 +480,8 @@ export class ApolloClient implements DataProxy { /** * Watches the cache store of the fragment according to the options specified - * and returns an {@link Observable}. We can subscribe to this - * {@link Observable} and receive updated results through a GraphQL + * and returns an Observable. We can subscribe to this + * Observable and receive updated results through a GraphQL * observer when the cache store changes. * * You must pass in a GraphQL document with a single fragment or a document @@ -486,7 +489,8 @@ export class ApolloClient implements DataProxy { * in a document with multiple fragments then you must also specify a * `fragmentName`. * - * @param options - An object of type {@link WatchFragmentOptions} that allows + * @since 3.10.0 + * @param options - An object of type `WatchFragmentOptions` that allows * the cache to identify the fragment and optionally specify whether to react * to optimistic updates. */ @@ -494,7 +498,9 @@ export class ApolloClient implements DataProxy { public watchFragment< TFragmentData = unknown, TVariables = OperationVariables, - >(options: WatchFragmentOptions) { + >( + options: WatchFragmentOptions + ): Observable> { return this.cache.watchFragment(options); } From 41b49d77326d552b12c5598b5ff66d548d3eb190 Mon Sep 17 00:00:00 2001 From: alessbell Date: Thu, 14 Mar 2024 19:37:04 +0000 Subject: [PATCH 08/25] Clean up Prettier, Size-limit, and Api-Extractor --- .api-reports/api-report-cache.md | 2 -- .api-reports/api-report-core.md | 8 -------- .api-reports/api-report-react.md | 14 -------------- .api-reports/api-report-react_components.md | 14 -------------- .api-reports/api-report-react_context.md | 14 -------------- .api-reports/api-report-react_hoc.md | 14 -------------- .api-reports/api-report-react_hooks.md | 14 -------------- .api-reports/api-report-react_internal.md | 14 -------------- .api-reports/api-report-react_ssr.md | 14 -------------- .api-reports/api-report-testing.md | 14 -------------- .api-reports/api-report-testing_core.md | 14 -------------- .api-reports/api-report-utilities.md | 14 -------------- .api-reports/api-report.md | 8 -------- 13 files changed, 158 deletions(-) diff --git a/.api-reports/api-report-cache.md b/.api-reports/api-report-cache.md index 10deafdae0e..8aca339ffae 100644 --- a/.api-reports/api-report-cache.md +++ b/.api-reports/api-report-cache.md @@ -67,8 +67,6 @@ export abstract class ApolloCache implements DataProxy { // Warning: (ae-forgotten-export) The symbol "OperationVariables" needs to be exported by the entry point index.d.ts // Warning: (ae-forgotten-export) The symbol "WatchFragmentOptions" needs to be exported by the entry point index.d.ts // Warning: (ae-forgotten-export) The symbol "WatchFragmentResult" needs to be exported by the entry point index.d.ts - // - // (undocumented) watchFragment(options: WatchFragmentOptions): Observable>; // (undocumented) abstract write(write: Cache_2.WriteOptions): Reference | undefined; diff --git a/.api-reports/api-report-core.md b/.api-reports/api-report-core.md index 98d5c19e43b..feb59c39143 100644 --- a/.api-reports/api-report-core.md +++ b/.api-reports/api-report-core.md @@ -81,8 +81,6 @@ export abstract class ApolloCache implements DataProxy { abstract watch(watch: Cache_2.WatchOptions): () => void; // Warning: (ae-forgotten-export) The symbol "WatchFragmentOptions" needs to be exported by the entry point index.d.ts // Warning: (ae-forgotten-export) The symbol "WatchFragmentResult" needs to be exported by the entry point index.d.ts - // - // (undocumented) watchFragment(options: WatchFragmentOptions): Observable>; // (undocumented) abstract write(write: Cache_2.WriteOptions): Reference | undefined; @@ -92,8 +90,6 @@ export abstract class ApolloCache implements DataProxy { writeQuery({ id, data, ...options }: Cache_2.WriteQueryOptions): Reference | undefined; } -// Warning: (ae-unresolved-link) The @link reference could not be resolved: This type of declaration is not supported yet by the resolver -// // @public export class ApolloClient implements DataProxy { // (undocumented) @@ -135,15 +131,11 @@ export class ApolloClient implements DataProxy { setLocalStateFragmentMatcher(fragmentMatcher: FragmentMatcher): void; setResolvers(resolvers: Resolvers | Resolvers[]): void; stop(): void; - // Warning: (ae-unresolved-link) The @link reference could not be resolved: This type of declaration is not supported yet by the resolver subscribe(options: SubscriptionOptions): Observable>; // (undocumented) readonly typeDefs: ApolloClientOptions["typeDefs"]; // (undocumented) version: string; - // Warning: (ae-unresolved-link) The @link reference could not be resolved: This type of declaration is not supported yet by the resolver - // Warning: (ae-unresolved-link) The @link reference could not be resolved: This type of declaration is not supported yet by the resolver - // Warning: (ae-unresolved-link) The @link reference could not be resolved: The package "@apollo/client" does not have an export "WatchFragmentOptions" watchFragment(options: WatchFragmentOptions): Observable>; watchQuery(options: WatchQueryOptions): ObservableQuery; writeFragment(options: DataProxy.WriteFragmentOptions): Reference | undefined; diff --git a/.api-reports/api-report-react.md b/.api-reports/api-report-react.md index cde49cab950..87f5a6b3f75 100644 --- a/.api-reports/api-report-react.md +++ b/.api-reports/api-report-react.md @@ -83,8 +83,6 @@ abstract class ApolloCache implements DataProxy { // Warning: (ae-forgotten-export) The symbol "OperationVariables" needs to be exported by the entry point index.d.ts // Warning: (ae-forgotten-export) The symbol "WatchFragmentOptions" needs to be exported by the entry point index.d.ts // Warning: (ae-forgotten-export) The symbol "WatchFragmentResult" needs to be exported by the entry point index.d.ts - // - // (undocumented) watchFragment(options: WatchFragmentOptions): Observable>; // Warning: (ae-forgotten-export) The symbol "Reference" needs to be exported by the entry point index.d.ts // @@ -96,14 +94,10 @@ abstract class ApolloCache implements DataProxy { writeQuery({ id, data, ...options }: Cache_2.WriteQueryOptions): Reference | undefined; } -// Warning: (ae-unresolved-link) The @link reference could not be resolved: The package "@apollo/client" does not have an export "ApolloLink" -// Warning: (ae-unresolved-link) The @link reference could not be resolved: The package "@apollo/client" does not have an export "Observable" -// // @public class ApolloClient implements DataProxy { // (undocumented) __actionHookForDevTools(cb: () => any): void; - // Warning: (ae-unresolved-link) The @link reference could not be resolved: The package "@apollo/client" does not have an export "ApolloClient" constructor(options: ApolloClientOptions); // Warning: (ae-forgotten-export) The symbol "GraphQLRequest" needs to be exported by the entry point index.d.ts // @@ -141,7 +135,6 @@ class ApolloClient implements DataProxy { onResetStore(cb: () => Promise): () => void; // Warning: (ae-forgotten-export) The symbol "QueryOptions" needs to be exported by the entry point index.d.ts // Warning: (ae-forgotten-export) The symbol "ApolloQueryResult" needs to be exported by the entry point index.d.ts - // Warning: (ae-unresolved-link) The @link reference could not be resolved: The package "@apollo/client" does not have an export "QueryOptions" query(options: QueryOptions): Promise>; // (undocumented) queryDeduplication: boolean; @@ -159,7 +152,6 @@ class ApolloClient implements DataProxy { setResolvers(resolvers: Resolvers | Resolvers[]): void; stop(): void; // Warning: (ae-forgotten-export) The symbol "SubscriptionOptions" needs to be exported by the entry point index.d.ts - // Warning: (ae-unresolved-link) The @link reference could not be resolved: The package "@apollo/client" does not have an export "Observable" subscribe(options: SubscriptionOptions): Observable>; // Warning: (ae-forgotten-export) The symbol "ApolloClientOptions" needs to be exported by the entry point index.d.ts // @@ -167,14 +159,9 @@ class ApolloClient implements DataProxy { readonly typeDefs: ApolloClientOptions["typeDefs"]; // (undocumented) version: string; - // Warning: (ae-unresolved-link) The @link reference could not be resolved: The package "@apollo/client" does not have an export "Observable" - // Warning: (ae-unresolved-link) The @link reference could not be resolved: The package "@apollo/client" does not have an export "Observable" - // Warning: (ae-unresolved-link) The @link reference could not be resolved: The package "@apollo/client" does not have an export "WatchFragmentOptions" watchFragment(options: WatchFragmentOptions): Observable>; // Warning: (ae-forgotten-export) The symbol "WatchQueryOptions" needs to be exported by the entry point index.d.ts // Warning: (ae-forgotten-export) The symbol "ObservableQuery" needs to be exported by the entry point index.d.ts - // Warning: (ae-unresolved-link) The @link reference could not be resolved: The package "@apollo/client" does not have an export "ObservableQuery" - // Warning: (ae-unresolved-link) The @link reference could not be resolved: The package "@apollo/client" does not have an export "ObservableQuery" watchQuery(options: WatchQueryOptions): ObservableQuery; writeFragment(options: DataProxy.WriteFragmentOptions): Reference | undefined; writeQuery(options: DataProxy.WriteQueryOptions): Reference | undefined; @@ -195,7 +182,6 @@ interface ApolloClientOptions { // (undocumented) fragmentMatcher?: FragmentMatcher; headers?: Record; - // Warning: (ae-unresolved-link) The @link reference could not be resolved: The package "@apollo/client" does not have an export "ApolloLink" link?: ApolloLink; name?: string; queryDeduplication?: boolean; diff --git a/.api-reports/api-report-react_components.md b/.api-reports/api-report-react_components.md index 04605103ccc..09b48e892e5 100644 --- a/.api-reports/api-report-react_components.md +++ b/.api-reports/api-report-react_components.md @@ -83,8 +83,6 @@ abstract class ApolloCache implements DataProxy { // Warning: (ae-forgotten-export) The symbol "OperationVariables" needs to be exported by the entry point index.d.ts // Warning: (ae-forgotten-export) The symbol "WatchFragmentOptions" needs to be exported by the entry point index.d.ts // Warning: (ae-forgotten-export) The symbol "WatchFragmentResult" needs to be exported by the entry point index.d.ts - // - // (undocumented) watchFragment(options: WatchFragmentOptions): Observable>; // Warning: (ae-forgotten-export) The symbol "Reference" needs to be exported by the entry point index.d.ts // @@ -96,14 +94,10 @@ abstract class ApolloCache implements DataProxy { writeQuery({ id, data, ...options }: Cache_2.WriteQueryOptions): Reference | undefined; } -// Warning: (ae-unresolved-link) The @link reference could not be resolved: The package "@apollo/client" does not have an export "ApolloLink" -// Warning: (ae-unresolved-link) The @link reference could not be resolved: The package "@apollo/client" does not have an export "Observable" -// // @public class ApolloClient implements DataProxy { // (undocumented) __actionHookForDevTools(cb: () => any): void; - // Warning: (ae-unresolved-link) The @link reference could not be resolved: The package "@apollo/client" does not have an export "ApolloClient" constructor(options: ApolloClientOptions); // Warning: (ae-forgotten-export) The symbol "GraphQLRequest" needs to be exported by the entry point index.d.ts // @@ -142,7 +136,6 @@ class ApolloClient implements DataProxy { onResetStore(cb: () => Promise): () => void; // Warning: (ae-forgotten-export) The symbol "QueryOptions" needs to be exported by the entry point index.d.ts // Warning: (ae-forgotten-export) The symbol "ApolloQueryResult" needs to be exported by the entry point index.d.ts - // Warning: (ae-unresolved-link) The @link reference could not be resolved: The package "@apollo/client" does not have an export "QueryOptions" query(options: QueryOptions): Promise>; // (undocumented) queryDeduplication: boolean; @@ -160,7 +153,6 @@ class ApolloClient implements DataProxy { setResolvers(resolvers: Resolvers | Resolvers[]): void; stop(): void; // Warning: (ae-forgotten-export) The symbol "SubscriptionOptions" needs to be exported by the entry point index.d.ts - // Warning: (ae-unresolved-link) The @link reference could not be resolved: The package "@apollo/client" does not have an export "Observable" subscribe(options: SubscriptionOptions): Observable>; // Warning: (ae-forgotten-export) The symbol "ApolloClientOptions" needs to be exported by the entry point index.d.ts // @@ -168,14 +160,9 @@ class ApolloClient implements DataProxy { readonly typeDefs: ApolloClientOptions["typeDefs"]; // (undocumented) version: string; - // Warning: (ae-unresolved-link) The @link reference could not be resolved: The package "@apollo/client" does not have an export "Observable" - // Warning: (ae-unresolved-link) The @link reference could not be resolved: The package "@apollo/client" does not have an export "Observable" - // Warning: (ae-unresolved-link) The @link reference could not be resolved: The package "@apollo/client" does not have an export "WatchFragmentOptions" watchFragment(options: WatchFragmentOptions): Observable>; // Warning: (ae-forgotten-export) The symbol "WatchQueryOptions" needs to be exported by the entry point index.d.ts // Warning: (ae-forgotten-export) The symbol "ObservableQuery" needs to be exported by the entry point index.d.ts - // Warning: (ae-unresolved-link) The @link reference could not be resolved: The package "@apollo/client" does not have an export "ObservableQuery" - // Warning: (ae-unresolved-link) The @link reference could not be resolved: The package "@apollo/client" does not have an export "ObservableQuery" watchQuery(options: WatchQueryOptions): ObservableQuery; writeFragment(options: DataProxy.WriteFragmentOptions): Reference | undefined; writeQuery(options: DataProxy.WriteQueryOptions): Reference | undefined; @@ -196,7 +183,6 @@ interface ApolloClientOptions { // (undocumented) fragmentMatcher?: FragmentMatcher; headers?: Record; - // Warning: (ae-unresolved-link) The @link reference could not be resolved: The package "@apollo/client" does not have an export "ApolloLink" link?: ApolloLink; name?: string; queryDeduplication?: boolean; diff --git a/.api-reports/api-report-react_context.md b/.api-reports/api-report-react_context.md index 9a0ba096caf..f78d34ea62b 100644 --- a/.api-reports/api-report-react_context.md +++ b/.api-reports/api-report-react_context.md @@ -82,8 +82,6 @@ abstract class ApolloCache implements DataProxy { // Warning: (ae-forgotten-export) The symbol "OperationVariables" needs to be exported by the entry point index.d.ts // Warning: (ae-forgotten-export) The symbol "WatchFragmentOptions" needs to be exported by the entry point index.d.ts // Warning: (ae-forgotten-export) The symbol "WatchFragmentResult" needs to be exported by the entry point index.d.ts - // - // (undocumented) watchFragment(options: WatchFragmentOptions): Observable>; // Warning: (ae-forgotten-export) The symbol "Reference" needs to be exported by the entry point index.d.ts // @@ -95,14 +93,10 @@ abstract class ApolloCache implements DataProxy { writeQuery({ id, data, ...options }: Cache_2.WriteQueryOptions): Reference | undefined; } -// Warning: (ae-unresolved-link) The @link reference could not be resolved: The package "@apollo/client" does not have an export "ApolloLink" -// Warning: (ae-unresolved-link) The @link reference could not be resolved: The package "@apollo/client" does not have an export "Observable" -// // @public class ApolloClient implements DataProxy { // (undocumented) __actionHookForDevTools(cb: () => any): void; - // Warning: (ae-unresolved-link) The @link reference could not be resolved: The package "@apollo/client" does not have an export "ApolloClient" constructor(options: ApolloClientOptions); // Warning: (ae-forgotten-export) The symbol "GraphQLRequest" needs to be exported by the entry point index.d.ts // @@ -141,7 +135,6 @@ class ApolloClient implements DataProxy { onResetStore(cb: () => Promise): () => void; // Warning: (ae-forgotten-export) The symbol "QueryOptions" needs to be exported by the entry point index.d.ts // Warning: (ae-forgotten-export) The symbol "ApolloQueryResult" needs to be exported by the entry point index.d.ts - // Warning: (ae-unresolved-link) The @link reference could not be resolved: The package "@apollo/client" does not have an export "QueryOptions" query(options: QueryOptions): Promise>; // (undocumented) queryDeduplication: boolean; @@ -159,7 +152,6 @@ class ApolloClient implements DataProxy { setResolvers(resolvers: Resolvers | Resolvers[]): void; stop(): void; // Warning: (ae-forgotten-export) The symbol "SubscriptionOptions" needs to be exported by the entry point index.d.ts - // Warning: (ae-unresolved-link) The @link reference could not be resolved: The package "@apollo/client" does not have an export "Observable" subscribe(options: SubscriptionOptions): Observable>; // Warning: (ae-forgotten-export) The symbol "ApolloClientOptions" needs to be exported by the entry point index.d.ts // @@ -167,14 +159,9 @@ class ApolloClient implements DataProxy { readonly typeDefs: ApolloClientOptions["typeDefs"]; // (undocumented) version: string; - // Warning: (ae-unresolved-link) The @link reference could not be resolved: The package "@apollo/client" does not have an export "Observable" - // Warning: (ae-unresolved-link) The @link reference could not be resolved: The package "@apollo/client" does not have an export "Observable" - // Warning: (ae-unresolved-link) The @link reference could not be resolved: The package "@apollo/client" does not have an export "WatchFragmentOptions" watchFragment(options: WatchFragmentOptions): Observable>; // Warning: (ae-forgotten-export) The symbol "WatchQueryOptions" needs to be exported by the entry point index.d.ts // Warning: (ae-forgotten-export) The symbol "ObservableQuery" needs to be exported by the entry point index.d.ts - // Warning: (ae-unresolved-link) The @link reference could not be resolved: The package "@apollo/client" does not have an export "ObservableQuery" - // Warning: (ae-unresolved-link) The @link reference could not be resolved: The package "@apollo/client" does not have an export "ObservableQuery" watchQuery(options: WatchQueryOptions): ObservableQuery; writeFragment(options: DataProxy.WriteFragmentOptions): Reference | undefined; writeQuery(options: DataProxy.WriteQueryOptions): Reference | undefined; @@ -195,7 +182,6 @@ interface ApolloClientOptions { // (undocumented) fragmentMatcher?: FragmentMatcher; headers?: Record; - // Warning: (ae-unresolved-link) The @link reference could not be resolved: The package "@apollo/client" does not have an export "ApolloLink" link?: ApolloLink; name?: string; queryDeduplication?: boolean; diff --git a/.api-reports/api-report-react_hoc.md b/.api-reports/api-report-react_hoc.md index 95b584052f0..a1deecfc145 100644 --- a/.api-reports/api-report-react_hoc.md +++ b/.api-reports/api-report-react_hoc.md @@ -82,8 +82,6 @@ abstract class ApolloCache implements DataProxy { // Warning: (ae-forgotten-export) The symbol "OperationVariables" needs to be exported by the entry point index.d.ts // Warning: (ae-forgotten-export) The symbol "WatchFragmentOptions" needs to be exported by the entry point index.d.ts // Warning: (ae-forgotten-export) The symbol "WatchFragmentResult" needs to be exported by the entry point index.d.ts - // - // (undocumented) watchFragment(options: WatchFragmentOptions): Observable>; // Warning: (ae-forgotten-export) The symbol "Reference" needs to be exported by the entry point index.d.ts // @@ -95,14 +93,10 @@ abstract class ApolloCache implements DataProxy { writeQuery({ id, data, ...options }: Cache_2.WriteQueryOptions): Reference | undefined; } -// Warning: (ae-unresolved-link) The @link reference could not be resolved: The package "@apollo/client" does not have an export "ApolloLink" -// Warning: (ae-unresolved-link) The @link reference could not be resolved: The package "@apollo/client" does not have an export "Observable" -// // @public class ApolloClient implements DataProxy { // (undocumented) __actionHookForDevTools(cb: () => any): void; - // Warning: (ae-unresolved-link) The @link reference could not be resolved: The package "@apollo/client" does not have an export "ApolloClient" constructor(options: ApolloClientOptions); // Warning: (ae-forgotten-export) The symbol "GraphQLRequest" needs to be exported by the entry point index.d.ts // @@ -141,7 +135,6 @@ class ApolloClient implements DataProxy { onResetStore(cb: () => Promise): () => void; // Warning: (ae-forgotten-export) The symbol "QueryOptions" needs to be exported by the entry point index.d.ts // Warning: (ae-forgotten-export) The symbol "ApolloQueryResult" needs to be exported by the entry point index.d.ts - // Warning: (ae-unresolved-link) The @link reference could not be resolved: The package "@apollo/client" does not have an export "QueryOptions" query(options: QueryOptions): Promise>; // (undocumented) queryDeduplication: boolean; @@ -159,7 +152,6 @@ class ApolloClient implements DataProxy { setResolvers(resolvers: Resolvers | Resolvers[]): void; stop(): void; // Warning: (ae-forgotten-export) The symbol "SubscriptionOptions" needs to be exported by the entry point index.d.ts - // Warning: (ae-unresolved-link) The @link reference could not be resolved: The package "@apollo/client" does not have an export "Observable" subscribe(options: SubscriptionOptions): Observable>; // Warning: (ae-forgotten-export) The symbol "ApolloClientOptions" needs to be exported by the entry point index.d.ts // @@ -167,14 +159,9 @@ class ApolloClient implements DataProxy { readonly typeDefs: ApolloClientOptions["typeDefs"]; // (undocumented) version: string; - // Warning: (ae-unresolved-link) The @link reference could not be resolved: The package "@apollo/client" does not have an export "Observable" - // Warning: (ae-unresolved-link) The @link reference could not be resolved: The package "@apollo/client" does not have an export "Observable" - // Warning: (ae-unresolved-link) The @link reference could not be resolved: The package "@apollo/client" does not have an export "WatchFragmentOptions" watchFragment(options: WatchFragmentOptions): Observable>; // Warning: (ae-forgotten-export) The symbol "WatchQueryOptions" needs to be exported by the entry point index.d.ts // Warning: (ae-forgotten-export) The symbol "ObservableQuery" needs to be exported by the entry point index.d.ts - // Warning: (ae-unresolved-link) The @link reference could not be resolved: The package "@apollo/client" does not have an export "ObservableQuery" - // Warning: (ae-unresolved-link) The @link reference could not be resolved: The package "@apollo/client" does not have an export "ObservableQuery" watchQuery(options: WatchQueryOptions): ObservableQuery; writeFragment(options: DataProxy.WriteFragmentOptions): Reference | undefined; writeQuery(options: DataProxy.WriteQueryOptions): Reference | undefined; @@ -195,7 +182,6 @@ interface ApolloClientOptions { // (undocumented) fragmentMatcher?: FragmentMatcher; headers?: Record; - // Warning: (ae-unresolved-link) The @link reference could not be resolved: The package "@apollo/client" does not have an export "ApolloLink" link?: ApolloLink; name?: string; queryDeduplication?: boolean; diff --git a/.api-reports/api-report-react_hooks.md b/.api-reports/api-report-react_hooks.md index 05aa2224c13..53d506d45eb 100644 --- a/.api-reports/api-report-react_hooks.md +++ b/.api-reports/api-report-react_hooks.md @@ -81,8 +81,6 @@ abstract class ApolloCache implements DataProxy { // Warning: (ae-forgotten-export) The symbol "OperationVariables" needs to be exported by the entry point index.d.ts // Warning: (ae-forgotten-export) The symbol "WatchFragmentOptions" needs to be exported by the entry point index.d.ts // Warning: (ae-forgotten-export) The symbol "WatchFragmentResult" needs to be exported by the entry point index.d.ts - // - // (undocumented) watchFragment(options: WatchFragmentOptions): Observable>; // Warning: (ae-forgotten-export) The symbol "Reference" needs to be exported by the entry point index.d.ts // @@ -94,14 +92,10 @@ abstract class ApolloCache implements DataProxy { writeQuery({ id, data, ...options }: Cache_2.WriteQueryOptions): Reference | undefined; } -// Warning: (ae-unresolved-link) The @link reference could not be resolved: The package "@apollo/client" does not have an export "ApolloLink" -// Warning: (ae-unresolved-link) The @link reference could not be resolved: The package "@apollo/client" does not have an export "Observable" -// // @public class ApolloClient implements DataProxy { // (undocumented) __actionHookForDevTools(cb: () => any): void; - // Warning: (ae-unresolved-link) The @link reference could not be resolved: The package "@apollo/client" does not have an export "ApolloClient" constructor(options: ApolloClientOptions); // Warning: (ae-forgotten-export) The symbol "GraphQLRequest" needs to be exported by the entry point index.d.ts // @@ -140,7 +134,6 @@ class ApolloClient implements DataProxy { onResetStore(cb: () => Promise): () => void; // Warning: (ae-forgotten-export) The symbol "QueryOptions" needs to be exported by the entry point index.d.ts // Warning: (ae-forgotten-export) The symbol "ApolloQueryResult" needs to be exported by the entry point index.d.ts - // Warning: (ae-unresolved-link) The @link reference could not be resolved: The package "@apollo/client" does not have an export "QueryOptions" query(options: QueryOptions): Promise>; // (undocumented) queryDeduplication: boolean; @@ -158,7 +151,6 @@ class ApolloClient implements DataProxy { setResolvers(resolvers: Resolvers | Resolvers[]): void; stop(): void; // Warning: (ae-forgotten-export) The symbol "SubscriptionOptions" needs to be exported by the entry point index.d.ts - // Warning: (ae-unresolved-link) The @link reference could not be resolved: The package "@apollo/client" does not have an export "Observable" subscribe(options: SubscriptionOptions): Observable>; // Warning: (ae-forgotten-export) The symbol "ApolloClientOptions" needs to be exported by the entry point index.d.ts // @@ -166,14 +158,9 @@ class ApolloClient implements DataProxy { readonly typeDefs: ApolloClientOptions["typeDefs"]; // (undocumented) version: string; - // Warning: (ae-unresolved-link) The @link reference could not be resolved: The package "@apollo/client" does not have an export "Observable" - // Warning: (ae-unresolved-link) The @link reference could not be resolved: The package "@apollo/client" does not have an export "Observable" - // Warning: (ae-unresolved-link) The @link reference could not be resolved: The package "@apollo/client" does not have an export "WatchFragmentOptions" watchFragment(options: WatchFragmentOptions): Observable>; // Warning: (ae-forgotten-export) The symbol "WatchQueryOptions" needs to be exported by the entry point index.d.ts // Warning: (ae-forgotten-export) The symbol "ObservableQuery" needs to be exported by the entry point index.d.ts - // Warning: (ae-unresolved-link) The @link reference could not be resolved: The package "@apollo/client" does not have an export "ObservableQuery" - // Warning: (ae-unresolved-link) The @link reference could not be resolved: The package "@apollo/client" does not have an export "ObservableQuery" watchQuery(options: WatchQueryOptions): ObservableQuery; writeFragment(options: DataProxy.WriteFragmentOptions): Reference | undefined; writeQuery(options: DataProxy.WriteQueryOptions): Reference | undefined; @@ -194,7 +181,6 @@ interface ApolloClientOptions { // (undocumented) fragmentMatcher?: FragmentMatcher; headers?: Record; - // Warning: (ae-unresolved-link) The @link reference could not be resolved: The package "@apollo/client" does not have an export "ApolloLink" link?: ApolloLink; name?: string; queryDeduplication?: boolean; diff --git a/.api-reports/api-report-react_internal.md b/.api-reports/api-report-react_internal.md index ba8370d5371..230fbe77d7b 100644 --- a/.api-reports/api-report-react_internal.md +++ b/.api-reports/api-report-react_internal.md @@ -81,8 +81,6 @@ abstract class ApolloCache implements DataProxy { // Warning: (ae-forgotten-export) The symbol "OperationVariables" needs to be exported by the entry point index.d.ts // Warning: (ae-forgotten-export) The symbol "WatchFragmentOptions" needs to be exported by the entry point index.d.ts // Warning: (ae-forgotten-export) The symbol "WatchFragmentResult" needs to be exported by the entry point index.d.ts - // - // (undocumented) watchFragment(options: WatchFragmentOptions): Observable>; // Warning: (ae-forgotten-export) The symbol "Reference" needs to be exported by the entry point index.d.ts // @@ -94,14 +92,10 @@ abstract class ApolloCache implements DataProxy { writeQuery({ id, data, ...options }: Cache_2.WriteQueryOptions): Reference | undefined; } -// Warning: (ae-unresolved-link) The @link reference could not be resolved: The package "@apollo/client" does not have an export "ApolloLink" -// Warning: (ae-unresolved-link) The @link reference could not be resolved: The package "@apollo/client" does not have an export "Observable" -// // @public class ApolloClient implements DataProxy { // (undocumented) __actionHookForDevTools(cb: () => any): void; - // Warning: (ae-unresolved-link) The @link reference could not be resolved: The package "@apollo/client" does not have an export "ApolloClient" constructor(options: ApolloClientOptions); // Warning: (ae-forgotten-export) The symbol "GraphQLRequest" needs to be exported by the entry point index.d.ts // @@ -140,7 +134,6 @@ class ApolloClient implements DataProxy { onResetStore(cb: () => Promise): () => void; // Warning: (ae-forgotten-export) The symbol "QueryOptions" needs to be exported by the entry point index.d.ts // Warning: (ae-forgotten-export) The symbol "ApolloQueryResult" needs to be exported by the entry point index.d.ts - // Warning: (ae-unresolved-link) The @link reference could not be resolved: The package "@apollo/client" does not have an export "QueryOptions" query(options: QueryOptions): Promise>; // (undocumented) queryDeduplication: boolean; @@ -158,7 +151,6 @@ class ApolloClient implements DataProxy { setResolvers(resolvers: Resolvers | Resolvers[]): void; stop(): void; // Warning: (ae-forgotten-export) The symbol "SubscriptionOptions" needs to be exported by the entry point index.d.ts - // Warning: (ae-unresolved-link) The @link reference could not be resolved: The package "@apollo/client" does not have an export "Observable" subscribe(options: SubscriptionOptions): Observable>; // Warning: (ae-forgotten-export) The symbol "ApolloClientOptions" needs to be exported by the entry point index.d.ts // @@ -166,14 +158,9 @@ class ApolloClient implements DataProxy { readonly typeDefs: ApolloClientOptions["typeDefs"]; // (undocumented) version: string; - // Warning: (ae-unresolved-link) The @link reference could not be resolved: The package "@apollo/client" does not have an export "Observable" - // Warning: (ae-unresolved-link) The @link reference could not be resolved: The package "@apollo/client" does not have an export "Observable" - // Warning: (ae-unresolved-link) The @link reference could not be resolved: The package "@apollo/client" does not have an export "WatchFragmentOptions" watchFragment(options: WatchFragmentOptions): Observable>; // Warning: (ae-forgotten-export) The symbol "WatchQueryOptions" needs to be exported by the entry point index.d.ts // Warning: (ae-forgotten-export) The symbol "ObservableQuery" needs to be exported by the entry point index.d.ts - // Warning: (ae-unresolved-link) The @link reference could not be resolved: The package "@apollo/client" does not have an export "ObservableQuery" - // Warning: (ae-unresolved-link) The @link reference could not be resolved: The package "@apollo/client" does not have an export "ObservableQuery" watchQuery(options: WatchQueryOptions): ObservableQuery; writeFragment(options: DataProxy.WriteFragmentOptions): Reference | undefined; writeQuery(options: DataProxy.WriteQueryOptions): Reference | undefined; @@ -194,7 +181,6 @@ interface ApolloClientOptions { // (undocumented) fragmentMatcher?: FragmentMatcher; headers?: Record; - // Warning: (ae-unresolved-link) The @link reference could not be resolved: The package "@apollo/client" does not have an export "ApolloLink" link?: ApolloLink; name?: string; queryDeduplication?: boolean; diff --git a/.api-reports/api-report-react_ssr.md b/.api-reports/api-report-react_ssr.md index 26da1d70ac7..94a8258be2b 100644 --- a/.api-reports/api-report-react_ssr.md +++ b/.api-reports/api-report-react_ssr.md @@ -82,8 +82,6 @@ abstract class ApolloCache implements DataProxy { // Warning: (ae-forgotten-export) The symbol "OperationVariables" needs to be exported by the entry point index.d.ts // Warning: (ae-forgotten-export) The symbol "WatchFragmentOptions" needs to be exported by the entry point index.d.ts // Warning: (ae-forgotten-export) The symbol "WatchFragmentResult" needs to be exported by the entry point index.d.ts - // - // (undocumented) watchFragment(options: WatchFragmentOptions): Observable>; // Warning: (ae-forgotten-export) The symbol "Reference" needs to be exported by the entry point index.d.ts // @@ -95,14 +93,10 @@ abstract class ApolloCache implements DataProxy { writeQuery({ id, data, ...options }: Cache_2.WriteQueryOptions): Reference | undefined; } -// Warning: (ae-unresolved-link) The @link reference could not be resolved: The package "@apollo/client" does not have an export "ApolloLink" -// Warning: (ae-unresolved-link) The @link reference could not be resolved: The package "@apollo/client" does not have an export "Observable" -// // @public class ApolloClient implements DataProxy { // (undocumented) __actionHookForDevTools(cb: () => any): void; - // Warning: (ae-unresolved-link) The @link reference could not be resolved: The package "@apollo/client" does not have an export "ApolloClient" constructor(options: ApolloClientOptions); // Warning: (ae-forgotten-export) The symbol "GraphQLRequest" needs to be exported by the entry point index.d.ts // @@ -141,7 +135,6 @@ class ApolloClient implements DataProxy { onResetStore(cb: () => Promise): () => void; // Warning: (ae-forgotten-export) The symbol "QueryOptions" needs to be exported by the entry point index.d.ts // Warning: (ae-forgotten-export) The symbol "ApolloQueryResult" needs to be exported by the entry point index.d.ts - // Warning: (ae-unresolved-link) The @link reference could not be resolved: The package "@apollo/client" does not have an export "QueryOptions" query(options: QueryOptions): Promise>; // (undocumented) queryDeduplication: boolean; @@ -159,7 +152,6 @@ class ApolloClient implements DataProxy { setResolvers(resolvers: Resolvers | Resolvers[]): void; stop(): void; // Warning: (ae-forgotten-export) The symbol "SubscriptionOptions" needs to be exported by the entry point index.d.ts - // Warning: (ae-unresolved-link) The @link reference could not be resolved: The package "@apollo/client" does not have an export "Observable" subscribe(options: SubscriptionOptions): Observable>; // Warning: (ae-forgotten-export) The symbol "ApolloClientOptions" needs to be exported by the entry point index.d.ts // @@ -167,14 +159,9 @@ class ApolloClient implements DataProxy { readonly typeDefs: ApolloClientOptions["typeDefs"]; // (undocumented) version: string; - // Warning: (ae-unresolved-link) The @link reference could not be resolved: The package "@apollo/client" does not have an export "Observable" - // Warning: (ae-unresolved-link) The @link reference could not be resolved: The package "@apollo/client" does not have an export "Observable" - // Warning: (ae-unresolved-link) The @link reference could not be resolved: The package "@apollo/client" does not have an export "WatchFragmentOptions" watchFragment(options: WatchFragmentOptions): Observable>; // Warning: (ae-forgotten-export) The symbol "WatchQueryOptions" needs to be exported by the entry point index.d.ts // Warning: (ae-forgotten-export) The symbol "ObservableQuery" needs to be exported by the entry point index.d.ts - // Warning: (ae-unresolved-link) The @link reference could not be resolved: The package "@apollo/client" does not have an export "ObservableQuery" - // Warning: (ae-unresolved-link) The @link reference could not be resolved: The package "@apollo/client" does not have an export "ObservableQuery" watchQuery(options: WatchQueryOptions): ObservableQuery; writeFragment(options: DataProxy.WriteFragmentOptions): Reference | undefined; writeQuery(options: DataProxy.WriteQueryOptions): Reference | undefined; @@ -195,7 +182,6 @@ interface ApolloClientOptions { // (undocumented) fragmentMatcher?: FragmentMatcher; headers?: Record; - // Warning: (ae-unresolved-link) The @link reference could not be resolved: The package "@apollo/client" does not have an export "ApolloLink" link?: ApolloLink; name?: string; queryDeduplication?: boolean; diff --git a/.api-reports/api-report-testing.md b/.api-reports/api-report-testing.md index b185b0a9081..cab4b3a9e8c 100644 --- a/.api-reports/api-report-testing.md +++ b/.api-reports/api-report-testing.md @@ -82,8 +82,6 @@ abstract class ApolloCache implements DataProxy { // Warning: (ae-forgotten-export) The symbol "OperationVariables" needs to be exported by the entry point index.d.ts // Warning: (ae-forgotten-export) The symbol "WatchFragmentOptions" needs to be exported by the entry point index.d.ts // Warning: (ae-forgotten-export) The symbol "WatchFragmentResult" needs to be exported by the entry point index.d.ts - // - // (undocumented) watchFragment(options: WatchFragmentOptions): Observable>; // Warning: (ae-forgotten-export) The symbol "Reference" needs to be exported by the entry point index.d.ts // @@ -95,14 +93,10 @@ abstract class ApolloCache implements DataProxy { writeQuery({ id, data, ...options }: Cache_2.WriteQueryOptions): Reference | undefined; } -// Warning: (ae-unresolved-link) The @link reference could not be resolved: The package "@apollo/client" does not have an export "ApolloLink" -// Warning: (ae-unresolved-link) The @link reference could not be resolved: The package "@apollo/client" does not have an export "Observable" -// // @public class ApolloClient implements DataProxy { // (undocumented) __actionHookForDevTools(cb: () => any): void; - // Warning: (ae-unresolved-link) The @link reference could not be resolved: The package "@apollo/client" does not have an export "ApolloClient" constructor(options: ApolloClientOptions); // Warning: (ae-forgotten-export) The symbol "GraphQLRequest" needs to be exported by the entry point index.d.ts // @@ -141,7 +135,6 @@ class ApolloClient implements DataProxy { onResetStore(cb: () => Promise): () => void; // Warning: (ae-forgotten-export) The symbol "QueryOptions" needs to be exported by the entry point index.d.ts // Warning: (ae-forgotten-export) The symbol "ApolloQueryResult" needs to be exported by the entry point index.d.ts - // Warning: (ae-unresolved-link) The @link reference could not be resolved: The package "@apollo/client" does not have an export "QueryOptions" query(options: QueryOptions): Promise>; // (undocumented) queryDeduplication: boolean; @@ -159,7 +152,6 @@ class ApolloClient implements DataProxy { setResolvers(resolvers: Resolvers | Resolvers[]): void; stop(): void; // Warning: (ae-forgotten-export) The symbol "SubscriptionOptions" needs to be exported by the entry point index.d.ts - // Warning: (ae-unresolved-link) The @link reference could not be resolved: The package "@apollo/client" does not have an export "Observable" subscribe(options: SubscriptionOptions): Observable>; // Warning: (ae-forgotten-export) The symbol "ApolloClientOptions" needs to be exported by the entry point index.d.ts // @@ -167,14 +159,9 @@ class ApolloClient implements DataProxy { readonly typeDefs: ApolloClientOptions["typeDefs"]; // (undocumented) version: string; - // Warning: (ae-unresolved-link) The @link reference could not be resolved: The package "@apollo/client" does not have an export "Observable" - // Warning: (ae-unresolved-link) The @link reference could not be resolved: The package "@apollo/client" does not have an export "Observable" - // Warning: (ae-unresolved-link) The @link reference could not be resolved: The package "@apollo/client" does not have an export "WatchFragmentOptions" watchFragment(options: WatchFragmentOptions): Observable>; // Warning: (ae-forgotten-export) The symbol "WatchQueryOptions" needs to be exported by the entry point index.d.ts // Warning: (ae-forgotten-export) The symbol "ObservableQuery" needs to be exported by the entry point index.d.ts - // Warning: (ae-unresolved-link) The @link reference could not be resolved: The package "@apollo/client" does not have an export "ObservableQuery" - // Warning: (ae-unresolved-link) The @link reference could not be resolved: The package "@apollo/client" does not have an export "ObservableQuery" watchQuery(options: WatchQueryOptions): ObservableQuery; writeFragment(options: DataProxy.WriteFragmentOptions): Reference | undefined; writeQuery(options: DataProxy.WriteQueryOptions): Reference | undefined; @@ -195,7 +182,6 @@ interface ApolloClientOptions { // (undocumented) fragmentMatcher?: FragmentMatcher; headers?: Record; - // Warning: (ae-unresolved-link) The @link reference could not be resolved: The package "@apollo/client" does not have an export "ApolloLink" link?: ApolloLink; name?: string; queryDeduplication?: boolean; diff --git a/.api-reports/api-report-testing_core.md b/.api-reports/api-report-testing_core.md index aca90c131c6..94a2174bc34 100644 --- a/.api-reports/api-report-testing_core.md +++ b/.api-reports/api-report-testing_core.md @@ -81,8 +81,6 @@ abstract class ApolloCache implements DataProxy { // Warning: (ae-forgotten-export) The symbol "OperationVariables" needs to be exported by the entry point index.d.ts // Warning: (ae-forgotten-export) The symbol "WatchFragmentOptions" needs to be exported by the entry point index.d.ts // Warning: (ae-forgotten-export) The symbol "WatchFragmentResult" needs to be exported by the entry point index.d.ts - // - // (undocumented) watchFragment(options: WatchFragmentOptions): Observable>; // Warning: (ae-forgotten-export) The symbol "Reference" needs to be exported by the entry point index.d.ts // @@ -94,14 +92,10 @@ abstract class ApolloCache implements DataProxy { writeQuery({ id, data, ...options }: Cache_2.WriteQueryOptions): Reference | undefined; } -// Warning: (ae-unresolved-link) The @link reference could not be resolved: The package "@apollo/client" does not have an export "ApolloLink" -// Warning: (ae-unresolved-link) The @link reference could not be resolved: The package "@apollo/client" does not have an export "Observable" -// // @public class ApolloClient implements DataProxy { // (undocumented) __actionHookForDevTools(cb: () => any): void; - // Warning: (ae-unresolved-link) The @link reference could not be resolved: The package "@apollo/client" does not have an export "ApolloClient" constructor(options: ApolloClientOptions); // Warning: (ae-forgotten-export) The symbol "GraphQLRequest" needs to be exported by the entry point index.d.ts // @@ -140,7 +134,6 @@ class ApolloClient implements DataProxy { onResetStore(cb: () => Promise): () => void; // Warning: (ae-forgotten-export) The symbol "QueryOptions" needs to be exported by the entry point index.d.ts // Warning: (ae-forgotten-export) The symbol "ApolloQueryResult" needs to be exported by the entry point index.d.ts - // Warning: (ae-unresolved-link) The @link reference could not be resolved: The package "@apollo/client" does not have an export "QueryOptions" query(options: QueryOptions): Promise>; // (undocumented) queryDeduplication: boolean; @@ -158,7 +151,6 @@ class ApolloClient implements DataProxy { setResolvers(resolvers: Resolvers | Resolvers[]): void; stop(): void; // Warning: (ae-forgotten-export) The symbol "SubscriptionOptions" needs to be exported by the entry point index.d.ts - // Warning: (ae-unresolved-link) The @link reference could not be resolved: The package "@apollo/client" does not have an export "Observable" subscribe(options: SubscriptionOptions): Observable>; // Warning: (ae-forgotten-export) The symbol "ApolloClientOptions" needs to be exported by the entry point index.d.ts // @@ -166,14 +158,9 @@ class ApolloClient implements DataProxy { readonly typeDefs: ApolloClientOptions["typeDefs"]; // (undocumented) version: string; - // Warning: (ae-unresolved-link) The @link reference could not be resolved: The package "@apollo/client" does not have an export "Observable" - // Warning: (ae-unresolved-link) The @link reference could not be resolved: The package "@apollo/client" does not have an export "Observable" - // Warning: (ae-unresolved-link) The @link reference could not be resolved: The package "@apollo/client" does not have an export "WatchFragmentOptions" watchFragment(options: WatchFragmentOptions): Observable>; // Warning: (ae-forgotten-export) The symbol "WatchQueryOptions" needs to be exported by the entry point index.d.ts // Warning: (ae-forgotten-export) The symbol "ObservableQuery" needs to be exported by the entry point index.d.ts - // Warning: (ae-unresolved-link) The @link reference could not be resolved: The package "@apollo/client" does not have an export "ObservableQuery" - // Warning: (ae-unresolved-link) The @link reference could not be resolved: The package "@apollo/client" does not have an export "ObservableQuery" watchQuery(options: WatchQueryOptions): ObservableQuery; writeFragment(options: DataProxy.WriteFragmentOptions): Reference | undefined; writeQuery(options: DataProxy.WriteQueryOptions): Reference | undefined; @@ -194,7 +181,6 @@ interface ApolloClientOptions { // (undocumented) fragmentMatcher?: FragmentMatcher; headers?: Record; - // Warning: (ae-unresolved-link) The @link reference could not be resolved: The package "@apollo/client" does not have an export "ApolloLink" link?: ApolloLink; name?: string; queryDeduplication?: boolean; diff --git a/.api-reports/api-report-utilities.md b/.api-reports/api-report-utilities.md index 984843a9dcf..7be9a361b3a 100644 --- a/.api-reports/api-report-utilities.md +++ b/.api-reports/api-report-utilities.md @@ -97,8 +97,6 @@ abstract class ApolloCache implements DataProxy { // Warning: (ae-forgotten-export) The symbol "OperationVariables" needs to be exported by the entry point index.d.ts // Warning: (ae-forgotten-export) The symbol "WatchFragmentOptions" needs to be exported by the entry point index.d.ts // Warning: (ae-forgotten-export) The symbol "WatchFragmentResult" needs to be exported by the entry point index.d.ts - // - // (undocumented) watchFragment(options: WatchFragmentOptions): Observable>; // (undocumented) abstract write(write: Cache_2.WriteOptions): Reference | undefined; @@ -108,14 +106,10 @@ abstract class ApolloCache implements DataProxy { writeQuery({ id, data, ...options }: Cache_2.WriteQueryOptions): Reference | undefined; } -// Warning: (ae-unresolved-link) The @link reference could not be resolved: The package "@apollo/client" does not have an export "ApolloLink" -// Warning: (ae-unresolved-link) The @link reference could not be resolved: This type of declaration is not supported yet by the resolver -// // @public class ApolloClient implements DataProxy { // (undocumented) __actionHookForDevTools(cb: () => any): void; - // Warning: (ae-unresolved-link) The @link reference could not be resolved: The package "@apollo/client" does not have an export "ApolloClient" constructor(options: ApolloClientOptions); // Warning: (ae-forgotten-export) The symbol "GraphQLRequest" needs to be exported by the entry point index.d.ts // @@ -153,7 +147,6 @@ class ApolloClient implements DataProxy { onResetStore(cb: () => Promise): () => void; // Warning: (ae-forgotten-export) The symbol "QueryOptions" needs to be exported by the entry point index.d.ts // Warning: (ae-forgotten-export) The symbol "ApolloQueryResult" needs to be exported by the entry point index.d.ts - // Warning: (ae-unresolved-link) The @link reference could not be resolved: The package "@apollo/client" does not have an export "QueryOptions" query(options: QueryOptions): Promise>; // (undocumented) queryDeduplication: boolean; @@ -171,7 +164,6 @@ class ApolloClient implements DataProxy { setResolvers(resolvers: Resolvers | Resolvers[]): void; stop(): void; // Warning: (ae-forgotten-export) The symbol "SubscriptionOptions" needs to be exported by the entry point index.d.ts - // Warning: (ae-unresolved-link) The @link reference could not be resolved: This type of declaration is not supported yet by the resolver subscribe(options: SubscriptionOptions): Observable>; // Warning: (ae-forgotten-export) The symbol "ApolloClientOptions" needs to be exported by the entry point index.d.ts // @@ -179,14 +171,9 @@ class ApolloClient implements DataProxy { readonly typeDefs: ApolloClientOptions["typeDefs"]; // (undocumented) version: string; - // Warning: (ae-unresolved-link) The @link reference could not be resolved: This type of declaration is not supported yet by the resolver - // Warning: (ae-unresolved-link) The @link reference could not be resolved: This type of declaration is not supported yet by the resolver - // Warning: (ae-unresolved-link) The @link reference could not be resolved: The package "@apollo/client" does not have an export "WatchFragmentOptions" watchFragment(options: WatchFragmentOptions): Observable>; // Warning: (ae-forgotten-export) The symbol "WatchQueryOptions" needs to be exported by the entry point index.d.ts // Warning: (ae-forgotten-export) The symbol "ObservableQuery" needs to be exported by the entry point index.d.ts - // Warning: (ae-unresolved-link) The @link reference could not be resolved: The package "@apollo/client" does not have an export "ObservableQuery" - // Warning: (ae-unresolved-link) The @link reference could not be resolved: The package "@apollo/client" does not have an export "ObservableQuery" watchQuery(options: WatchQueryOptions): ObservableQuery; writeFragment(options: DataProxy.WriteFragmentOptions): Reference | undefined; writeQuery(options: DataProxy.WriteQueryOptions): Reference | undefined; @@ -207,7 +194,6 @@ interface ApolloClientOptions { // (undocumented) fragmentMatcher?: FragmentMatcher; headers?: Record; - // Warning: (ae-unresolved-link) The @link reference could not be resolved: The package "@apollo/client" does not have an export "ApolloLink" link?: ApolloLink; name?: string; queryDeduplication?: boolean; diff --git a/.api-reports/api-report.md b/.api-reports/api-report.md index 10370a4d61d..2948c358c8f 100644 --- a/.api-reports/api-report.md +++ b/.api-reports/api-report.md @@ -83,8 +83,6 @@ export abstract class ApolloCache implements DataProxy { abstract watch(watch: Cache_2.WatchOptions): () => void; // Warning: (ae-forgotten-export) The symbol "WatchFragmentOptions" needs to be exported by the entry point index.d.ts // Warning: (ae-forgotten-export) The symbol "WatchFragmentResult" needs to be exported by the entry point index.d.ts - // - // (undocumented) watchFragment(options: WatchFragmentOptions): Observable>; // (undocumented) abstract write(write: Cache_2.WriteOptions): Reference | undefined; @@ -94,8 +92,6 @@ export abstract class ApolloCache implements DataProxy { writeQuery({ id, data, ...options }: Cache_2.WriteQueryOptions): Reference | undefined; } -// Warning: (ae-unresolved-link) The @link reference could not be resolved: This type of declaration is not supported yet by the resolver -// // @public export class ApolloClient implements DataProxy { // (undocumented) @@ -137,15 +133,11 @@ export class ApolloClient implements DataProxy { setLocalStateFragmentMatcher(fragmentMatcher: FragmentMatcher): void; setResolvers(resolvers: Resolvers | Resolvers[]): void; stop(): void; - // Warning: (ae-unresolved-link) The @link reference could not be resolved: This type of declaration is not supported yet by the resolver subscribe(options: SubscriptionOptions): Observable>; // (undocumented) readonly typeDefs: ApolloClientOptions["typeDefs"]; // (undocumented) version: string; - // Warning: (ae-unresolved-link) The @link reference could not be resolved: This type of declaration is not supported yet by the resolver - // Warning: (ae-unresolved-link) The @link reference could not be resolved: This type of declaration is not supported yet by the resolver - // Warning: (ae-unresolved-link) The @link reference could not be resolved: The package "@apollo/client" does not have an export "WatchFragmentOptions" watchFragment(options: WatchFragmentOptions): Observable>; watchQuery(options: WatchQueryOptions): ObservableQuery; writeFragment(options: DataProxy.WriteFragmentOptions): Reference | undefined; From cba1c3a92e781830d1de77b16d81b6953215bfee Mon Sep 17 00:00:00 2001 From: Alessia Bellisario Date: Thu, 14 Mar 2024 16:06:34 -0400 Subject: [PATCH 09/25] fix: use ObservableStream in tests and fix bug --- src/__tests__/ApolloClient.ts | 226 +++++++++------------------------ src/cache/core/cache.ts | 3 +- src/react/hooks/useFragment.ts | 2 + 3 files changed, 60 insertions(+), 171 deletions(-) diff --git a/src/__tests__/ApolloClient.ts b/src/__tests__/ApolloClient.ts index 46f0bdc0745..92d29297968 100644 --- a/src/__tests__/ApolloClient.ts +++ b/src/__tests__/ApolloClient.ts @@ -14,8 +14,8 @@ import { ApolloLink } from "../link/core"; import { HttpLink } from "../link/http"; import { InMemoryCache } from "../cache"; import { concatPagination } from "../utilities"; -import { itAsync, wait } from "../testing"; -import { spyOnConsole } from "../testing/internal"; +import { itAsync } from "../testing"; +import { ObservableStream, spyOnConsole } from "../testing/internal"; import { TypedDocumentNode } from "@graphql-typed-document-node/core"; import { invariant } from "../utilities/globals"; @@ -2209,22 +2209,20 @@ describe("ApolloClient", () => { from: { __typename: "Item", id: 5 }, }); - const handleNext = jest.fn(); - - observable.subscribe(handleNext); - - await wait(0); // need to wait a tick + const stream = new ObservableStream(observable); - expect(handleNext).toHaveBeenCalledTimes(1); + { + const result = await stream.takeNext(); - expect(handleNext).toHaveBeenLastCalledWith({ - data: { - __typename: "Item", - id: 5, - text: "Item #5", - }, - complete: true, - }); + expect(result).toEqual({ + data: { + __typename: "Item", + id: 5, + text: "Item #5", + }, + complete: true, + }); + } }); it("if only partial data is available, `complete` is `false`", async () => { const cache = new InMemoryCache(); @@ -2239,15 +2237,6 @@ describe("ApolloClient", () => { } `; - const observable = client.watchFragment({ - fragment: ItemFragment, - from: { __typename: "Item", id: 5 }, - }); - - const handleNext = jest.fn(); - - observable.subscribe(handleNext); - { // we expect a "Missing field 'text' while writing result..." error // when writing item to the cache, so we'll silence the console.error @@ -2261,18 +2250,27 @@ describe("ApolloClient", () => { }); } - expect(handleNext).toHaveBeenCalledTimes(1); - - expect(handleNext).toHaveBeenLastCalledWith({ - data: { - __typename: "Item", - id: 5, - }, - complete: false, - missing: { - text: "Can't find field 'text' on Item:5 object", - }, + const observable = client.watchFragment({ + fragment: ItemFragment, + from: { __typename: "Item", id: 5 }, }); + + const stream = new ObservableStream(observable); + + { + const result = await stream.takeNext(); + + expect(result).toEqual({ + data: { + __typename: "Item", + id: 5, + }, + complete: false, + missing: { + text: "Can't find field 'text' on Item:5 object", + }, + }); + } }); it("if no data is written after observable is subscribed to, next is never called", async () => { const cache = new InMemoryCache(); @@ -2292,6 +2290,18 @@ describe("ApolloClient", () => { from: { __typename: "Item", id: 5 }, }); + const stream = new ObservableStream(observable); + + { + const result = await stream.takeNext(); + + expect(result).toEqual({ + complete: false, + data: {}, + missing: "Dangling reference to missing Item:5 object", + }); + } + const handleNext = jest.fn(); observable.subscribe(handleNext); @@ -2311,15 +2321,6 @@ describe("ApolloClient", () => { } `; - const observable = client.watchFragment({ - fragment: ItemFragment, - from: { __typename: "Item", id: 5 }, - }); - - const handleNext = jest.fn(); - - observable.subscribe(handleNext); - cache.writeFragment({ fragment: ItemFragment, data: { @@ -2329,139 +2330,26 @@ describe("ApolloClient", () => { }, }); - expect(handleNext).toHaveBeenCalledTimes(1); - expect(handleNext).toHaveBeenLastCalledWith({ - data: { - __typename: "Item", - id: 5, - text: "Item #5", - }, - complete: true, + const observable = client.watchFragment({ + fragment: ItemFragment, + from: { __typename: "Item", id: 5 }, }); - }); - it.each>([ - // This query uses a basic field-level @nonreactive directive. - gql` - query GetItems { - list { - id - text @nonreactive - } - } - `, - // This query uses @nonreactive on an anonymous/inline ...spread directive. - gql` - query GetItems { - list { - id - ... @nonreactive { - text - } - } - } - `, - // This query uses @nonreactive on a ...spread with a type condition. - gql` - query GetItems { - list { - id - ... on Item @nonreactive { - text - } - } - } - `, - // This query uses @nonreactive directive on a named fragment ...spread. - gql` - query GetItems { - list { - id - ...ItemText @nonreactive - } - } - fragment ItemText on Item { - text - } - `, - ])( - "watchQuery can use @nonreactive to avoid rerendering", - async (query) => { - const cache = new InMemoryCache({ - typePolicies: { - Query: { - fields: { - list: concatPagination(), - }, - }, - Item: { - keyFields: ["id"], - // Configuring keyArgs:false for Item.text is one way to prevent field - // keys like text@nonreactive, but it's not the only way. Since - // @nonreactive is now in the KNOWN_DIRECTIVES array defined in - // utilities/graphql/storeUtils.ts, the '@nonreactive' suffix won't be - // automatically appended to field keys by default. - // fields: { - // text: { - // keyArgs: false, - // }, - // }, - }, - }, - }); - - const client = new ApolloClient({ - cache, - link: ApolloLink.empty(), - }); - - const queryObs = client.watchQuery({ - query, - }); - const handleNext = jest.fn(); + const stream = new ObservableStream(observable); - queryObs.subscribe(handleNext); + { + const result = await stream.takeNext(); - cache.writeQuery({ - query, + expect(result).toEqual({ data: { - list: [ - { __typename: "Item", id: 1, text: "first" }, - { __typename: "Item", id: 2, text: "second" }, - { __typename: "Item", id: 3, text: "third" }, - ], - }, - }); - - expect(cache.extract()).toEqual({ - ROOT_QUERY: { - __typename: "Query", - list: [ - { __ref: 'Item:{"id":1}' }, - { __ref: 'Item:{"id":2}' }, - { __ref: 'Item:{"id":3}' }, - ], - }, - 'Item:{"id":1}': { __typename: "Item", - id: 1, - text: "first", - }, - 'Item:{"id":2}': { - __typename: "Item", - id: 2, - text: "second", - }, - 'Item:{"id":3}': { - __typename: "Item", - id: 3, - text: "third", + id: 5, + text: "Item #5", }, + complete: true, }); } - ); - it.todo("always returns partial data"); - it.todo("missing is a tree describing missing fields"); + }); }); describe("defaultOptions", () => { diff --git a/src/cache/core/cache.ts b/src/cache/core/cache.ts index 8e018ac900f..d7e4b19baad 100644 --- a/src/cache/core/cache.ts +++ b/src/cache/core/cache.ts @@ -48,7 +48,6 @@ export interface WatchFragmentOptions { canonizeResults?: boolean; } -// todo: refactor duplicated type, see UseFragmentResult export type WatchFragmentResult = | { data: TData; @@ -201,7 +200,7 @@ export abstract class ApolloCache implements DataProxy { optimistic, }; - let latestDiff = this.diff(diffOptions); + let latestDiff: DataProxy.DiffResult | undefined; return new Observable((observer) => { return this.watch({ diff --git a/src/react/hooks/useFragment.ts b/src/react/hooks/useFragment.ts index 47ec2d2bca0..4d178c80086 100644 --- a/src/react/hooks/useFragment.ts +++ b/src/react/hooks/useFragment.ts @@ -13,6 +13,7 @@ import { useSyncExternalStore } from "./useSyncExternalStore.js"; import type { ApolloClient, OperationVariables } from "../../core/index.js"; import type { NoInfer } from "../types/types.js"; import { useDeepMemo, wrapHook } from "./internal/index.js"; +import equal from "@wry/equality"; export interface UseFragmentOptions extends Omit< @@ -100,6 +101,7 @@ function _useFragment( let lastTimeout = 0; const subscription = cache.watchFragment(options).subscribe({ next: (result) => { + if (equal(result, resultRef.current)) return; resultRef.current = result; // If we get another update before we've re-rendered, bail out of // the update and try again. This ensures that the relative timing From 7a7c5ed3b9dd8173f174c5350083a969e6b678e9 Mon Sep 17 00:00:00 2001 From: alessbell Date: Thu, 14 Mar 2024 20:08:53 +0000 Subject: [PATCH 10/25] Clean up Prettier, Size-limit, and Api-Extractor --- .size-limits.json | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.size-limits.json b/.size-limits.json index 1332ae918c5..4b5ca67d444 100644 --- a/.size-limits.json +++ b/.size-limits.json @@ -1,4 +1,4 @@ { - "dist/apollo-client.min.cjs": 39374, - "import { ApolloClient, InMemoryCache, HttpLink } from \"dist/index.js\" (production)": 32793 + "dist/apollo-client.min.cjs": 39367, + "import { ApolloClient, InMemoryCache, HttpLink } from \"dist/index.js\" (production)": 32788 } From 7e6539d7ad873737858520827d8bfec904fee09e Mon Sep 17 00:00:00 2001 From: Alessia Bellisario Date: Thu, 14 Mar 2024 16:35:56 -0400 Subject: [PATCH 11/25] fix: remove unused type and import in ApolloClient test --- src/__tests__/ApolloClient.ts | 7 ------- 1 file changed, 7 deletions(-) diff --git a/src/__tests__/ApolloClient.ts b/src/__tests__/ApolloClient.ts index 92d29297968..6c140949c2c 100644 --- a/src/__tests__/ApolloClient.ts +++ b/src/__tests__/ApolloClient.ts @@ -13,7 +13,6 @@ import { Observable } from "../utilities"; import { ApolloLink } from "../link/core"; import { HttpLink } from "../link/http"; import { InMemoryCache } from "../cache"; -import { concatPagination } from "../utilities"; import { itAsync } from "../testing"; import { ObservableStream, spyOnConsole } from "../testing/internal"; import { TypedDocumentNode } from "@graphql-typed-document-node/core"; @@ -2176,12 +2175,6 @@ describe("ApolloClient", () => { }); describe("watchFragment", () => { - type Item = { - __typename: string; - id: number; - text?: string; - }; - it("if all data is available, `complete` is `true`", async () => { const cache = new InMemoryCache(); const client = new ApolloClient({ From 4a8dac064f2254cfe94cf74633d1130cfb52f9a4 Mon Sep 17 00:00:00 2001 From: Alessia Bellisario Date: Fri, 15 Mar 2024 12:21:27 -0400 Subject: [PATCH 12/25] fix: dont create new subscription in ApolloClient test --- src/__tests__/ApolloClient.ts | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) diff --git a/src/__tests__/ApolloClient.ts b/src/__tests__/ApolloClient.ts index 6c140949c2c..44e90c6ea9b 100644 --- a/src/__tests__/ApolloClient.ts +++ b/src/__tests__/ApolloClient.ts @@ -2295,11 +2295,9 @@ describe("ApolloClient", () => { }); } - const handleNext = jest.fn(); - - observable.subscribe(handleNext); - - expect(handleNext).toHaveBeenCalledTimes(0); + await expect(stream.takeNext({ timeout: 1000 })).rejects.toEqual( + expect.any(Error) + ); }); it("does not react to updates to @nonreactive fields", async () => { const cache = new InMemoryCache(); From dabe2cda3852aa1e9f830f086f14552f77cdff57 Mon Sep 17 00:00:00 2001 From: Alessia Bellisario Date: Fri, 15 Mar 2024 12:34:27 -0400 Subject: [PATCH 13/25] fix: add documentation for options and result types --- .api-reports/api-report-cache.md | 8 ++---- .api-reports/api-report-core.md | 8 ++---- .api-reports/api-report-react.md | 8 ++---- .api-reports/api-report-react_components.md | 8 ++---- .api-reports/api-report-react_context.md | 8 ++---- .api-reports/api-report-react_hoc.md | 8 ++---- .api-reports/api-report-react_hooks.md | 8 ++---- .api-reports/api-report-react_internal.md | 8 ++---- .api-reports/api-report-react_ssr.md | 8 ++---- .api-reports/api-report-testing.md | 8 ++---- .api-reports/api-report-testing_core.md | 8 ++---- .api-reports/api-report-utilities.md | 8 ++---- .api-reports/api-report.md | 8 ++---- src/cache/core/cache.ts | 29 ++++++++++++++++++++- 14 files changed, 54 insertions(+), 79 deletions(-) diff --git a/.api-reports/api-report-cache.md b/.api-reports/api-report-cache.md index 8aca339ffae..0bf245fdeb9 100644 --- a/.api-reports/api-report-cache.md +++ b/.api-reports/api-report-cache.md @@ -976,22 +976,18 @@ export type TypePolicy = { }; }; -// @public (undocumented) +// @public interface WatchFragmentOptions { // @deprecated (undocumented) canonizeResults?: boolean; - // (undocumented) fragment: DocumentNode | TypedDocumentNode; - // (undocumented) fragmentName?: string; - // (undocumented) from: StoreObject | Reference | string; - // (undocumented) optimistic?: boolean; variables?: TVars; } -// @public (undocumented) +// @public type WatchFragmentResult = { data: TData; complete: true; diff --git a/.api-reports/api-report-core.md b/.api-reports/api-report-core.md index feb59c39143..c9be0d52fb6 100644 --- a/.api-reports/api-report-core.md +++ b/.api-reports/api-report-core.md @@ -2212,22 +2212,18 @@ export interface UriFunction { (operation: Operation): string; } -// @public (undocumented) +// @public interface WatchFragmentOptions { // @deprecated (undocumented) canonizeResults?: boolean; - // (undocumented) fragment: DocumentNode | TypedDocumentNode; - // (undocumented) fragmentName?: string; - // (undocumented) from: StoreObject | Reference | string; - // (undocumented) optimistic?: boolean; variables?: TVars; } -// @public (undocumented) +// @public type WatchFragmentResult = { data: TData; complete: true; diff --git a/.api-reports/api-report-react.md b/.api-reports/api-report-react.md index 87f5a6b3f75..6b291639724 100644 --- a/.api-reports/api-report-react.md +++ b/.api-reports/api-report-react.md @@ -2367,22 +2367,18 @@ TVariables variables: TVariables; }; -// @public (undocumented) +// @public interface WatchFragmentOptions { // @deprecated (undocumented) canonizeResults?: boolean; - // (undocumented) fragment: DocumentNode | TypedDocumentNode; - // (undocumented) fragmentName?: string; - // (undocumented) from: StoreObject | Reference | string; - // (undocumented) optimistic?: boolean; variables?: TVars; } -// @public (undocumented) +// @public type WatchFragmentResult = { data: TData; complete: true; diff --git a/.api-reports/api-report-react_components.md b/.api-reports/api-report-react_components.md index 09b48e892e5..e209c316d27 100644 --- a/.api-reports/api-report-react_components.md +++ b/.api-reports/api-report-react_components.md @@ -1744,22 +1744,18 @@ interface UriFunction { (operation: Operation): string; } -// @public (undocumented) +// @public interface WatchFragmentOptions { // @deprecated (undocumented) canonizeResults?: boolean; - // (undocumented) fragment: DocumentNode | TypedDocumentNode; - // (undocumented) fragmentName?: string; - // (undocumented) from: StoreObject | Reference | string; - // (undocumented) optimistic?: boolean; variables?: TVars; } -// @public (undocumented) +// @public type WatchFragmentResult = { data: TData; complete: true; diff --git a/.api-reports/api-report-react_context.md b/.api-reports/api-report-react_context.md index f78d34ea62b..00227f7c365 100644 --- a/.api-reports/api-report-react_context.md +++ b/.api-reports/api-report-react_context.md @@ -1667,22 +1667,18 @@ interface UriFunction { (operation: Operation): string; } -// @public (undocumented) +// @public interface WatchFragmentOptions { // @deprecated (undocumented) canonizeResults?: boolean; - // (undocumented) fragment: DocumentNode | TypedDocumentNode; - // (undocumented) fragmentName?: string; - // (undocumented) from: StoreObject | Reference | string; - // (undocumented) optimistic?: boolean; variables?: TVars; } -// @public (undocumented) +// @public type WatchFragmentResult = { data: TData; complete: true; diff --git a/.api-reports/api-report-react_hoc.md b/.api-reports/api-report-react_hoc.md index a1deecfc145..48734526078 100644 --- a/.api-reports/api-report-react_hoc.md +++ b/.api-reports/api-report-react_hoc.md @@ -1679,22 +1679,18 @@ interface UriFunction { (operation: Operation): string; } -// @public (undocumented) +// @public interface WatchFragmentOptions { // @deprecated (undocumented) canonizeResults?: boolean; - // (undocumented) fragment: DocumentNode | TypedDocumentNode; - // (undocumented) fragmentName?: string; - // (undocumented) from: StoreObject | Reference | string; - // (undocumented) optimistic?: boolean; variables?: TVars; } -// @public (undocumented) +// @public type WatchFragmentResult = { data: TData; complete: true; diff --git a/.api-reports/api-report-react_hooks.md b/.api-reports/api-report-react_hooks.md index 53d506d45eb..8297aa40a2d 100644 --- a/.api-reports/api-report-react_hooks.md +++ b/.api-reports/api-report-react_hooks.md @@ -2203,22 +2203,18 @@ export interface UseSuspenseQueryResult; } -// @public (undocumented) +// @public interface WatchFragmentOptions { // @deprecated (undocumented) canonizeResults?: boolean; - // (undocumented) fragment: DocumentNode | TypedDocumentNode; - // (undocumented) fragmentName?: string; - // (undocumented) from: StoreObject | Reference | string; - // (undocumented) optimistic?: boolean; variables?: TVars; } -// @public (undocumented) +// @public type WatchFragmentResult = { data: TData; complete: true; diff --git a/.api-reports/api-report-react_internal.md b/.api-reports/api-report-react_internal.md index 230fbe77d7b..b08b1bc6ba2 100644 --- a/.api-reports/api-report-react_internal.md +++ b/.api-reports/api-report-react_internal.md @@ -2018,22 +2018,18 @@ interface UseSuspenseQueryResult; } -// @public (undocumented) +// @public interface WatchFragmentOptions { // @deprecated (undocumented) canonizeResults?: boolean; - // (undocumented) fragment: DocumentNode | TypedDocumentNode; - // (undocumented) fragmentName?: string; - // (undocumented) from: StoreObject | Reference | string; - // (undocumented) optimistic?: boolean; variables?: TVars; } -// @public (undocumented) +// @public type WatchFragmentResult = { data: TData; complete: true; diff --git a/.api-reports/api-report-react_ssr.md b/.api-reports/api-report-react_ssr.md index 94a8258be2b..21c4a42669a 100644 --- a/.api-reports/api-report-react_ssr.md +++ b/.api-reports/api-report-react_ssr.md @@ -1652,22 +1652,18 @@ interface UriFunction { (operation: Operation): string; } -// @public (undocumented) +// @public interface WatchFragmentOptions { // @deprecated (undocumented) canonizeResults?: boolean; - // (undocumented) fragment: DocumentNode | TypedDocumentNode; - // (undocumented) fragmentName?: string; - // (undocumented) from: StoreObject | Reference | string; - // (undocumented) optimistic?: boolean; variables?: TVars; } -// @public (undocumented) +// @public type WatchFragmentResult = { data: TData; complete: true; diff --git a/.api-reports/api-report-testing.md b/.api-reports/api-report-testing.md index cab4b3a9e8c..a9484356dde 100644 --- a/.api-reports/api-report-testing.md +++ b/.api-reports/api-report-testing.md @@ -1703,22 +1703,18 @@ type VariableMatcher> = (variables: V) => boolean; // @public (undocumented) export function wait(ms: number): Promise; -// @public (undocumented) +// @public interface WatchFragmentOptions { // @deprecated (undocumented) canonizeResults?: boolean; - // (undocumented) fragment: DocumentNode | TypedDocumentNode; - // (undocumented) fragmentName?: string; - // (undocumented) from: StoreObject | Reference | string; - // (undocumented) optimistic?: boolean; variables?: TVars; } -// @public (undocumented) +// @public type WatchFragmentResult = { data: TData; complete: true; diff --git a/.api-reports/api-report-testing_core.md b/.api-reports/api-report-testing_core.md index 94a2174bc34..0f5badbd21f 100644 --- a/.api-reports/api-report-testing_core.md +++ b/.api-reports/api-report-testing_core.md @@ -1660,22 +1660,18 @@ type VariableMatcher> = (variables: V) => boolean; // @public (undocumented) export function wait(ms: number): Promise; -// @public (undocumented) +// @public interface WatchFragmentOptions { // @deprecated (undocumented) canonizeResults?: boolean; - // (undocumented) fragment: DocumentNode | TypedDocumentNode; - // (undocumented) fragmentName?: string; - // (undocumented) from: StoreObject | Reference | string; - // (undocumented) optimistic?: boolean; variables?: TVars; } -// @public (undocumented) +// @public type WatchFragmentResult = { data: TData; complete: true; diff --git a/.api-reports/api-report-utilities.md b/.api-reports/api-report-utilities.md index 7be9a361b3a..8dde27dbc41 100644 --- a/.api-reports/api-report-utilities.md +++ b/.api-reports/api-report-utilities.md @@ -2572,22 +2572,18 @@ export function valueToObjectRepresentation(argObj: any, name: NameNode, value: // @public (undocumented) export type VariableValue = (node: VariableNode) => any; -// @public (undocumented) +// @public interface WatchFragmentOptions { // @deprecated (undocumented) canonizeResults?: boolean; - // (undocumented) fragment: DocumentNode | TypedDocumentNode; - // (undocumented) fragmentName?: string; - // (undocumented) from: StoreObject | Reference | string; - // (undocumented) optimistic?: boolean; variables?: TVars; } -// @public (undocumented) +// @public type WatchFragmentResult = { data: TData; complete: true; diff --git a/.api-reports/api-report.md b/.api-reports/api-report.md index 2948c358c8f..f2c04199b74 100644 --- a/.api-reports/api-report.md +++ b/.api-reports/api-report.md @@ -3023,22 +3023,18 @@ TVariables variables: TVariables; }; -// @public (undocumented) +// @public interface WatchFragmentOptions { // @deprecated (undocumented) canonizeResults?: boolean; - // (undocumented) fragment: DocumentNode | TypedDocumentNode; - // (undocumented) fragmentName?: string; - // (undocumented) from: StoreObject | Reference | string; - // (undocumented) optimistic?: boolean; variables?: TVars; } -// @public (undocumented) +// @public type WatchFragmentResult = { data: TData; complete: true; diff --git a/src/cache/core/cache.ts b/src/cache/core/cache.ts index d7e4b19baad..325bb4165fe 100644 --- a/src/cache/core/cache.ts +++ b/src/cache/core/cache.ts @@ -26,14 +26,38 @@ import type { MissingTree } from "./types/common.js"; export type Transaction = (c: ApolloCache) => void; +/** + * Watched fragment options. + */ export interface WatchFragmentOptions { + /** + * **Required.** A GraphQL fragment document parsed into an AST with the `gql` + * template literal. + */ fragment: DocumentNode | TypedDocumentNode; + /** + * **Required.** An object containing a `__typename` and primary key fields + * (such as `id`) identifying the entity object from which the fragment will + * be retrieved, or a `{ __ref: "..." }` reference, or a `string` ID + * (uncommon). + */ from: StoreObject | Reference | string; /** - * Any variables that the GraphQL query may depend on. + * Any variables that the GraphQL fragment may depend on. */ variables?: TVars; + /** + * The name of the fragment defined in the fragment document. + * + * **Required** if the fragment document includes more than one fragment, + * optional otherwise. + */ fragmentName?: string; + /** + * If `true`, `watchFragment` returns optimistic results. + * + * The default value is `true`. + */ optimistic?: boolean; /** * @deprecated @@ -48,6 +72,9 @@ export interface WatchFragmentOptions { canonizeResults?: boolean; } +/** + * Watched fragment results. + */ export type WatchFragmentResult = | { data: TData; From bc4532d1c11a67641dccd785862e050955e8e6de Mon Sep 17 00:00:00 2001 From: Alessia Bellisario Date: Fri, 15 Mar 2024 14:00:17 -0400 Subject: [PATCH 14/25] test: npm audit fix in netlify.toml --- netlify.toml | 1 + 1 file changed, 1 insertion(+) diff --git a/netlify.toml b/netlify.toml index 510fb6a139b..1027f32e7b3 100644 --- a/netlify.toml +++ b/netlify.toml @@ -16,6 +16,7 @@ git clone https://github.com/apollographql/docs --branch main --single-branch monodocs cd monodocs npm i + npm audit fix --force cp -r ../docs local DOCS_LOCAL=true npm run build \ """ From 155d6f5c16a4533846eb25b9cd8d53714c90dd36 Mon Sep 17 00:00:00 2001 From: Alessia Bellisario Date: Fri, 15 Mar 2024 14:11:51 -0400 Subject: [PATCH 15/25] test: use Node 16 for deploy previews --- netlify.toml | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/netlify.toml b/netlify.toml index 1027f32e7b3..798136d26be 100644 --- a/netlify.toml +++ b/netlify.toml @@ -5,6 +5,9 @@ [build.environment] NODE_VERSION = "18" +[context.deploy-preview.environment] + NODE_VERSION = "16" + [context.deploy-preview.build] base = "docs" ignore = "git diff --quiet $CACHED_COMMIT_REF $COMMIT_REF . ../src" @@ -16,7 +19,6 @@ git clone https://github.com/apollographql/docs --branch main --single-branch monodocs cd monodocs npm i - npm audit fix --force cp -r ../docs local DOCS_LOCAL=true npm run build \ """ From a430082e752fb915dfa02f7d9c75c2ef786d4b26 Mon Sep 17 00:00:00 2001 From: Alessia Bellisario Date: Fri, 15 Mar 2024 14:15:06 -0400 Subject: [PATCH 16/25] remove node 18 from netlify.toml --- netlify.toml | 3 --- 1 file changed, 3 deletions(-) diff --git a/netlify.toml b/netlify.toml index 798136d26be..3723f1b6a80 100644 --- a/netlify.toml +++ b/netlify.toml @@ -2,9 +2,6 @@ publish = "docs/public" command = "npm run typedoc; npm run docmodel > docs/public/log.txt || true" -[build.environment] - NODE_VERSION = "18" - [context.deploy-preview.environment] NODE_VERSION = "16" From 09dd69705bdb229c9e7b3715bf9af4ff4430cefe Mon Sep 17 00:00:00 2001 From: Alessia Bellisario Date: Fri, 15 Mar 2024 14:16:40 -0400 Subject: [PATCH 17/25] use context.production.environment in netlify.toml --- netlify.toml | 3 +++ 1 file changed, 3 insertions(+) diff --git a/netlify.toml b/netlify.toml index 3723f1b6a80..7f8a85c8c9d 100644 --- a/netlify.toml +++ b/netlify.toml @@ -2,6 +2,9 @@ publish = "docs/public" command = "npm run typedoc; npm run docmodel > docs/public/log.txt || true" +[context.production.environment] + NODE_VERSION = "18" + [context.deploy-preview.environment] NODE_VERSION = "16" From eba46c68c1afe65631dd2798e3ec27e2123e8ecd Mon Sep 17 00:00:00 2001 From: Alessia Bellisario Date: Fri, 15 Mar 2024 14:21:55 -0400 Subject: [PATCH 18/25] use netlify GUI to set Node version --- netlify.toml | 6 ------ 1 file changed, 6 deletions(-) diff --git a/netlify.toml b/netlify.toml index 7f8a85c8c9d..363e4f0818d 100644 --- a/netlify.toml +++ b/netlify.toml @@ -2,12 +2,6 @@ publish = "docs/public" command = "npm run typedoc; npm run docmodel > docs/public/log.txt || true" -[context.production.environment] - NODE_VERSION = "18" - -[context.deploy-preview.environment] - NODE_VERSION = "16" - [context.deploy-preview.build] base = "docs" ignore = "git diff --quiet $CACHED_COMMIT_REF $COMMIT_REF . ../src" From 88cc319a7da2f0aad7cdc4e7e9ac9e56b1a35e07 Mon Sep 17 00:00:00 2001 From: Alessia Bellisario Date: Mon, 18 Mar 2024 10:59:10 -0400 Subject: [PATCH 19/25] fix: add docgroups to watchFragment options --- src/cache/core/cache.ts | 16 +++++++++++++--- 1 file changed, 13 insertions(+), 3 deletions(-) diff --git a/src/cache/core/cache.ts b/src/cache/core/cache.ts index 325bb4165fe..6c9e4108223 100644 --- a/src/cache/core/cache.ts +++ b/src/cache/core/cache.ts @@ -31,32 +31,42 @@ export type Transaction = (c: ApolloCache) => void; */ export interface WatchFragmentOptions { /** - * **Required.** A GraphQL fragment document parsed into an AST with the `gql` + * A GraphQL fragment document parsed into an AST with the `gql` * template literal. + * + * @docGroup 1. Required options */ fragment: DocumentNode | TypedDocumentNode; /** - * **Required.** An object containing a `__typename` and primary key fields + * An object containing a `__typename` and primary key fields * (such as `id`) identifying the entity object from which the fragment will * be retrieved, or a `{ __ref: "..." }` reference, or a `string` ID * (uncommon). + * + * @docGroup 1. Required options */ from: StoreObject | Reference | string; /** * Any variables that the GraphQL fragment may depend on. + * + * @docGroup 2. Cache options */ variables?: TVars; /** * The name of the fragment defined in the fragment document. * - * **Required** if the fragment document includes more than one fragment, + * Required if the fragment document includes more than one fragment, * optional otherwise. + * + * @docGroup 2. Cache options */ fragmentName?: string; /** * If `true`, `watchFragment` returns optimistic results. * * The default value is `true`. + * + * @docGroup 2. Cache options */ optimistic?: boolean; /** From 3efd80d07ff595d0b57f86da04d6e4dccbbb3c17 Mon Sep 17 00:00:00 2001 From: Alessia Bellisario Date: Mon, 18 Mar 2024 13:34:12 -0400 Subject: [PATCH 20/25] fix: update doc block descriptions --- src/core/ApolloClient.ts | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/core/ApolloClient.ts b/src/core/ApolloClient.ts index 3de11723a3b..53abab69401 100644 --- a/src/core/ApolloClient.ts +++ b/src/core/ApolloClient.ts @@ -359,7 +359,7 @@ export class ApolloClient implements DataProxy { /** * This watches the cache store of the query according to the options specified and * returns an `ObservableQuery`. We can subscribe to this `ObservableQuery` and - * receive updated results through a GraphQL observer when the cache store changes. + * receive updated results through an observer when the cache store changes. * * Note that this method is not an implementation of GraphQL subscriptions. Rather, * it uses Apollo's store in order to reactively deliver updates to your query results. @@ -480,8 +480,8 @@ export class ApolloClient implements DataProxy { /** * Watches the cache store of the fragment according to the options specified - * and returns an Observable. We can subscribe to this - * Observable and receive updated results through a GraphQL + * and returns an `Observable`. We can subscribe to this + * `Observable` and receive updated results through an * observer when the cache store changes. * * You must pass in a GraphQL document with a single fragment or a document From 641382092f51114a349f4111140fb2aa8509876a Mon Sep 17 00:00:00 2001 From: Alessia Bellisario Date: Mon, 18 Mar 2024 13:38:58 -0400 Subject: [PATCH 21/25] fix: use stableOptions in dependency array and revert useLazyRef change --- src/react/hooks/useFragment.ts | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/src/react/hooks/useFragment.ts b/src/react/hooks/useFragment.ts index 4d178c80086..3c1425eecf7 100644 --- a/src/react/hooks/useFragment.ts +++ b/src/react/hooks/useFragment.ts @@ -12,7 +12,7 @@ import { useApolloClient } from "./useApolloClient.js"; import { useSyncExternalStore } from "./useSyncExternalStore.js"; import type { ApolloClient, OperationVariables } from "../../core/index.js"; import type { NoInfer } from "../types/types.js"; -import { useDeepMemo, wrapHook } from "./internal/index.js"; +import { useDeepMemo, useLazyRef, wrapHook } from "./internal/index.js"; import equal from "@wry/equality"; export interface UseFragmentOptions @@ -83,9 +83,12 @@ function _useFragment( }; }, [options]); - const resultRef = React.useRef>( + const resultRef = useLazyRef>(() => diffToResult(cache.diff(diffOptions)) ); + + const stableOptions = useDeepMemo(() => options, [options]); + // Since .next is async, we need to make sure that we // get the correct diff on the next render given new diffOptions React.useMemo(() => { @@ -99,7 +102,7 @@ function _useFragment( React.useCallback( (forceUpdate) => { let lastTimeout = 0; - const subscription = cache.watchFragment(options).subscribe({ + const subscription = cache.watchFragment(stableOptions).subscribe({ next: (result) => { if (equal(result, resultRef.current)) return; resultRef.current = result; @@ -116,7 +119,7 @@ function _useFragment( clearTimeout(lastTimeout); }; }, - [cache, diffOptions] + [cache, stableOptions] ), getSnapshot, getSnapshot From c453e71f61984a425ea3528afe2889e284347c2b Mon Sep 17 00:00:00 2001 From: alessbell Date: Mon, 18 Mar 2024 17:42:20 +0000 Subject: [PATCH 22/25] Clean up Prettier, Size-limit, and Api-Extractor --- .size-limits.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.size-limits.json b/.size-limits.json index 4b5ca67d444..dd93933136b 100644 --- a/.size-limits.json +++ b/.size-limits.json @@ -1,4 +1,4 @@ { - "dist/apollo-client.min.cjs": 39367, + "dist/apollo-client.min.cjs": 39403, "import { ApolloClient, InMemoryCache, HttpLink } from \"dist/index.js\" (production)": 32788 } From 4fedd26a0e8b3bd1bb5e30953f6fdca1958b3932 Mon Sep 17 00:00:00 2001 From: Alessia Bellisario Date: Mon, 18 Mar 2024 14:02:34 -0400 Subject: [PATCH 23/25] fix: update test --- src/__tests__/ApolloClient.ts | 24 +++++++++++++++++++++++- 1 file changed, 23 insertions(+), 1 deletion(-) diff --git a/src/__tests__/ApolloClient.ts b/src/__tests__/ApolloClient.ts index 44e90c6ea9b..0fb16d14b59 100644 --- a/src/__tests__/ApolloClient.ts +++ b/src/__tests__/ApolloClient.ts @@ -2299,7 +2299,7 @@ describe("ApolloClient", () => { expect.any(Error) ); }); - it("does not react to updates to @nonreactive fields", async () => { + it("does not support the @nonreactive directive", async () => { const cache = new InMemoryCache(); const client = new ApolloClient({ cache, @@ -2340,6 +2340,28 @@ describe("ApolloClient", () => { complete: true, }); } + + cache.writeFragment({ + fragment: ItemFragment, + data: { + __typename: "Item", + id: 5, + text: "Item #5 (edited)", + }, + }); + + { + const result = await stream.takeNext(); + + expect(result).toEqual({ + data: { + __typename: "Item", + id: 5, + text: "Item #5 (edited)", + }, + complete: true, + }); + } }); }); From ccb3a1a87569b896c2c9130dc16f16342e4a3140 Mon Sep 17 00:00:00 2001 From: Alessia Bellisario Date: Mon, 18 Mar 2024 14:10:15 -0400 Subject: [PATCH 24/25] fix: adds test case for reacting to cache writes --- src/__tests__/ApolloClient.ts | 66 +++++++++++++++++++++++++++++++++++ 1 file changed, 66 insertions(+) diff --git a/src/__tests__/ApolloClient.ts b/src/__tests__/ApolloClient.ts index 0fb16d14b59..e0e35233a01 100644 --- a/src/__tests__/ApolloClient.ts +++ b/src/__tests__/ApolloClient.ts @@ -2217,6 +2217,70 @@ describe("ApolloClient", () => { }); } }); + it("cache writes emit a new value", async () => { + const cache = new InMemoryCache(); + const client = new ApolloClient({ + cache, + link: ApolloLink.empty(), + }); + const ItemFragment = gql` + fragment ItemFragment on Item { + id + text + } + `; + + cache.writeFragment({ + fragment: ItemFragment, + data: { + __typename: "Item", + id: 5, + text: "Item #5", + }, + }); + + const observable = client.watchFragment({ + fragment: ItemFragment, + from: { __typename: "Item", id: 5 }, + }); + + const stream = new ObservableStream(observable); + + { + const result = await stream.takeNext(); + + expect(result).toEqual({ + data: { + __typename: "Item", + id: 5, + text: "Item #5", + }, + complete: true, + }); + } + + cache.writeFragment({ + fragment: ItemFragment, + data: { + __typename: "Item", + id: 5, + text: "Item #5 (edited)", + }, + }); + + { + const result = await stream.takeNext(); + + expect(result).toEqual({ + data: { + __typename: "Item", + id: 5, + text: "Item #5 (edited)", + }, + complete: true, + }); + } + }); it("if only partial data is available, `complete` is `false`", async () => { const cache = new InMemoryCache(); const client = new ApolloClient({ @@ -2357,6 +2421,8 @@ describe("ApolloClient", () => { data: { __typename: "Item", id: 5, + // The @nonreactive directive can only be used on fields or fragment + // spreads in queries, and has no effect here text: "Item #5 (edited)", }, complete: true, From 46c8eb70de93ab4eaa6d33a22402007908520c5b Mon Sep 17 00:00:00 2001 From: Alessia Bellisario Date: Mon, 18 Mar 2024 14:18:05 -0400 Subject: [PATCH 25/25] fix: use it.failing for nonreactive test case --- src/__tests__/ApolloClient.ts | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/__tests__/ApolloClient.ts b/src/__tests__/ApolloClient.ts index e0e35233a01..67ce0002714 100644 --- a/src/__tests__/ApolloClient.ts +++ b/src/__tests__/ApolloClient.ts @@ -2363,7 +2363,9 @@ describe("ApolloClient", () => { expect.any(Error) ); }); - it("does not support the @nonreactive directive", async () => { + // The @nonreactive directive can only be used on fields or fragment + // spreads in queries, and currently has no effect here + it.failing("does not support the @nonreactive directive", async () => { const cache = new InMemoryCache(); const client = new ApolloClient({ cache, @@ -2421,9 +2423,7 @@ describe("ApolloClient", () => { data: { __typename: "Item", id: 5, - // The @nonreactive directive can only be used on fields or fragment - // spreads in queries, and has no effect here - text: "Item #5 (edited)", + text: "Item #5", }, complete: true, });