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

Changed typings of updateQuery's previousQueryResult to be potentially undefined #12276

Merged
merged 39 commits into from
Feb 6, 2025
Merged
Show file tree
Hide file tree
Changes from 15 commits
Commits
Show all changes
39 commits
Select commit Hold shift + click to select a range
af64266
Changed typings of updateQuery's previousQueryResult to be potentiall…
Cellule Jan 15, 2025
e0f1e75
Fix more types
Cellule Jan 15, 2025
a4ce9be
Fix another test
Cellule Jan 15, 2025
9613b1e
format
Cellule Jan 15, 2025
34d92d3
Fixed expectation
Cellule Jan 20, 2025
179608a
Type safe attempt that is backward compatible
Cellule Jan 27, 2025
3ed8547
Self Review
Cellule Jan 27, 2025
0c11195
Fix tests
Cellule Jan 28, 2025
5fd221d
Try alternate approach using an option to skip updateQuery when there…
Cellule Feb 3, 2025
82d4f65
run extract-api
Cellule Feb 3, 2025
478c434
Fixed tests and documentation
Cellule Feb 3, 2025
0c7af89
Provide previousQueryResult through second argument in a type-safe ma…
Cellule Feb 3, 2025
36db4fc
Merge remote-tracking branch 'origin/release-3.13' into update-query-…
Cellule Feb 3, 2025
1e7f3f4
Fix
Cellule Feb 3, 2025
2443ac2
Fix test
Cellule Feb 4, 2025
f1828e0
Merge remote-tracking branch 'origin/release-3.13' into update-query-…
Cellule Feb 5, 2025
e0cda56
prettier
Cellule Feb 5, 2025
edf8520
PR Fixes
Cellule Feb 5, 2025
3f9c0cf
more fixes
Cellule Feb 5, 2025
88e4a0d
Revert type
Cellule Feb 5, 2025
db6a1f3
Remove unused generic argument from SubscribeToMoreUpdateQueryFn
jerelmiller Feb 5, 2025
9a17013
Deprecate UpdateQueryFn
jerelmiller Feb 6, 2025
5664f53
Export SubscribeToMoreUpdateQueryFn
jerelmiller Feb 6, 2025
8544944
Fix type of updateQuery in ObservableQueryFields
jerelmiller Feb 6, 2025
4fe89b1
Remove type constraint on TVariables in UpdateQueryMapFn
jerelmiller Feb 6, 2025
01f09ba
Fix type of updateQuery in hoc
jerelmiller Feb 6, 2025
96d3b3d
Update api report
jerelmiller Feb 6, 2025
1f15bcc
Don't export UpdateQueryFn since it wasn't already exported
jerelmiller Feb 6, 2025
2bb708b
Update api report
jerelmiller Feb 6, 2025
8917c83
Update size limits
jerelmiller Feb 6, 2025
9dd3c48
Use type inference
jerelmiller Feb 6, 2025
3e9c14f
Remove review comment
jerelmiller Feb 6, 2025
90227bc
Add additional changeset for patch of variables type
jerelmiller Feb 6, 2025
0371b7e
Update changeset
jerelmiller Feb 6, 2025
9b1f108
Add additional changeset
jerelmiller Feb 6, 2025
536cb47
Rename argument to unsafePreviousData in TypeScript
jerelmiller Feb 6, 2025
f438fb0
Update api report
jerelmiller Feb 6, 2025
1665f8a
Update changeset
jerelmiller Feb 6, 2025
b817562
Merge branch 'release-3.13' into update-query-typings
jerelmiller Feb 6, 2025
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
66 changes: 48 additions & 18 deletions .api-reports/api-report-core.api.md
Original file line number Diff line number Diff line change
Expand Up @@ -1726,8 +1726,8 @@ export class ObservableQuery<TData = any, TVariables extends OperationVariables
silentSetOptions(newOptions: Partial<WatchQueryOptions<TVariables, TData>>): void;
startPolling(pollInterval: number): void;
stopPolling(): void;
subscribeToMore<TSubscriptionData = TData, TSubscriptionVariables extends OperationVariables = TVariables>(options: SubscribeToMoreOptions<TData, TSubscriptionVariables, TSubscriptionData>): () => void;
updateQuery<TVars extends OperationVariables = TVariables>(mapFn: (previousQueryResult: Unmasked<TData>, options: Pick<WatchQueryOptions<TVars, TData>, "variables">) => Unmasked<TData>): void;
subscribeToMore<TSubscriptionData = TData, TSubscriptionVariables extends OperationVariables = TVariables>(options: SubscribeToMoreOptions<TData, TSubscriptionVariables, TSubscriptionData, TVariables>): () => void;
updateQuery(mapFn: UpdateQueryMapFn<TData, TVariables>): void;
get variables(): TVariables | undefined;
}

