Skip to content

Commit 963801c

Browse files
committed
Merge branch 'main' into implement-simplified-imperitive-methods
2 parents 8cba588 + ef62f7b commit 963801c

113 files changed

Lines changed: 2644 additions & 2607 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

packages/angular-query-experimental/src/__tests__/infinite-query-options.test-d.ts

Lines changed: 37 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import { assertType, describe, expectTypeOf, it, test } from 'vitest'
2+
import { queryKey } from '@tanstack/query-test-utils'
23
import { QueryClient, dataTagSymbol } from '@tanstack/query-core'
34
import { infiniteQueryOptions } from '../infinite-query-options'
45
import { injectInfiniteQuery } from '../inject-infinite-query'
@@ -11,9 +12,10 @@ import type {
1112

1213
describe('infiniteQueryOptions', () => {
1314
it('should not allow excess properties', () => {
15+
const key = queryKey()
1416
assertType(
1517
infiniteQueryOptions({
16-
queryKey: ['key'],
18+
queryKey: key,
1719
queryFn: () => Promise.resolve('data'),
1820
getNextPageParam: () => 1,
1921
initialPageParam: 1,
@@ -23,8 +25,9 @@ describe('infiniteQueryOptions', () => {
2325
)
2426
})
2527
it('should infer types for callbacks', () => {
28+
const key = queryKey()
2629
infiniteQueryOptions({
27-
queryKey: ['key'],
30+
queryKey: key,
2831
queryFn: () => Promise.resolve('data'),
2932
staleTime: 1000,
3033
getNextPageParam: () => 1,
@@ -35,8 +38,9 @@ describe('infiniteQueryOptions', () => {
3538
})
3639
})
3740
it('should work when passed to useInfiniteQuery', () => {
41+
const key = queryKey()
3842
const options = infiniteQueryOptions({
39-
queryKey: ['key'],
43+
queryKey: key,
4044
queryFn: () => Promise.resolve('string'),
4145
getNextPageParam: () => 1,
4246
initialPageParam: 1,
@@ -51,8 +55,9 @@ describe('infiniteQueryOptions', () => {
5155
})
5256

5357
it('should work when passed to fetchInfiniteQuery', async () => {
58+
const key = queryKey()
5459
const options = infiniteQueryOptions({
55-
queryKey: ['key'],
60+
queryKey: key,
5661
queryFn: () => Promise.resolve('string'),
5762
getNextPageParam: () => 1,
5863
initialPageParam: 1,
@@ -91,61 +96,66 @@ describe('infiniteQueryOptions', () => {
9196
})
9297

9398
it('should tag the queryKey with the result type of the QueryFn', () => {
94-
const { queryKey } = infiniteQueryOptions({
95-
queryKey: ['key'],
99+
const key = queryKey()
100+
const { queryKey: tagged } = infiniteQueryOptions({
101+
queryKey: key,
96102
queryFn: () => Promise.resolve('string'),
97103
getNextPageParam: () => 1,
98104
initialPageParam: 1,
99105
})
100106

101-
expectTypeOf(queryKey[dataTagSymbol]).toEqualTypeOf<InfiniteData<string>>()
107+
expectTypeOf(tagged[dataTagSymbol]).toEqualTypeOf<InfiniteData<string>>()
102108
})
103109
it('should tag the queryKey even if no promise is returned', () => {
104-
const { queryKey } = infiniteQueryOptions({
105-
queryKey: ['key'],
110+
const key = queryKey()
111+
const { queryKey: tagged } = infiniteQueryOptions({
112+
queryKey: key,
106113
queryFn: () => 'string',
107114
getNextPageParam: () => 1,
108115
initialPageParam: 1,
109116
})
110117

111-
expectTypeOf(queryKey[dataTagSymbol]).toEqualTypeOf<InfiniteData<string>>()
118+
expectTypeOf(tagged[dataTagSymbol]).toEqualTypeOf<InfiniteData<string>>()
112119
})
113120
it('should tag the queryKey with the result type of the QueryFn if select is used', () => {
114-
const { queryKey } = infiniteQueryOptions({
115-
queryKey: ['key'],
121+
const key = queryKey()
122+
const { queryKey: tagged } = infiniteQueryOptions({
123+
queryKey: key,
116124
queryFn: () => Promise.resolve('string'),
117125
select: (data) => data.pages,
118126
getNextPageParam: () => 1,
119127
initialPageParam: 1,
120128
})
121129

122-
expectTypeOf(queryKey[dataTagSymbol]).toEqualTypeOf<InfiniteData<string>>()
130+
expectTypeOf(tagged[dataTagSymbol]).toEqualTypeOf<InfiniteData<string>>()
123131
})
124132
it('should return the proper type when passed to getQueryData', () => {
125-
const { queryKey } = infiniteQueryOptions({
126-
queryKey: ['key'],
133+
const key = queryKey()
134+
const { queryKey: tagged } = infiniteQueryOptions({
135+
queryKey: key,
127136
queryFn: () => Promise.resolve('string'),
128137
getNextPageParam: () => 1,
129138
initialPageParam: 1,
130139
})
131140

132141
const queryClient = new QueryClient()
133-
const data = queryClient.getQueryData(queryKey)
142+
const data = queryClient.getQueryData(tagged)
134143

135144
expectTypeOf(data).toEqualTypeOf<
136145
InfiniteData<string, unknown> | undefined
137146
>()
138147
})
139148
it('should properly type when passed to setQueryData', () => {
140-
const { queryKey } = infiniteQueryOptions({
141-
queryKey: ['key'],
149+
const key = queryKey()
150+
const { queryKey: tagged } = infiniteQueryOptions({
151+
queryKey: key,
142152
queryFn: () => Promise.resolve('string'),
143153
getNextPageParam: () => 1,
144154
initialPageParam: 1,
145155
})
146156

147157
const queryClient = new QueryClient()
148-
const data = queryClient.setQueryData(queryKey, (prev) => {
158+
const data = queryClient.setQueryData(tagged, (prev) => {
149159
expectTypeOf(prev).toEqualTypeOf<
150160
InfiniteData<string, unknown> | undefined
151161
>()
@@ -158,9 +168,10 @@ describe('infiniteQueryOptions', () => {
158168
})
159169

160170
test('should not be allowed to be passed to non-infinite query functions', () => {
171+
const key = queryKey()
161172
const queryClient = new QueryClient()
162173
const options = infiniteQueryOptions({
163-
queryKey: ['key'],
174+
queryKey: key,
164175
queryFn: () => Promise.resolve('string'),
165176
getNextPageParam: () => 1,
166177
initialPageParam: 1,
@@ -184,35 +195,37 @@ describe('infiniteQueryOptions', () => {
184195
})
185196

186197
test('allow optional initialData function', () => {
198+
const key = queryKey()
187199
const initialData: { example: boolean } | undefined = { example: true }
188200
const queryOptions = infiniteQueryOptions({
189-
queryKey: ['example'],
201+
queryKey: key,
190202
queryFn: () => initialData,
191203
initialData: initialData
192204
? () => ({ pages: [initialData], pageParams: [] })
193205
: undefined,
194206
getNextPageParam: () => 1,
195207
initialPageParam: 1,
196208
})
197-
expectTypeOf(queryOptions.initialData).toMatchTypeOf<
209+
expectTypeOf(queryOptions.initialData).toExtend<
198210
| InitialDataFunction<InfiniteData<{ example: boolean }, number>>
199211
| InfiniteData<{ example: boolean }, number>
200212
| undefined
201213
>()
202214
})
203215

204216
test('allow optional initialData object', () => {
217+
const key = queryKey()
205218
const initialData: { example: boolean } | undefined = { example: true }
206219
const queryOptions = infiniteQueryOptions({
207-
queryKey: ['example'],
220+
queryKey: key,
208221
queryFn: () => initialData,
209222
initialData: initialData
210223
? { pages: [initialData], pageParams: [] }
211224
: undefined,
212225
getNextPageParam: () => 1,
213226
initialPageParam: 1,
214227
})
215-
expectTypeOf(queryOptions.initialData).toMatchTypeOf<
228+
expectTypeOf(queryOptions.initialData).toExtend<
216229
| InitialDataFunction<InfiniteData<{ example: boolean }, number>>
217230
| InfiniteData<{ example: boolean }, number>
218231
| undefined

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

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,14 @@
11
import { describe, expect, it } from 'vitest'
2+
import { queryKey } from '@tanstack/query-test-utils'
23

34
import { infiniteQueryOptions } from '../infinite-query-options'
45
import type { CreateInfiniteQueryOptions } from '../types'
56

67
describe('infiniteQueryOptions', () => {
78
it('should return the object received as a parameter without any modification.', () => {
9+
const key = queryKey()
810
const object: CreateInfiniteQueryOptions = {
9-
queryKey: ['key'],
11+
queryKey: key,
1012
queryFn: () => Promise.resolve(5),
1113
getNextPageParam: () => null,
1214
initialPageParam: null,

packages/angular-query-experimental/src/__tests__/inject-infinite-query.test-d.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import { TestBed } from '@angular/core/testing'
22
import { afterEach, beforeEach, describe, expectTypeOf, test, vi } from 'vitest'
33
import { provideZonelessChangeDetection } from '@angular/core'
4-
import { sleep } from '@tanstack/query-test-utils'
4+
import { queryKey, sleep } from '@tanstack/query-test-utils'
55
import { QueryClient, injectInfiniteQuery, provideTanStackQuery } from '..'
66
import type { InfiniteData } from '@tanstack/query-core'
77

@@ -24,9 +24,10 @@ describe('injectInfiniteQuery', () => {
2424
})
2525

2626
test('should narrow type after isSuccess', () => {
27+
const key = queryKey()
2728
const query = TestBed.runInInjectionContext(() => {
2829
return injectInfiniteQuery(() => ({
29-
queryKey: ['infiniteQuery'],
30+
queryKey: key,
3031
queryFn: ({ pageParam }) =>
3132
sleep(0).then(() => 'data on page ' + pageParam),
3233
initialPageParam: 0,

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

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import { TestBed } from '@angular/core/testing'
22
import { afterEach, beforeEach, describe, expect, test, vi } from 'vitest'
33
import { Injector, provideZonelessChangeDetection } from '@angular/core'
4-
import { sleep } from '@tanstack/query-test-utils'
4+
import { queryKey, sleep } from '@tanstack/query-test-utils'
55
import { QueryClient, injectInfiniteQuery, provideTanStackQuery } from '..'
66
import { expectSignals } from './test-utils'
77

@@ -24,9 +24,10 @@ describe('injectInfiniteQuery', () => {
2424
})
2525

2626
test('should properly execute infinite query', async () => {
27+
const key = queryKey()
2728
const query = TestBed.runInInjectionContext(() => {
2829
return injectInfiniteQuery(() => ({
29-
queryKey: ['infiniteQuery'],
30+
queryKey: key,
3031
queryFn: ({ pageParam }) =>
3132
sleep(10).then(() => 'data on page ' + pageParam),
3233
initialPageParam: 0,
@@ -64,21 +65,23 @@ describe('injectInfiniteQuery', () => {
6465

6566
describe('injection context', () => {
6667
test('throws NG0203 with descriptive error outside injection context', () => {
68+
const key = queryKey()
6769
expect(() => {
6870
injectInfiniteQuery(() => ({
69-
queryKey: ['injectionContextError'],
71+
queryKey: key,
7072
queryFn: ({ pageParam }) =>
7173
sleep(0).then(() => 'data on page ' + pageParam),
7274
initialPageParam: 0,
7375
getNextPageParam: () => 12,
7476
}))
75-
}).toThrowError(/NG0203(.*?)injectInfiniteQuery/)
77+
}).toThrow(/NG0203(.*?)injectInfiniteQuery/)
7678
})
7779

7880
test('can be used outside injection context when passing an injector', () => {
81+
const key = queryKey()
7982
const query = injectInfiniteQuery(
8083
() => ({
81-
queryKey: ['manualInjector'],
84+
queryKey: key,
8285
queryFn: ({ pageParam }) =>
8386
sleep(0).then(() => 'data on page ' + pageParam),
8487
initialPageParam: 0,

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

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import { TestBed } from '@angular/core/testing'
22
import { afterEach, beforeEach, describe, expect, test, vi } from 'vitest'
33
import { Injector, provideZonelessChangeDetection } from '@angular/core'
4-
import { sleep } from '@tanstack/query-test-utils'
4+
import { queryKey, sleep } from '@tanstack/query-test-utils'
55
import {
66
QueryClient,
77
injectIsFetching,
@@ -29,9 +29,10 @@ describe('injectIsFetching', () => {
2929
})
3030

3131
test('Returns number of fetching queries', async () => {
32+
const key = queryKey()
3233
const isFetching = TestBed.runInInjectionContext(() => {
3334
injectQuery(() => ({
34-
queryKey: ['isFetching1'],
35+
queryKey: key,
3536
queryFn: () => sleep(100).then(() => 'Some data'),
3637
}))
3738
return injectIsFetching()
@@ -48,7 +49,7 @@ describe('injectIsFetching', () => {
4849
test('throws NG0203 with descriptive error outside injection context', () => {
4950
expect(() => {
5051
injectIsFetching()
51-
}).toThrowError(/NG0203(.*?)injectIsFetching/)
52+
}).toThrow(/NG0203(.*?)injectIsFetching/)
5253
})
5354

5455
test('can be used outside injection context when passing an injector', () => {

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

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import { afterEach, beforeEach, describe, expect, test, vi } from 'vitest'
22
import { TestBed } from '@angular/core/testing'
33
import { Injector, provideZonelessChangeDetection } from '@angular/core'
4-
import { sleep } from '@tanstack/query-test-utils'
4+
import { queryKey, sleep } from '@tanstack/query-test-utils'
55
import {
66
QueryClient,
77
injectIsMutating,
@@ -29,9 +29,10 @@ describe('injectIsMutating', () => {
2929
})
3030

3131
test('should properly return isMutating state', async () => {
32+
const key = queryKey()
3233
const [mutation, isMutating] = TestBed.runInInjectionContext(() => [
3334
injectMutation(() => ({
34-
mutationKey: ['isMutating1'],
35+
mutationKey: key,
3536
mutationFn: (params: { par1: string }) => sleep(10).then(() => params),
3637
})),
3738
injectIsMutating(),
@@ -54,7 +55,7 @@ describe('injectIsMutating', () => {
5455
test('throws NG0203 with descriptive error outside injection context', () => {
5556
expect(() => {
5657
injectIsMutating()
57-
}).toThrowError(/NG0203(.*?)injectIsMutating/)
58+
}).toThrow(/NG0203(.*?)injectIsMutating/)
5859
})
5960

6061
test('can be used outside injection context when passing an injector', () => {

packages/angular-query-experimental/src/__tests__/inject-is-restoring.test.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,6 @@ describe('injectIsRestoring', () => {
6767
test('throws NG0203 with descriptive error outside injection context', () => {
6868
expect(() => {
6969
injectIsRestoring()
70-
}).toThrowError(/NG0203(.*?)injectIsRestoring/)
70+
}).toThrow(/NG0203(.*?)injectIsRestoring/)
7171
})
7272
})

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

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ import {
88
import { TestBed } from '@angular/core/testing'
99
import { afterEach, beforeEach, describe, expect, test, vi } from 'vitest'
1010
import { By } from '@angular/platform-browser'
11-
import { sleep } from '@tanstack/query-test-utils'
11+
import { queryKey, sleep } from '@tanstack/query-test-utils'
1212
import {
1313
QueryClient,
1414
injectMutation,
@@ -37,7 +37,7 @@ describe('injectMutationState', () => {
3737

3838
describe('injectMutationState', () => {
3939
test('should return variables after calling mutate 1', () => {
40-
const mutationKey = ['mutation']
40+
const mutationKey = queryKey()
4141
const variables = 'foo123'
4242

4343
const mutation = TestBed.runInInjectionContext(() => {
@@ -60,8 +60,8 @@ describe('injectMutationState', () => {
6060
})
6161

6262
test('reactive options should update injectMutationState', () => {
63-
const mutationKey1 = ['mutation1']
64-
const mutationKey2 = ['mutation2']
63+
const mutationKey1 = queryKey()
64+
const mutationKey2 = queryKey()
6565
const variables1 = 'foo123'
6666
const variables2 = 'bar234'
6767

@@ -98,7 +98,7 @@ describe('injectMutationState', () => {
9898

9999
test('should return variables after calling mutate 2', () => {
100100
queryClient.clear()
101-
const mutationKey = ['mutation']
101+
const mutationKey = queryKey()
102102
const variables = 'bar234'
103103

104104
const mutation = TestBed.runInInjectionContext(() => {
@@ -182,7 +182,7 @@ describe('injectMutationState', () => {
182182
test('throws NG0203 with descriptive error outside injection context', () => {
183183
expect(() => {
184184
injectMutationState()
185-
}).toThrowError(/NG0203(.*?)injectMutationState/)
185+
}).toThrow(/NG0203(.*?)injectMutationState/)
186186
})
187187

188188
test('can be used outside injection context when passing an injector', () => {

0 commit comments

Comments
 (0)