Skip to content

Commit 32d1e82

Browse files
authored
docs(angular-query): add jsdoc (#7379)
* fix: remove unused export
1 parent d032247 commit 32d1e82

18 files changed

+439
-34
lines changed

examples/angular/basic/src/app/app.config.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
import { provideHttpClient, withFetch } from '@angular/common/http'
2-
import { ApplicationConfig } from '@angular/core'
32
import {
43
QueryClient,
54
provideAngularQuery,
65
} from '@tanstack/angular-query-experimental'
6+
import type { ApplicationConfig } from '@angular/core'
77

88
export const appConfig: ApplicationConfig = {
99
providers: [

packages/angular-query-devtools-experimental/src/angular-query-devtools.component.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,9 @@ export class AngularQueryDevtools
3939
/*
4040
* It is intentional that there are no default values on inputs.
4141
* Core devtools will set defaults when values are undefined.
42-
* */
42+
*
43+
* Signal inputs are not used to remain compatible with previous Angular versions.
44+
*/
4345

4446
/**
4547
* Add this attribute if you want the dev tools to default to being open

packages/angular-query-experimental/src/__tests__/inject-mutation-state.test.ts

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@ import { QueryClient } from '@tanstack/query-core'
33
import { TestBed } from '@angular/core/testing'
44
import { describe, expect, test, vi } from 'vitest'
55
import { By } from '@angular/platform-browser'
6-
import { JsonPipe } from '@angular/common'
76
import { injectMutation } from '../inject-mutation'
87
import { injectMutationState } from '../inject-mutation-state'
98
import { provideAngularQuery } from '../providers'
@@ -139,7 +138,6 @@ describe('injectMutationState', () => {
139138
}
140139
`,
141140
standalone: true,
142-
imports: [JsonPipe],
143141
})
144142
class FakeComponent {
145143
name = input.required<string>()

packages/angular-query-experimental/src/create-base-query.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ export function createBaseQuery<
3131
TQueryData,
3232
TQueryKey extends QueryKey,
3333
>(
34-
options: (
34+
optionsFn: (
3535
client: QueryClient,
3636
) => CreateBaseQueryOptions<
3737
TQueryFnData,
@@ -57,7 +57,7 @@ export function createBaseQuery<
5757
*/
5858
const defaultedOptionsSignal = computed(() => {
5959
const defaultedOptions = queryClient.defaultQueryOptions(
60-
options(queryClient),
60+
optionsFn(queryClient),
6161
)
6262
defaultedOptions._optimisticResults = 'optimistic'
6363
return defaultedOptions

packages/angular-query-experimental/src/index.ts

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -20,9 +20,5 @@ export * from './inject-mutation'
2020
export * from './inject-mutation-state'
2121
export * from './inject-queries'
2222
export * from './inject-query'
23-
export {
24-
injectQueryClient,
25-
provideQueryClient,
26-
QUERY_CLIENT,
27-
} from './inject-query-client'
23+
export { injectQueryClient, provideQueryClient } from './inject-query-client'
2824
export { provideAngularQuery } from './providers'

packages/angular-query-experimental/src/infinite-query-options.ts

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,14 @@ export type DefinedInitialDataInfiniteOptions<
4141
| (() => NonUndefinedGuard<InfiniteData<TQueryFnData, TPageParam>>)
4242
}
4343

44+
/**
45+
* Allows to share and re-use infinite query options in a type-safe way.
46+
*
47+
* The `queryKey` will be tagged with the type from `queryFn`.
48+
* @param options - The infinite query options to tag with the type from `queryFn`.
49+
* @returns The tagged infinite query options.
50+
* @public
51+
*/
4452
export function infiniteQueryOptions<
4553
TQueryFnData,
4654
TError = DefaultError,
@@ -65,6 +73,14 @@ export function infiniteQueryOptions<
6573
queryKey: DataTag<TQueryKey, InfiniteData<TQueryFnData>>
6674
}
6775

76+
/**
77+
* Allows to share and re-use infinite query options in a type-safe way.
78+
*
79+
* The `queryKey` will be tagged with the type from `queryFn`.
80+
* @param options - The infinite query options to tag with the type from `queryFn`.
81+
* @returns The tagged infinite query options.
82+
* @public
83+
*/
6884
export function infiniteQueryOptions<
6985
TQueryFnData,
7086
TError = DefaultError,
@@ -89,6 +105,14 @@ export function infiniteQueryOptions<
89105
queryKey: DataTag<TQueryKey, InfiniteData<TQueryFnData>>
90106
}
91107

108+
/**
109+
* Allows to share and re-use infinite query options in a type-safe way.
110+
*
111+
* The `queryKey` will be tagged with the type from `queryFn`.
112+
* @param options - The infinite query options to tag with the type from `queryFn`.
113+
* @returns The tagged infinite query options.
114+
* @public
115+
*/
92116
export function infiniteQueryOptions(options: unknown) {
93117
return options
94118
}

packages/angular-query-experimental/src/inject-infinite-query.ts

Lines changed: 37 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -20,14 +20,22 @@ import type {
2020
UndefinedInitialDataInfiniteOptions,
2121
} from './infinite-query-options'
2222

23+
/**
24+
* Injects an infinite query: a declarative dependency on an asynchronous source of data that is tied to a unique key.
25+
* Infinite queries can additively "load more" data onto an existing set of data or "infinite scroll"
26+
* @param optionsFn - A function that returns infinite query options.
27+
* @param injector - The Angular injector to use.
28+
* @returns The infinite query result.
29+
* @public
30+
*/
2331
export function injectInfiniteQuery<
2432
TQueryFnData,
2533
TError = DefaultError,
2634
TData = InfiniteData<TQueryFnData>,
2735
TQueryKey extends QueryKey = QueryKey,
2836
TPageParam = unknown,
2937
>(
30-
options: (
38+
optionsFn: (
3139
client: QueryClient,
3240
) => UndefinedInitialDataInfiniteOptions<
3341
TQueryFnData,
@@ -39,14 +47,22 @@ export function injectInfiniteQuery<
3947
injector?: Injector,
4048
): CreateInfiniteQueryResult<TData, TError>
4149

50+
/**
51+
* Injects an infinite query: a declarative dependency on an asynchronous source of data that is tied to a unique key.
52+
* Infinite queries can additively "load more" data onto an existing set of data or "infinite scroll"
53+
* @param optionsFn - A function that returns infinite query options.
54+
* @param injector - The Angular injector to use.
55+
* @returns The infinite query result.
56+
* @public
57+
*/
4258
export function injectInfiniteQuery<
4359
TQueryFnData,
4460
TError = DefaultError,
4561
TData = InfiniteData<TQueryFnData>,
4662
TQueryKey extends QueryKey = QueryKey,
4763
TPageParam = unknown,
4864
>(
49-
options: (
65+
optionsFn: (
5066
client: QueryClient,
5167
) => DefinedInitialDataInfiniteOptions<
5268
TQueryFnData,
@@ -58,14 +74,22 @@ export function injectInfiniteQuery<
5874
injector?: Injector,
5975
): DefinedCreateInfiniteQueryResult<TData, TError>
6076

77+
/**
78+
* Injects an infinite query: a declarative dependency on an asynchronous source of data that is tied to a unique key.
79+
* Infinite queries can additively "load more" data onto an existing set of data or "infinite scroll"
80+
* @param optionsFn - A function that returns infinite query options.
81+
* @param injector - The Angular injector to use.
82+
* @returns The infinite query result.
83+
* @public
84+
*/
6185
export function injectInfiniteQuery<
6286
TQueryFnData,
6387
TError = DefaultError,
6488
TData = InfiniteData<TQueryFnData>,
6589
TQueryKey extends QueryKey = QueryKey,
6690
TPageParam = unknown,
6791
>(
68-
options: (
92+
optionsFn: (
6993
client: QueryClient,
7094
) => CreateInfiniteQueryOptions<
7195
TQueryFnData,
@@ -78,14 +102,22 @@ export function injectInfiniteQuery<
78102
injector?: Injector,
79103
): CreateInfiniteQueryResult<TData, TError>
80104

105+
/**
106+
* Injects an infinite query: a declarative dependency on an asynchronous source of data that is tied to a unique key.
107+
* Infinite queries can additively "load more" data onto an existing set of data or "infinite scroll"
108+
* @param optionsFn - A function that returns infinite query options.
109+
* @param injector - The Angular injector to use.
110+
* @returns The infinite query result.
111+
* @public
112+
*/
81113
export function injectInfiniteQuery(
82-
options: (client: QueryClient) => CreateInfiniteQueryOptions,
114+
optionsFn: (client: QueryClient) => CreateInfiniteQueryOptions,
83115
injector?: Injector,
84116
) {
85117
return assertInjector(injectInfiniteQuery, injector, () => {
86118
const queryClient = injectQueryClient()
87119
return createBaseQuery(
88-
options,
120+
optionsFn,
89121
InfiniteQueryObserver as typeof QueryObserver,
90122
queryClient,
91123
)

packages/angular-query-experimental/src/inject-is-fetching.ts

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,16 @@ import { assertInjector } from './util/assert-injector/assert-injector'
44
import { injectQueryClient } from './inject-query-client'
55
import type { Injector, Signal } from '@angular/core'
66

7+
/**
8+
* Injects a signal that tracks the number of queries that your application is loading or
9+
* fetching in the background.
10+
*
11+
* Can be used for app-wide loading indicators
12+
* @param filters - The filters to apply to the query.
13+
* @param injector - The Angular injector to use.
14+
* @returns signal with number of loading or fetching queries.
15+
* @public
16+
*/
717
export function injectIsFetching(
818
filters?: QueryFilters,
919
injector?: Injector,

packages/angular-query-experimental/src/inject-is-mutating.ts

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,15 @@ import { assertInjector } from './util/assert-injector/assert-injector'
44
import { injectQueryClient } from './inject-query-client'
55
import type { Injector, Signal } from '@angular/core'
66

7+
/**
8+
* Injects a signal that tracks the number of mutations that your application is fetching.
9+
*
10+
* Can be used for app-wide loading indicators
11+
* @param filters - The filters to apply to the query.
12+
* @param injector - The Angular injector to use.
13+
* @returns signal with number of fetching mutations.
14+
* @public
15+
*/
716
export function injectIsMutating(
817
filters?: MutationFilters,
918
injector?: Injector,

packages/angular-query-experimental/src/inject-mutation-state.ts

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,10 +43,20 @@ function getResult<TResult = MutationState>(
4343
)
4444
}
4545

46+
/**
47+
* @public
48+
*/
4649
export interface InjectMutationStateOptions {
4750
injector?: Injector
4851
}
4952

53+
/**
54+
* Injects a signal that tracks the state of all mutations.
55+
* @param mutationStateOptionsFn - A function that returns mutation state options.
56+
* @param options - The Angular injector to use.
57+
* @returns The signal that tracks the state of all mutations.
58+
* @public
59+
*/
5060
export function injectMutationState<TResult = MutationState>(
5161
mutationStateOptionsFn: () => MutationStateOptions<TResult> = () => ({}),
5262
options?: InjectMutationStateOptions,

packages/angular-query-experimental/src/inject-mutation.ts

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -26,13 +26,22 @@ import type {
2626
CreateMutationResult,
2727
} from './types'
2828

29+
/**
30+
* Injects a mutation: an imperative function that can be invoked which typically performs server side effects.
31+
*
32+
* Unlike queries, mutations are not run automatically.
33+
* @param optionsFn - A function that returns mutation options.
34+
* @param injector - The Angular injector to use.
35+
* @returns The mutation.
36+
* @public
37+
*/
2938
export function injectMutation<
3039
TData = unknown,
3140
TError = DefaultError,
3241
TVariables = void,
3342
TContext = unknown,
3443
>(
35-
options: (
44+
optionsFn: (
3645
client: QueryClient,
3746
) => CreateMutationOptions<TData, TError, TVariables, TContext>,
3847
injector?: Injector,
@@ -50,7 +59,7 @@ export function injectMutation<
5059
TError,
5160
TVariables,
5261
TContext
53-
>(queryClient, options(queryClient))
62+
>(queryClient, optionsFn(queryClient))
5463
const mutate: CreateMutateFunction<
5564
TData,
5665
TError,
@@ -61,7 +70,7 @@ export function injectMutation<
6170
}
6271

6372
effect(() => {
64-
observer.setOptions(options(queryClient))
73+
observer.setOptions(optionsFn(queryClient))
6574
})
6675

6776
const result = signal(observer.getCurrentResult())

packages/angular-query-experimental/src/inject-queries.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -119,6 +119,7 @@ type GetResults<T> =
119119

120120
/**
121121
* QueriesOptions reducer recursively unwraps function arguments to infer/enforce type param
122+
* @public
122123
*/
123124
export type QueriesOptions<
124125
T extends Array<any>,
@@ -161,6 +162,7 @@ export type QueriesOptions<
161162

162163
/**
163164
* QueriesResults reducer recursively maps type param to results
165+
* @public
164166
*/
165167
export type QueriesResults<
166168
T extends Array<any>,
@@ -196,6 +198,9 @@ export type QueriesResults<
196198
: // Fallback
197199
Array<QueryObserverResult>
198200

201+
/**
202+
* @public
203+
*/
199204
export function injectQueries<
200205
T extends Array<any>,
201206
TCombinedResult = QueriesResults<T>,
Lines changed: 21 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,25 @@
11
import { createNoopInjectionToken } from './util/create-injection-token/create-injection-token'
22
import type { QueryClient } from '@tanstack/query-core'
33

4-
const [injectQueryClient, provideQueryClient, QUERY_CLIENT] =
5-
createNoopInjectionToken<QueryClient>('QueryClientToken')
4+
const tokens = createNoopInjectionToken<QueryClient>('QueryClientToken')
65

7-
export { injectQueryClient, provideQueryClient, QUERY_CLIENT }
6+
/**
7+
* Injects the `QueryClient` instance into the component or service.
8+
*
9+
* **Example**
10+
* ```ts
11+
* const queryClient = injectQueryClient();
12+
* ```
13+
* @returns The `QueryClient` instance.
14+
* @public
15+
*/
16+
export const injectQueryClient = tokens[0]
17+
18+
/**
19+
* Usually {@link provideAngularQuery} is used once to set up TanStack Query and the
20+
* {@link https://tanstack.com/query/latest/docs/reference/QueryClient|QueryClient}
21+
* for the entire application. You can use `provideQueryClient` to provide a
22+
* different `QueryClient` instance for a part of the application.
23+
* @public
24+
*/
25+
export const provideQueryClient = tokens[1]

0 commit comments

Comments
 (0)