Expand Down Expand Up @@ -2317,13 +2317,34 @@ class Stump extends Layer {
}

// @public (undocumented)
export type SubscribeToMoreOptions<TData = any, TSubscriptionVariables = OperationVariables, TSubscriptionData = TData> = {
export interface SubscribeToMoreFunction<TData, TVariables extends OperationVariables = OperationVariables> {
// (undocumented)
<TSubscriptionData = TData, TSubscriptionVariables extends OperationVariables = TVariables>(options: SubscribeToMoreOptions<TData, TSubscriptionVariables, TSubscriptionData, TVariables>): () => void;
}

// @public (undocumented)
export interface SubscribeToMoreOptions<TData = any, TSubscriptionVariables extends OperationVariables = OperationVariables, TSubscriptionData = TData, TVariables extends OperationVariables = TSubscriptionVariables> {
// (undocumented)
context?: DefaultContext;
// (undocumented)
document: DocumentNode | TypedDocumentNode<TSubscriptionData, TSubscriptionVariables>;
variables?: TSubscriptionVariables;
updateQuery?: UpdateQueryFn<TData, TSubscriptionVariables, TSubscriptionData>;
// (undocumented)
onError?: (error: Error) => void;
context?: DefaultContext;
};
// Warning: (ae-forgotten-export) The symbol "SubscribeToMoreUpdateQueryFn" needs to be exported by the entry point index.d.ts
//
// (undocumented)
updateQuery?: SubscribeToMoreUpdateQueryFn<TData, TVariables, TSubscriptionVariables, TSubscriptionData>;
// (undocumented)
variables?: TSubscriptionVariables;
}

// @public (undocumented)
type SubscribeToMoreUpdateQueryFn<TData = any, TVariables extends OperationVariables = OperationVariables, TSubscriptionVariables extends OperationVariables = TVariables, TSubscriptionData = TData> = UpdateQueryMapFn<TData, TVariables, {
subscriptionData: {
data: Unmasked<TSubscriptionData>;
};
subscriptionVariables: TSubscriptionVariables | undefined;
}>;

