Skip to content

Commit

Permalink
deprecate use(Lazy)Query on(Error|Completed) callbacks (#12340)
Browse files Browse the repository at this point in the history
* deprecate `use(Lazy)Query` `on(Error|Completed)` callbacks

* changeset

* Apply suggestions from code review

Co-authored-by: Jerel Miller <[email protected]>

* Update src/react/types/deprecation.md

Co-authored-by: Jerel Miller <[email protected]>

* Apply suggestions from code review

* Update src/react/types/deprecation.md

* Update src/react/types/deprecation.md

* Slight tweaks to changes around behavior section

* Slight tweak to defer section

* Add section on our recommendation

* Update section for bugs

* Minor tweak to solutions section

* Mention switch in behavior

* Slight tweak to end

* remove draft file, add links to issue

* api-extractor

---------

Co-authored-by: Jerel Miller <[email protected]>
  • Loading branch information
phryneas and jerelmiller authored Feb 7, 2025
1 parent 67c16c9 commit 716d02e
Show file tree
Hide file tree
Showing 9 changed files with 50 additions and 4 deletions.
4 changes: 4 additions & 0 deletions .api-reports/api-report-react.api.md
Original file line number Diff line number Diff line change
Expand Up @@ -1048,7 +1048,9 @@ export interface LazyQueryHookExecOptions<TData = any, TVariables extends Operat
export interface LazyQueryHookOptions<TData = any, TVariables extends OperationVariables = OperationVariables> extends BaseQueryOptions<TVariables, TData> {
// @internal (undocumented)
defaultOptions?: Partial<WatchQueryOptions<TVariables, TData>>;
// @deprecated
onCompleted?: (data: MaybeMasked<TData>) => void;
// @deprecated
onError?: (error: ApolloError) => void;
}

Expand Down Expand Up @@ -1596,7 +1598,9 @@ export interface QueryDataOptions<TData = any, TVariables extends OperationVaria
export interface QueryFunctionOptions<TData = any, TVariables extends OperationVariables = OperationVariables> extends BaseQueryOptions<TVariables, TData> {
// @internal (undocumented)
defaultOptions?: Partial<WatchQueryOptions<TVariables, TData>>;
// @deprecated
onCompleted?: (data: MaybeMasked<TData>) => void;
// @deprecated
onError?: (error: ApolloError) => void;
skip?: boolean;
}
Expand Down
2 changes: 2 additions & 0 deletions .api-reports/api-report-react_components.api.md
Original file line number Diff line number Diff line change
Expand Up @@ -1419,7 +1419,9 @@ export interface QueryComponentOptions<TData = any, TVariables extends Operation
interface QueryFunctionOptions<TData = any, TVariables extends OperationVariables = OperationVariables> extends BaseQueryOptions<TVariables, TData> {
// @internal (undocumented)
defaultOptions?: Partial<WatchQueryOptions<TVariables, TData>>;
// @deprecated
onCompleted?: (data: MaybeMasked<TData>) => void;
// @deprecated
onError?: (error: ApolloError) => void;
skip?: boolean;
}
Expand Down
2 changes: 2 additions & 0 deletions .api-reports/api-report-react_context.api.md
Original file line number Diff line number Diff line change
Expand Up @@ -1346,7 +1346,9 @@ interface QueryDataOptions<TData = any, TVariables extends OperationVariables =
interface QueryFunctionOptions<TData = any, TVariables extends OperationVariables = OperationVariables> extends BaseQueryOptions<TVariables, TData> {
// @internal (undocumented)
defaultOptions?: Partial<WatchQueryOptions<TVariables, TData>>;
// @deprecated
onCompleted?: (data: MaybeMasked<TData>) => void;
// @deprecated
onError?: (error: ApolloError) => void;
skip?: boolean;
}
Expand Down
4 changes: 4 additions & 0 deletions .api-reports/api-report-react_hooks.api.md
Original file line number Diff line number Diff line change
Expand Up @@ -997,7 +997,9 @@ interface LazyQueryHookExecOptions<TData = any, TVariables extends OperationVari
interface LazyQueryHookOptions<TData = any, TVariables extends OperationVariables = OperationVariables> extends BaseQueryOptions<TVariables, TData> {
// @internal (undocumented)
defaultOptions?: Partial<WatchQueryOptions<TVariables, TData>>;
// @deprecated
onCompleted?: (data: MaybeMasked<TData>) => void;
// @deprecated
onError?: (error: ApolloError) => void;
}

Expand Down Expand Up @@ -1469,7 +1471,9 @@ const QUERY_REF_BRAND: unique symbol;
interface QueryFunctionOptions<TData = any, TVariables extends OperationVariables = OperationVariables> extends BaseQueryOptions<TVariables, TData> {
// @internal (undocumented)
defaultOptions?: Partial<WatchQueryOptions<TVariables, TData>>;
// @deprecated
onCompleted?: (data: MaybeMasked<TData>) => void;
// @deprecated
onError?: (error: ApolloError) => void;
skip?: boolean;
}
Expand Down
2 changes: 2 additions & 0 deletions .api-reports/api-report-react_internal.api.md
Original file line number Diff line number Diff line change
Expand Up @@ -1566,7 +1566,9 @@ const QUERY_REFERENCE_SYMBOL: unique symbol;
interface QueryFunctionOptions<TData = any, TVariables extends OperationVariables = OperationVariables> extends BaseQueryOptions<TVariables, TData> {
// @internal (undocumented)
defaultOptions?: Partial<WatchQueryOptions<TVariables, TData>>;
// @deprecated
onCompleted?: (data: MaybeMasked<TData>) => void;
// @deprecated
onError?: (error: ApolloError) => void;
skip?: boolean;
}
Expand Down
2 changes: 2 additions & 0 deletions .api-reports/api-report-react_ssr.api.md
Original file line number Diff line number Diff line change
Expand Up @@ -1331,7 +1331,9 @@ interface QueryDataOptions<TData = any, TVariables extends OperationVariables =
interface QueryFunctionOptions<TData = any, TVariables extends OperationVariables = OperationVariables> extends BaseQueryOptions<TVariables, TData> {
// @internal (undocumented)
defaultOptions?: Partial<WatchQueryOptions<TVariables, TData>>;
// @deprecated
onCompleted?: (data: MaybeMasked<TData>) => void;
// @deprecated
onError?: (error: ApolloError) => void;
skip?: boolean;
}
Expand Down
4 changes: 4 additions & 0 deletions .api-reports/api-report.api.md
Original file line number Diff line number Diff line change
Expand Up @@ -1465,7 +1465,9 @@ export interface LazyQueryHookExecOptions<TData = any, TVariables extends Operat
export interface LazyQueryHookOptions<TData = any, TVariables extends OperationVariables = OperationVariables> extends BaseQueryOptions<TVariables, TData> {
// @internal (undocumented)
defaultOptions?: Partial<WatchQueryOptions<TVariables, TData>>;
// @deprecated
onCompleted?: (data: MaybeMasked<TData>) => void;
// @deprecated
onError?: (error: ApolloError) => void;
}

Expand Down Expand Up @@ -2180,7 +2182,9 @@ export interface QueryDataOptions<TData = any, TVariables extends OperationVaria
export interface QueryFunctionOptions<TData = any, TVariables extends OperationVariables = OperationVariables> extends BaseQueryOptions<TVariables, TData> {
// @internal (undocumented)
defaultOptions?: Partial<WatchQueryOptions<TVariables, TData>>;
// @deprecated
onCompleted?: (data: MaybeMasked<TData>) => void;
// @deprecated
onError?: (error: ApolloError) => void;
skip?: boolean;
}
Expand Down
6 changes: 6 additions & 0 deletions .changeset/heavy-pumas-boil.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
---
"@apollo/client": minor
---

Deprecate the `onCompleted` and `onError` callbacks of `useQuery` and `useLazyQuery`.
For more context, please see the [related issue](https://github.com/apollographql/apollo-client/issues/12352) on GitHub.
28 changes: 24 additions & 4 deletions src/react/types/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -68,9 +68,19 @@ export interface QueryFunctionOptions<
> extends BaseQueryOptions<TVariables, TData> {
/** {@inheritDoc @apollo/client!QueryOptionsDocumentation#skip:member} */
skip?: boolean;
/** {@inheritDoc @apollo/client!QueryOptionsDocumentation#onCompleted:member} */
/**
* {@inheritDoc @apollo/client!QueryOptionsDocumentation#onCompleted:member}
*
* @deprecated This option will be removed in the next major version of Apollo Client.
* For more context, please see the [related issue](https://github.com/apollographql/apollo-client/issues/12352) on GitHub.
*/
onCompleted?: (data: MaybeMasked<TData>) => void;
/** {@inheritDoc @apollo/client!QueryOptionsDocumentation#onError:member} */
/**
* {@inheritDoc @apollo/client!QueryOptionsDocumentation#onError:member}
*
* @deprecated This option will be removed in the next major version of Apollo Client.
* For more context, please see the [related issue](https://github.com/apollographql/apollo-client/issues/12352) on GitHub.
*/
onError?: (error: ApolloError) => void;

// Default WatchQueryOptions for this useQuery, providing initial values for
Expand Down Expand Up @@ -167,9 +177,19 @@ export interface LazyQueryHookOptions<
TData = any,
TVariables extends OperationVariables = OperationVariables,
> extends BaseQueryOptions<TVariables, TData> {
/** {@inheritDoc @apollo/client!QueryOptionsDocumentation#onCompleted:member} */
/**
* {@inheritDoc @apollo/client!QueryOptionsDocumentation#onCompleted:member}
*
* @deprecated This option will be removed in the next major version of Apollo Client.
* For more context, please see the [related issue](https://github.com/apollographql/apollo-client/issues/12352) on GitHub.
*/
onCompleted?: (data: MaybeMasked<TData>) => void;
/** {@inheritDoc @apollo/client!QueryOptionsDocumentation#onError:member} */
/**
* {@inheritDoc @apollo/client!QueryOptionsDocumentation#onError:member}
*
* @deprecated This option will be removed in the next major version of Apollo Client.
* For more context, please see the [related issue](https://github.com/apollographql/apollo-client/issues/12352) on GitHub.
*/
onError?: (error: ApolloError) => void;

/** @internal */
Expand Down

0 comments on commit 716d02e

Please sign in to comment.