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

refactor(angular-query): change query functions to accept an options object instead of an injector #8776

Draft
wants to merge 2 commits into
base: main
Choose a base branch
from

Conversation

dominicbachmann
Copy link

change query functions to accept an options object instead of an injector so that it matches angular APIs such as effect and allows adding more options in the future.

BREAKING CHANGE: The injector option has been replaced with an options object. The injector can now be provided with the options object. Closes #8711

…object instead of an injector

change query functions to accept an options object instead of an injector so that it matches angular APIs such as effect and allows adding more options in the future.

BREAKING CHANGE: The injector option has been replaced with an options object. The injector can now be provided with the options object.
Closes TanStack#8711
@dominicbachmann dominicbachmann force-pushed the enhancement/angular-consistent-injector-options branch from c5074bd to 5e63c55 Compare March 8, 2025 14:25
Copy link

nx-cloud bot commented Mar 9, 2025

View your CI Pipeline Execution ↗ for commit 35647f7.

Command Status Duration Result
nx affected --targets=test:sherif,test:knip,tes... ✅ Succeeded 2m 30s View ↗
nx run-many --target=build --exclude=examples/*... ✅ Succeeded 10s View ↗

☁️ Nx Cloud last updated this comment at 2025-03-09 14:59:19 UTC

Copy link

pkg-pr-new bot commented Mar 9, 2025

Open in Stackblitz

More templates

@tanstack/angular-query-devtools-experimental

npm i https://pkg.pr.new/@tanstack/angular-query-devtools-experimental@8776

@tanstack/angular-query-experimental

npm i https://pkg.pr.new/@tanstack/angular-query-experimental@8776

@tanstack/query-async-storage-persister

npm i https://pkg.pr.new/@tanstack/query-async-storage-persister@8776

@tanstack/query-broadcast-client-experimental

npm i https://pkg.pr.new/@tanstack/query-broadcast-client-experimental@8776

@tanstack/eslint-plugin-query

npm i https://pkg.pr.new/@tanstack/eslint-plugin-query@8776

@tanstack/query-core

npm i https://pkg.pr.new/@tanstack/query-core@8776

@tanstack/query-devtools

npm i https://pkg.pr.new/@tanstack/query-devtools@8776

@tanstack/query-persist-client-core

npm i https://pkg.pr.new/@tanstack/query-persist-client-core@8776

@tanstack/query-sync-storage-persister

npm i https://pkg.pr.new/@tanstack/query-sync-storage-persister@8776

@tanstack/react-query

npm i https://pkg.pr.new/@tanstack/react-query@8776

@tanstack/react-query-devtools

npm i https://pkg.pr.new/@tanstack/react-query-devtools@8776

@tanstack/react-query-next-experimental

npm i https://pkg.pr.new/@tanstack/react-query-next-experimental@8776

@tanstack/react-query-persist-client

npm i https://pkg.pr.new/@tanstack/react-query-persist-client@8776

@tanstack/solid-query

npm i https://pkg.pr.new/@tanstack/solid-query@8776

@tanstack/solid-query-devtools

npm i https://pkg.pr.new/@tanstack/solid-query-devtools@8776

@tanstack/solid-query-persist-client

npm i https://pkg.pr.new/@tanstack/solid-query-persist-client@8776

@tanstack/svelte-query

npm i https://pkg.pr.new/@tanstack/svelte-query@8776

@tanstack/svelte-query-devtools

npm i https://pkg.pr.new/@tanstack/svelte-query-devtools@8776

@tanstack/svelte-query-persist-client

npm i https://pkg.pr.new/@tanstack/svelte-query-persist-client@8776

@tanstack/vue-query

npm i https://pkg.pr.new/@tanstack/vue-query@8776

@tanstack/vue-query-devtools

npm i https://pkg.pr.new/@tanstack/vue-query-devtools@8776

commit: 35647f7

Copy link

codecov bot commented Mar 9, 2025

Codecov Report

Attention: Patch coverage is 71.42857% with 2 lines in your changes missing coverage. Please review.

Project coverage is 88.65%. Comparing base (0511c82) to head (35647f7).
Report is 2 commits behind head on main.

Additional details and impacted files

Impacted file tree graph

@@             Coverage Diff             @@
##             main    #8776       +/-   ##
===========================================
+ Coverage   46.39%   88.65%   +42.26%     
===========================================
  Files         199       16      -183     
  Lines        7551      282     -7269     
  Branches     1732       44     -1688     
===========================================
- Hits         3503      250     -3253     
+ Misses       3668       31     -3637     
+ Partials      380        1      -379     
Components Coverage Δ
@tanstack/angular-query-devtools-experimental ∅ <ø> (∅)
@tanstack/angular-query-experimental 88.65% <71.42%> (ø)
@tanstack/eslint-plugin-query ∅ <ø> (∅)
@tanstack/query-async-storage-persister ∅ <ø> (∅)
@tanstack/query-broadcast-client-experimental ∅ <ø> (∅)
@tanstack/query-codemods ∅ <ø> (∅)
@tanstack/query-core ∅ <ø> (∅)
@tanstack/query-devtools ∅ <ø> (∅)
@tanstack/query-persist-client-core ∅ <ø> (∅)
@tanstack/query-sync-storage-persister ∅ <ø> (∅)
@tanstack/react-query ∅ <ø> (∅)
@tanstack/react-query-devtools ∅ <ø> (∅)
@tanstack/react-query-next-experimental ∅ <ø> (∅)
@tanstack/react-query-persist-client ∅ <ø> (∅)
@tanstack/solid-query ∅ <ø> (∅)
@tanstack/solid-query-devtools ∅ <ø> (∅)
@tanstack/solid-query-persist-client ∅ <ø> (∅)
@tanstack/svelte-query ∅ <ø> (∅)
@tanstack/svelte-query-devtools ∅ <ø> (∅)
@tanstack/svelte-query-persist-client ∅ <ø> (∅)
@tanstack/vue-query ∅ <ø> (∅)
@tanstack/vue-query-devtools ∅ <ø> (∅)
🚀 New features to boost your workflow:
  • Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@@ -313,3 +313,7 @@ export type CreateMutationResult<
* @public
*/
export type NonUndefinedGuard<T> = T extends undefined ? never : T

