From 80d2ba579fe6d2a2d102d1fe79d7d503f31cd931 Mon Sep 17 00:00:00 2001 From: Alessia Bellisario Date: Thu, 4 Apr 2024 17:24:01 -0400 Subject: [PATCH] `watchFragment` fixes (#11754) --- .api-reports/api-report-cache.md | 6 ++---- .api-reports/api-report-core.md | 6 ++---- .api-reports/api-report.md | 6 ++---- .changeset/old-onions-sleep.md | 5 +++++ .size-limits.json | 4 ++-- src/cache/index.ts | 6 +++++- src/core/ApolloClient.ts | 1 + src/core/index.ts | 2 ++ 8 files changed, 21 insertions(+), 15 deletions(-) create mode 100644 .changeset/old-onions-sleep.md diff --git a/.api-reports/api-report-cache.md b/.api-reports/api-report-cache.md index 0bf245fdeb9..0f075697b78 100644 --- a/.api-reports/api-report-cache.md +++ b/.api-reports/api-report-cache.md @@ -65,8 +65,6 @@ export abstract class ApolloCache implements DataProxy { // (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 watchFragment(options: WatchFragmentOptions): Observable>; // (undocumented) abstract write(write: Cache_2.WriteOptions): Reference | undefined; @@ -977,7 +975,7 @@ export type TypePolicy = { }; // @public -interface WatchFragmentOptions { +export interface WatchFragmentOptions { // @deprecated (undocumented) canonizeResults?: boolean; fragment: DocumentNode | TypedDocumentNode; @@ -988,7 +986,7 @@ interface WatchFragmentOptions { } // @public -type WatchFragmentResult = { +export type WatchFragmentResult = { data: TData; complete: true; missing?: never; diff --git a/.api-reports/api-report-core.md b/.api-reports/api-report-core.md index c9be0d52fb6..aabdc975485 100644 --- a/.api-reports/api-report-core.md +++ b/.api-reports/api-report-core.md @@ -79,8 +79,6 @@ 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 watchFragment(options: WatchFragmentOptions): Observable>; // (undocumented) abstract write(write: Cache_2.WriteOptions): Reference | undefined; @@ -2213,7 +2211,7 @@ export interface UriFunction { } // @public -interface WatchFragmentOptions { +export interface WatchFragmentOptions { // @deprecated (undocumented) canonizeResults?: boolean; fragment: DocumentNode | TypedDocumentNode; @@ -2224,7 +2222,7 @@ interface WatchFragmentOptions { } // @public -type WatchFragmentResult = { +export type WatchFragmentResult = { data: TData; complete: true; missing?: never; diff --git a/.api-reports/api-report.md b/.api-reports/api-report.md index f54282563f2..e9290fed8eb 100644 --- a/.api-reports/api-report.md +++ b/.api-reports/api-report.md @@ -81,8 +81,6 @@ 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 watchFragment(options: WatchFragmentOptions): Observable>; // (undocumented) abstract write(write: Cache_2.WriteOptions): Reference | undefined; @@ -3023,7 +3021,7 @@ TVariables }; // @public -interface WatchFragmentOptions { +export interface WatchFragmentOptions { // @deprecated (undocumented) canonizeResults?: boolean; fragment: DocumentNode | TypedDocumentNode; @@ -3034,7 +3032,7 @@ interface WatchFragmentOptions { } // @public -type WatchFragmentResult = { +export type WatchFragmentResult = { data: TData; complete: true; missing?: never; diff --git a/.changeset/old-onions-sleep.md b/.changeset/old-onions-sleep.md new file mode 100644 index 00000000000..e7961c33261 --- /dev/null +++ b/.changeset/old-onions-sleep.md @@ -0,0 +1,5 @@ +--- +"@apollo/client": patch +--- + +Export `WatchFragmentOptions` and `WatchFragmentResult` from main entrypoint and fix bug where `this` wasn't bound to the `watchFragment` method on `ApolloClient`. diff --git a/.size-limits.json b/.size-limits.json index 7f569cdcf1f..7d54db2a009 100644 --- a/.size-limits.json +++ b/.size-limits.json @@ -1,4 +1,4 @@ { - "dist/apollo-client.min.cjs": 39510, - "import { ApolloClient, InMemoryCache, HttpLink } from \"dist/index.js\" (production)": 32799 + "dist/apollo-client.min.cjs": 39518, + "import { ApolloClient, InMemoryCache, HttpLink } from \"dist/index.js\" (production)": 32809 } diff --git a/src/cache/index.ts b/src/cache/index.ts index d57341ff2ac..1f55d8c16df 100644 --- a/src/cache/index.ts +++ b/src/cache/index.ts @@ -1,6 +1,10 @@ import "../utilities/globals/index.js"; -export type { Transaction } from "./core/cache.js"; +export type { + Transaction, + WatchFragmentOptions, + WatchFragmentResult, +} from "./core/cache.js"; export { ApolloCache } from "./core/cache.js"; export { Cache } from "./core/types/Cache.js"; export type { DataProxy } from "./core/types/DataProxy.js"; diff --git a/src/core/ApolloClient.ts b/src/core/ApolloClient.ts index 53abab69401..42daf602226 100644 --- a/src/core/ApolloClient.ts +++ b/src/core/ApolloClient.ts @@ -239,6 +239,7 @@ export class ApolloClient implements DataProxy { this.watchQuery = this.watchQuery.bind(this); this.query = this.query.bind(this); this.mutate = this.mutate.bind(this); + this.watchFragment = this.watchFragment.bind(this); this.resetStore = this.resetStore.bind(this); this.reFetchObservableQueries = this.reFetchObservableQueries.bind(this); diff --git a/src/core/index.ts b/src/core/index.ts index 5757cdb2071..785b2d03efc 100644 --- a/src/core/index.ts +++ b/src/core/index.ts @@ -40,6 +40,8 @@ export type { FieldMergeFunction, FieldFunctionOptions, PossibleTypesMap, + WatchFragmentOptions, + WatchFragmentResult, } from "../cache/index.js"; export { Cache,