Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: extract watchFragment into separate method on ApolloCache #11465

Merged
merged 30 commits into from
Mar 18, 2024
Merged
Show file tree
Hide file tree
Changes from 23 commits
Commits
Show all changes
30 commits
Select commit Hold shift + click to select a range
07568d1
feat: extract watchFragment into separate method on ApolloCache
alessbell Jan 5, 2024
3018643
Clean up Prettier, Size-limit, and Api-Extractor
alessbell Mar 12, 2024
58808c7
chore: add docs and pr fixes
alessbell Mar 12, 2024
d8bc35e
Merge branch 'issue-11348-extract-watchFragment' of github.com:apollo…
alessbell Mar 12, 2024
9897f51
Clean up Prettier, Size-limit, and Api-Extractor
alessbell Mar 12, 2024
ea48ea3
small refactor
alessbell Mar 12, 2024
9ddc241
Merge branch 'issue-11348-extract-watchFragment' of github.com:apollo…
alessbell Mar 12, 2024
64b6139
Clean up Prettier, Size-limit, and Api-Extractor
alessbell Mar 12, 2024
397b3b3
docs: adds doc block annotations for generated docs
alessbell Mar 14, 2024
5ec77d1
Merge branch 'issue-11348-extract-watchFragment' of github.com:apollo…
alessbell Mar 14, 2024
41b49d7
Clean up Prettier, Size-limit, and Api-Extractor
alessbell Mar 14, 2024
cba1c3a
fix: use ObservableStream in tests and fix bug
alessbell Mar 14, 2024
6ba14cd
Merge branch 'issue-11348-extract-watchFragment' of github.com:apollo…
alessbell Mar 14, 2024
7a7c5ed
Clean up Prettier, Size-limit, and Api-Extractor
alessbell Mar 14, 2024
7e6539d
fix: remove unused type and import in ApolloClient test
alessbell Mar 14, 2024
4a8dac0
fix: dont create new subscription in ApolloClient test
alessbell Mar 15, 2024
dabe2cd
fix: add documentation for options and result types
alessbell Mar 15, 2024
bc4532d
test: npm audit fix in netlify.toml
alessbell Mar 15, 2024
155d6f5
test: use Node 16 for deploy previews
alessbell Mar 15, 2024
a430082
remove node 18 from netlify.toml
alessbell Mar 15, 2024
09dd697
use context.production.environment in netlify.toml
alessbell Mar 15, 2024
eba46c6
use netlify GUI to set Node version
alessbell Mar 15, 2024
d243a38
Merge branch 'release-3.10' into issue-11348-extract-watchFragment
alessbell Mar 15, 2024
88cc319
fix: add docgroups to watchFragment options
alessbell Mar 18, 2024
3efd80d
fix: update doc block descriptions
alessbell Mar 18, 2024
6413820
fix: use stableOptions in dependency array and revert useLazyRef change
alessbell Mar 18, 2024
c453e71
Clean up Prettier, Size-limit, and Api-Extractor
alessbell Mar 18, 2024
4fedd26
fix: update test
alessbell Mar 18, 2024
ccb3a1a
fix: adds test case for reacting to cache writes
alessbell Mar 18, 2024
46c8eb7
fix: use it.failing for nonreactive test case
alessbell Mar 18, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
68 changes: 65 additions & 3 deletions .api-reports/api-report-cache.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
//
Expand Down Expand Up @@ -63,6 +64,10 @@ export abstract class ApolloCache<TSerialized> implements DataProxy {
updateQuery<TData = any, TVariables = any>(options: Cache_2.UpdateQueryOptions<TData, TVariables>, update: (data: TData | null) => TData | null | void): TData | null;
// (undocumented)
abstract watch<TData = any, TVariables = any>(watch: Cache_2.WatchOptions<TData, TVariables>): () => 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<TData = any, TVars = OperationVariables>(options: WatchFragmentOptions<TData, TVars>): Observable<WatchFragmentResult<TData>>;
// (undocumented)
abstract write<TData = any, TVariables = any>(write: Cache_2.WriteOptions<TData, TVariables>): Reference | undefined;
// (undocumented)
Expand Down Expand Up @@ -274,6 +279,40 @@ export interface DataProxy {
writeQuery<TData = any, TVariables = any>(options: DataProxy.WriteQueryOptions<TData, TVariables>): 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> = T extends DeepPartialPrimitive ? T : T extends Map<infer TKey, infer TValue> ? DeepPartialMap<TKey, TValue> : T extends ReadonlyMap<infer TKey, infer TValue> ? DeepPartialReadonlyMap<TKey, TValue> : T extends Set<infer TItem> ? DeepPartialSet<TItem> : T extends ReadonlySet<infer TItem> ? DeepPartialReadonlySet<TItem> : T extends (...args: any[]) => unknown ? T | undefined : T extends object ? T extends (ReadonlyArray<infer TItem>) ? TItem[] extends (T) ? readonly TItem[] extends T ? ReadonlyArray<DeepPartial<TItem | undefined>> : Array<DeepPartial<TItem | undefined>> : DeepPartialObject<T> : DeepPartialObject<T> : unknown;

// Warning: (ae-forgotten-export) The symbol "DeepPartial" needs to be exported by the entry point index.d.ts
//
// @public (undocumented)
type DeepPartialMap<TKey, TValue> = {} & Map<DeepPartial<TKey>, DeepPartial<TValue>>;

// @public (undocumented)
type DeepPartialObject<T extends object> = {
[K in keyof T]?: DeepPartial<T[K]>;
};

// 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<TKey, TValue> = {} & ReadonlyMap<DeepPartial<TKey>, DeepPartial<TValue>>;

// @public (undocumented)
type DeepPartialReadonlySet<T> = {} & ReadonlySet<DeepPartial<T>>;

// @public (undocumented)
type DeepPartialSet<T> = {} & Set<DeepPartial<T>>;

// Warning: (ae-forgotten-export) The symbol "KeyFieldsContext" needs to be exported by the entry point index.d.ts
//
// @public (undocumented)
Expand Down Expand Up @@ -533,8 +572,6 @@ export class InMemoryCache extends ApolloCache<NormalizedCacheObject> {
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<TData, TVariables extends OperationVariables = any>(options: Cache_2.DiffOptions<TData, TVariables>): Cache_2.DiffResult<TData>;
// (undocumented)
Expand Down Expand Up @@ -824,6 +861,9 @@ export type PossibleTypesMap = {
[supertype: string]: string[];
};

// @public (undocumented)
type Primitive = null | undefined | string | number | boolean | symbol | bigint;

// @public (undocumented)
type ReactiveListener<T> = (value: T) => any;

Expand Down Expand Up @@ -936,6 +976,28 @@ export type TypePolicy = {
};
};

// @public
interface WatchFragmentOptions<TData, TVars> {
// @deprecated (undocumented)
canonizeResults?: boolean;
fragment: DocumentNode | TypedDocumentNode<TData, TVars>;
fragmentName?: string;
from: StoreObject | Reference | string;
optimistic?: boolean;
variables?: TVars;
}

// @public
type WatchFragmentResult<TData> = {
data: TData;
complete: true;
missing?: never;
} | {
data: DeepPartial<TData>;
complete: false;
missing: MissingTree;
};

// @public (undocumented)
interface WriteContext extends ReadMergeModifyContext {
// (undocumented)
Expand Down
66 changes: 63 additions & 3 deletions .api-reports/api-report-core.md
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,9 @@ export abstract class ApolloCache<TSerialized> implements DataProxy {
updateQuery<TData = any, TVariables = any>(options: Cache_2.UpdateQueryOptions<TData, TVariables>, update: (data: TData | null) => TData | null | void): TData | null;
// (undocumented)
abstract watch<TData = any, TVariables = any>(watch: Cache_2.WatchOptions<TData, TVariables>): () => void;
// Warning: (ae-forgotten-export) The symbol "WatchFragmentOptions" needs to be exported by the entry point index.d.ts
alessbell marked this conversation as resolved.
Show resolved Hide resolved
// Warning: (ae-forgotten-export) The symbol "WatchFragmentResult" needs to be exported by the entry point index.d.ts
watchFragment<TData = any, TVars = OperationVariables>(options: WatchFragmentOptions<TData, TVars>): Observable<WatchFragmentResult<TData>>;
// (undocumented)
abstract write<TData = any, TVariables = any>(write: Cache_2.WriteOptions<TData, TVariables>): Reference | undefined;
// (undocumented)
Expand All @@ -87,8 +90,6 @@ export abstract class ApolloCache<TSerialized> implements DataProxy {
writeQuery<TData = any, TVariables = any>({ id, data, ...options }: Cache_2.WriteQueryOptions<TData, TVariables>): 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<TCacheShape> implements DataProxy {
// (undocumented)
Expand Down Expand Up @@ -130,12 +131,12 @@ export class ApolloClient<TCacheShape> 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<T = any, TVariables extends OperationVariables = OperationVariables>(options: SubscriptionOptions<TVariables, T>): Observable<FetchResult<T>>;
// (undocumented)
readonly typeDefs: ApolloClientOptions<TCacheShape>["typeDefs"];
// (undocumented)
version: string;
watchFragment<TFragmentData = unknown, TVariables = OperationVariables>(options: WatchFragmentOptions<TFragmentData, TVariables>): Observable<WatchFragmentResult<TFragmentData>>;
watchQuery<T = any, TVariables extends OperationVariables = OperationVariables>(options: WatchQueryOptions<TVariables, T>): ObservableQuery<T, TVariables>;
writeFragment<TData = any, TVariables = OperationVariables>(options: DataProxy.WriteFragmentOptions<TData, TVariables>): Reference | undefined;
writeQuery<TData = any, TVariables = OperationVariables>(options: DataProxy.WriteQueryOptions<TData, TVariables>): Reference | undefined;
Expand Down Expand Up @@ -523,6 +524,40 @@ export interface DataProxy {
writeQuery<TData = any, TVariables = any>(options: DataProxy.WriteQueryOptions<TData, TVariables>): 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> = T extends DeepPartialPrimitive ? T : T extends Map<infer TKey, infer TValue> ? DeepPartialMap<TKey, TValue> : T extends ReadonlyMap<infer TKey, infer TValue> ? DeepPartialReadonlyMap<TKey, TValue> : T extends Set<infer TItem> ? DeepPartialSet<TItem> : T extends ReadonlySet<infer TItem> ? DeepPartialReadonlySet<TItem> : T extends (...args: any[]) => unknown ? T | undefined : T extends object ? T extends (ReadonlyArray<infer TItem>) ? TItem[] extends (T) ? readonly TItem[] extends T ? ReadonlyArray<DeepPartial<TItem | undefined>> : Array<DeepPartial<TItem | undefined>> : DeepPartialObject<T> : DeepPartialObject<T> : unknown;

// Warning: (ae-forgotten-export) The symbol "DeepPartial" needs to be exported by the entry point index.d.ts
//
// @public (undocumented)
type DeepPartialMap<TKey, TValue> = {} & Map<DeepPartial<TKey>, DeepPartial<TValue>>;

// @public (undocumented)
type DeepPartialObject<T extends object> = {
[K in keyof T]?: DeepPartial<T[K]>;
};

// 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<TKey, TValue> = {} & ReadonlyMap<DeepPartial<TKey>, DeepPartial<TValue>>;

// @public (undocumented)
type DeepPartialReadonlySet<T> = {} & ReadonlySet<DeepPartial<T>>;

// @public (undocumented)
type DeepPartialSet<T> = {} & Set<DeepPartial<T>>;

// @public (undocumented)
export interface DefaultContext extends Record<string, any> {
}
Expand Down Expand Up @@ -1636,6 +1671,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;
Expand Down Expand Up @@ -2174,6 +2212,28 @@ export interface UriFunction {
(operation: Operation): string;
}

// @public
interface WatchFragmentOptions<TData, TVars> {
// @deprecated (undocumented)
canonizeResults?: boolean;
fragment: DocumentNode | TypedDocumentNode<TData, TVars>;
fragmentName?: string;
from: StoreObject | Reference | string;
optimistic?: boolean;
variables?: TVars;
}

// @public
type WatchFragmentResult<TData> = {
data: TData;
complete: true;
missing?: never;
} | {
data: DeepPartial<TData>;
complete: false;
missing: MissingTree;
};

// @public (undocumented)
export type WatchQueryFetchPolicy = FetchPolicy | "cache-and-network";

Expand Down
37 changes: 27 additions & 10 deletions .api-reports/api-report-react.md
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,10 @@ abstract class ApolloCache<TSerialized> implements DataProxy {
updateQuery<TData = any, TVariables = any>(options: Cache_2.UpdateQueryOptions<TData, TVariables>, update: (data: TData | null) => TData | null | void): TData | null;
// (undocumented)
abstract watch<TData = any, TVariables = any>(watch: Cache_2.WatchOptions<TData, TVariables>): () => 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<TData = any, TVars = OperationVariables>(options: WatchFragmentOptions<TData, TVars>): Observable<WatchFragmentResult<TData>>;
// Warning: (ae-forgotten-export) The symbol "Reference" needs to be exported by the entry point index.d.ts
//
// (undocumented)
Expand All @@ -90,14 +94,10 @@ abstract class ApolloCache<TSerialized> implements DataProxy {
writeQuery<TData = any, TVariables = any>({ id, data, ...options }: Cache_2.WriteQueryOptions<TData, TVariables>): 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<TCacheShape> 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<TCacheShape>);
// Warning: (ae-forgotten-export) The symbol "GraphQLRequest" needs to be exported by the entry point index.d.ts
//
Expand Down Expand Up @@ -135,7 +135,6 @@ class ApolloClient<TCacheShape> implements DataProxy {
onResetStore(cb: () => Promise<any>): () => 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<T = any, TVariables extends OperationVariables = OperationVariables>(options: QueryOptions<TVariables, T>): Promise<ApolloQueryResult<T>>;
// (undocumented)
queryDeduplication: boolean;
Expand All @@ -153,19 +152,16 @@ class ApolloClient<TCacheShape> 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<T = any, TVariables extends OperationVariables = OperationVariables>(options: SubscriptionOptions<TVariables, T>): Observable<FetchResult<T>>;
// Warning: (ae-forgotten-export) The symbol "ApolloClientOptions" needs to be exported by the entry point index.d.ts
//
// (undocumented)
readonly typeDefs: ApolloClientOptions<TCacheShape>["typeDefs"];
// (undocumented)
version: string;
// Warning: (ae-forgotten-export) The symbol "OperationVariables" needs to be exported by the entry point index.d.ts
watchFragment<TFragmentData = unknown, TVariables = OperationVariables>(options: WatchFragmentOptions<TFragmentData, TVariables>): Observable<WatchFragmentResult<TFragmentData>>;
// 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<T = any, TVariables extends OperationVariables = OperationVariables>(options: WatchQueryOptions<TVariables, T>): ObservableQuery<T, TVariables>;
writeFragment<TData = any, TVariables = OperationVariables>(options: DataProxy.WriteFragmentOptions<TData, TVariables>): Reference | undefined;
writeQuery<TData = any, TVariables = OperationVariables>(options: DataProxy.WriteQueryOptions<TData, TVariables>): Reference | undefined;
Expand All @@ -186,7 +182,6 @@ interface ApolloClientOptions<TCacheShape> {
// (undocumented)
fragmentMatcher?: FragmentMatcher;
headers?: Record<string, string>;
// 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;
Expand Down Expand Up @@ -2372,6 +2367,28 @@ TVariables
variables: TVariables;
};

// @public
interface WatchFragmentOptions<TData, TVars> {
// @deprecated (undocumented)
canonizeResults?: boolean;
fragment: DocumentNode | TypedDocumentNode<TData, TVars>;
fragmentName?: string;
from: StoreObject | Reference | string;
optimistic?: boolean;
variables?: TVars;
}

// @public
type WatchFragmentResult<TData> = {
data: TData;
complete: true;
missing?: never;
} | {
data: DeepPartial<TData>;
complete: false;
missing: MissingTree;
};

// @public (undocumented)
type WatchQueryFetchPolicy = FetchPolicy | "cache-and-network";

Expand Down
Loading
Loading