// @public (undocumented)
export interface SubscriptionOptions<TVariables = OperationVariables, TData = any> {
Expand Down Expand Up @@ -2421,19 +2442,29 @@ type UnwrapFragmentRefs<TData> = true extends IsAny<TData> ? TData : TData exten
type UpdateQueries<TData> = MutationOptions<TData, any, any>["updateQueries"];

// @public (undocumented)
type UpdateQueryFn<TData = any, TSubscriptionVariables = OperationVariables, TSubscriptionData = TData> = (previousQueryResult: Unmasked<TData>, options: {
subscriptionData: {
data: Unmasked<TSubscriptionData>;
};
variables?: TSubscriptionVariables;
}) => Unmasked<TData>;
export interface UpdateQueryFn<TData, TVariables extends OperationVariables, TOptions = {}> {
// (undocumented)
(mapFn: UpdateQueryMapFn<TData, TVariables, TOptions>): void;
}

// @public (undocumented)
export interface UpdateQueryOptions<TVariables> {
export interface UpdateQueryMapFn<TData = any, TVariables extends OperationVariables = OperationVariables, TOptions = {}> {
// (undocumented)
variables?: TVariables;
(
previousQueryResult: Unmasked<TData>, options: TOptions & UpdateQueryOptions<TData, TVariables>): Unmasked<TData> | undefined;
}

// @public (undocumented)
export type UpdateQueryOptions<TData, TVariables> = {
variables?: TVariables;
} & ({
complete: true;
previousQueryResult: Unmasked<TData>;
} | {
complete: false;
previousQueryResult: DeepPartial<Unmasked<TData>> | undefined;
});

// @public (undocumented)
export interface UriFunction {
// (undocumented)
Expand Down Expand Up @@ -2508,11 +2539,10 @@ interface WriteContext extends ReadMergeModifyContext {
// src/cache/inmemory/policies.ts:162:3 - (ae-forgotten-export) The symbol "KeySpecifier" needs to be exported by the entry point index.d.ts
// src/cache/inmemory/policies.ts:162:3 - (ae-forgotten-export) The symbol "KeyArgsFunction" needs to be exported by the entry point index.d.ts
// src/cache/inmemory/types.ts:139:3 - (ae-forgotten-export) The symbol "KeyFieldsFunction" needs to be exported by the entry point index.d.ts
// src/core/ObservableQuery.ts:120:5 - (ae-forgotten-export) The symbol "QueryManager" needs to be exported by the entry point index.d.ts
// src/core/ObservableQuery.ts:121:5 - (ae-forgotten-export) The symbol "QueryInfo" needs to be exported by the entry point index.d.ts
// src/core/ObservableQuery.ts:119:5 - (ae-forgotten-export) The symbol "QueryManager" needs to be exported by the entry point index.d.ts
// src/core/ObservableQuery.ts:120:5 - (ae-forgotten-export) The symbol "QueryInfo" needs to be exported by the entry point index.d.ts
// src/core/QueryManager.ts:159:5 - (ae-forgotten-export) The symbol "MutationStoreValue" needs to be exported by the entry point index.d.ts
// src/core/QueryManager.ts:414:7 - (ae-forgotten-export) The symbol "UpdateQueries" needs to be exported by the entry point index.d.ts
// src/core/watchQueryOptions.ts:277:2 - (ae-forgotten-export) The symbol "UpdateQueryFn" needs to be exported by the entry point index.d.ts
// src/link/http/selectHttpOptionsAndBody.ts:128:32 - (ae-forgotten-export) The symbol "HttpQueryOptions" needs to be exported by the entry point index.d.ts

// (No @packageDocumentation comment for this package)
Expand Down
81 changes: 59 additions & 22 deletions .api-reports/api-report-react.api.md
Original file line number Diff line number Diff line change
Expand Up @@ -1429,8 +1429,9 @@ class ObservableQuery<TData = any, TVariables extends OperationVariables = Opera
startPolling(pollInterval: number): void;
stopPolling(): void;
// Warning: (ae-forgotten-export) The symbol "SubscribeToMoreOptions" needs to be exported by the entry point index.d.ts
subscribeToMore<TSubscriptionData = TData, TSubscriptionVariables extends OperationVariables = TVariables>(options: SubscribeToMoreOptions<TData, TSubscriptionVariables, TSubscriptionData>): () => void;
updateQuery<TVars extends OperationVariables = TVariables>(mapFn: (previousQueryResult: Unmasked<TData>, options: Pick<WatchQueryOptions<TVars, TData>, "variables">) => Unmasked<TData>): void;
subscribeToMore<TSubscriptionData = TData, TSubscriptionVariables extends OperationVariables = TVariables>(options: SubscribeToMoreOptions<TData, TSubscriptionVariables, TSubscriptionData, TVariables>): () => void;
// Warning: (ae-forgotten-export) The symbol "UpdateQueryMapFn" needs to be exported by the entry point index.d.ts
updateQuery(mapFn: UpdateQueryMapFn<TData, TVariables>): void;
get variables(): TVariables | undefined;
}

Expand All @@ -1447,8 +1448,10 @@ export interface ObservableQueryFields<TData, TVariables extends OperationVariab
reobserve: (newOptions?: Partial<WatchQueryOptions<TVariables, TData>>, newNetworkStatus?: NetworkStatus) => Promise<ApolloQueryResult<MaybeMasked<TData>>>;
startPolling: (pollInterval: number) => void;
stopPolling: () => void;
subscribeToMore: <TSubscriptionData = TData, TSubscriptionVariables extends OperationVariables = TVariables>(options: SubscribeToMoreOptions<TData, TSubscriptionVariables, TSubscriptionData>) => () => void;
updateQuery: <TVars extends OperationVariables = TVariables>(mapFn: (previousQueryResult: Unmasked<TData>, options: Pick<WatchQueryOptions<TVars, TData>, "variables">) => Unmasked<TData>) => void;
// Warning: (ae-forgotten-export) The symbol "SubscribeToMoreFunction" needs to be exported by the entry point index.d.ts
subscribeToMore: SubscribeToMoreFunction<TData, TVariables>;
// Warning: (ae-forgotten-export) The symbol "UpdateQueryFn" needs to be exported by the entry point index.d.ts
updateQuery: UpdateQueryFn<TData, TVariables>;
variables: TVariables | undefined;
}

Expand Down Expand Up @@ -2088,16 +2091,34 @@ Item
type StoreValue = number | string | string[] | Reference | Reference[] | null | undefined | void | Object;

// @public (undocumented)
type SubscribeToMoreFunction<TData, TVariables extends OperationVariables> = ObservableQueryFields<TData, TVariables>["subscribeToMore"];
interface SubscribeToMoreFunction<TData, TVariables extends OperationVariables = OperationVariables> {
// (undocumented)
<TSubscriptionData = TData, TSubscriptionVariables extends OperationVariables = TVariables>(options: SubscribeToMoreOptions<TData, TSubscriptionVariables, TSubscriptionData, TVariables>): () => void;
}

// @public (undocumented)
type SubscribeToMoreOptions<TData = any, TSubscriptionVariables = OperationVariables, TSubscriptionData = TData> = {
interface SubscribeToMoreOptions<TData = any, TSubscriptionVariables extends OperationVariables = OperationVariables, TSubscriptionData = TData, TVariables extends OperationVariables = TSubscriptionVariables> {
// (undocumented)
context?: Context;
// (undocumented)
document: DocumentNode | TypedDocumentNode<TSubscriptionData, TSubscriptionVariables>;
variables?: TSubscriptionVariables;
updateQuery?: UpdateQueryFn<TData, TSubscriptionVariables, TSubscriptionData>;
// (undocumented)
onError?: (error: Error) => void;
context?: Context;
};
// Warning: (ae-forgotten-export) The symbol "SubscribeToMoreUpdateQueryFn" needs to be exported by the entry point index.d.ts
//
// (undocumented)
updateQuery?: SubscribeToMoreUpdateQueryFn<TData, TVariables, TSubscriptionVariables, TSubscriptionData>;
// (undocumented)
variables?: TSubscriptionVariables;
}

// @public (undocumented)
type SubscribeToMoreUpdateQueryFn<TData = any, TVariables extends OperationVariables = OperationVariables, TSubscriptionVariables extends OperationVariables = TVariables, TSubscriptionData = TData> = UpdateQueryMapFn<TData, TVariables, {
subscriptionData: {
data: Unmasked<TSubscriptionData>;
};
subscriptionVariables: TSubscriptionVariables | undefined;
}>;

// @public (undocumented)
export interface SubscriptionCurrentObservable {
Expand Down Expand Up @@ -2218,12 +2239,30 @@ type UnwrapFragmentRefs<TData> = true extends IsAny<TData> ? TData : TData exten
type UpdateQueries<TData> = MutationOptions<TData, any, any>["updateQueries"];

// @public (undocumented)
type UpdateQueryFn<TData = any, TSubscriptionVariables = OperationVariables, TSubscriptionData = TData> = (previousQueryResult: Unmasked<TData>, options: {
subscriptionData: {
data: Unmasked<TSubscriptionData>;
};
variables?: TSubscriptionVariables;
}) => Unmasked<TData>;
interface UpdateQueryFn<TData, TVariables extends OperationVariables, TOptions = {}> {
// (undocumented)
(mapFn: UpdateQueryMapFn<TData, TVariables, TOptions>): void;
}

// @public (undocumented)
interface UpdateQueryMapFn<TData = any, TVariables extends OperationVariables = OperationVariables, TOptions = {}> {
// Warning: (ae-forgotten-export) The symbol "UpdateQueryOptions" needs to be exported by the entry point index.d.ts
//
// (undocumented)
(
previousQueryResult: Unmasked<TData>, options: TOptions & UpdateQueryOptions<TData, TVariables>): Unmasked<TData> | undefined;
}

// @public (undocumented)
type UpdateQueryOptions<TData, TVariables> = {
variables?: TVariables;
} & ({
complete: true;
previousQueryResult: Unmasked<TData>;
} | {
complete: false;
previousQueryResult: DeepPartial<Unmasked<TData>> | undefined;
});

// @public (undocumented)
interface UriFunction {
Expand Down Expand Up @@ -2520,16 +2559,14 @@ interface WatchQueryOptions<TVariables extends OperationVariables = OperationVar
// src/cache/core/types/common.ts:104:3 - (ae-forgotten-export) The symbol "ToReferenceFunction" needs to be exported by the entry point index.d.ts
// src/cache/core/types/common.ts:105:3 - (ae-forgotten-export) The symbol "StorageType" needs to be exported by the entry point index.d.ts
// src/core/LocalState.ts:46:5 - (ae-forgotten-export) The symbol "FragmentMap" needs to be exported by the entry point index.d.ts
// src/core/ObservableQuery.ts:120:5 - (ae-forgotten-export) The symbol "QueryManager" needs to be exported by the entry point index.d.ts
// src/core/ObservableQuery.ts:121:5 - (ae-forgotten-export) The symbol "QueryInfo" needs to be exported by the entry point index.d.ts
// src/core/ObservableQuery.ts:119:5 - (ae-forgotten-export) The symbol "QueryManager" needs to be exported by the entry point index.d.ts
// src/core/ObservableQuery.ts:120:5 - (ae-forgotten-export) The symbol "QueryInfo" needs to be exported by the entry point index.d.ts
// src/core/QueryManager.ts:159:5 - (ae-forgotten-export) The symbol "MutationStoreValue" needs to be exported by the entry point index.d.ts
// src/core/QueryManager.ts:414:7 - (ae-forgotten-export) The symbol "UpdateQueries" needs to be exported by the entry point index.d.ts
// src/core/types.ts:175:3 - (ae-forgotten-export) The symbol "MutationQueryReducer" needs to be exported by the entry point index.d.ts
// src/core/types.ts:204:5 - (ae-forgotten-export) The symbol "Resolver" needs to be exported by the entry point index.d.ts
// src/core/watchQueryOptions.ts:277:2 - (ae-forgotten-export) The symbol "UpdateQueryFn" needs to be exported by the entry point index.d.ts
// src/react/hooks/useBackgroundQuery.ts:38:3 - (ae-forgotten-export) The symbol "SubscribeToMoreFunction" needs to be exported by the entry point index.d.ts
// src/react/hooks/useBackgroundQuery.ts:54:3 - (ae-forgotten-export) The symbol "FetchMoreFunction" needs to be exported by the entry point index.d.ts
// src/react/hooks/useBackgroundQuery.ts:78:4 - (ae-forgotten-export) The symbol "RefetchFunction" needs to be exported by the entry point index.d.ts
// src/react/hooks/useBackgroundQuery.ts:51:3 - (ae-forgotten-export) The symbol "FetchMoreFunction" needs to be exported by the entry point index.d.ts
// src/react/hooks/useBackgroundQuery.ts:75:4 - (ae-forgotten-export) The symbol "RefetchFunction" needs to be exported by the entry point index.d.ts
// src/react/hooks/useLoadableQuery.ts:120:9 - (ae-forgotten-export) The symbol "ResetFunction" needs to be exported by the entry point index.d.ts

// (No @packageDocumentation comment for this package)
Expand Down
Loading
Loading