export type WithOptionalInjector = {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It may seem redundant or not DRY but please give each function its own options type. These should be part of the public API. This reduces the risk of breaking changes, even if only on type level.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Would you put the seperate option types also in the types.ts file?

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No, in the same file as the function.

@@ -17,7 +18,7 @@ import type { InjectOptions } from '@angular/core'
* ```
*/
export function injectQueryClient(
injectOptions: InjectOptions & { injector?: Injector } = {},
injectOptions: InjectOptions & WithOptionalInjector = {},
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No need to change injectQueryClient as it's deprecated and will be removed.

@@ -26,19 +27,19 @@ import type { DevtoolsErrorType } from '@tanstack/query-devtools'
*
* Consider `withDevtools` instead if you don't need this.
* @param optionsFn - A function that returns devtools panel options.
* @param injector - The Angular injector to use.
* @param options - Additional configuration
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let's think of a good name for this parameter - it's confusing if there's an optionsFn parameter and an options parameter.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I called it options because the parameter is also called options in Angular. I also didn't like having a param called optionsFn and options. Would you change it everywhere or just here? What do you think about staticOptions or something in that direction?

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You're right. Maybe we can follow effect from Angular's lead:

export function effect(
  effectFn: (onCleanup: EffectCleanupRegisterFn) => void,
  options?: CreateEffectOptions,

So first parameter e.g. named injectQueryFn, second options. What do you think?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sounds good to me!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Angular: injector parameter needs to be made consistent between all functions
2 participants