-
-
Notifications
You must be signed in to change notification settings - Fork 3.5k
init query rename and delegation #9835
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
base: main
Are you sure you want to change the base?
Changes from 8 commits
46d274c
16bed21
6d630b0
7670b40
a38e428
fab794f
6aa757c
fb9dcdc
3b33d44
a24433b
4825a0d
fa6f86f
c220826
560f086
6a3c2ed
1338e8e
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,7 @@ | ||
| --- | ||
| '@tanstack/react-query': minor | ||
| '@tanstack/query-core': minor | ||
| '@tanstack/vue-query': minor | ||
| --- | ||
|
|
||
| updated tests, respect select in imperitive methods | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,6 @@ | ||
| --- | ||
| '@tanstack/query-core': minor | ||
| '@tanstack/vue-query': minor | ||
| --- | ||
|
|
||
| renamed imperative methods |
| Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -10,6 +10,7 @@ import type { | |||||||||||||||||||||||||||||||||||||||||
| EnsureQueryDataOptions, | ||||||||||||||||||||||||||||||||||||||||||
| FetchInfiniteQueryOptions, | ||||||||||||||||||||||||||||||||||||||||||
| InfiniteData, | ||||||||||||||||||||||||||||||||||||||||||
| InfiniteQueryExecuteOptions, | ||||||||||||||||||||||||||||||||||||||||||
| MutationOptions, | ||||||||||||||||||||||||||||||||||||||||||
| OmitKeyof, | ||||||||||||||||||||||||||||||||||||||||||
| QueryKey, | ||||||||||||||||||||||||||||||||||||||||||
|
|
@@ -157,24 +158,55 @@ describe('getQueryState', () => { | |||||||||||||||||||||||||||||||||||||||||
| }) | ||||||||||||||||||||||||||||||||||||||||||
| }) | ||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||
| describe('fetchQuery', () => { | ||||||||||||||||||||||||||||||||||||||||||
| it('should not allow passing select option', () => { | ||||||||||||||||||||||||||||||||||||||||||
| assertType<Parameters<QueryClient['fetchQuery']>>([ | ||||||||||||||||||||||||||||||||||||||||||
| { | ||||||||||||||||||||||||||||||||||||||||||
| queryKey: ['key'], | ||||||||||||||||||||||||||||||||||||||||||
| queryFn: () => Promise.resolve('string'), | ||||||||||||||||||||||||||||||||||||||||||
| // @ts-expect-error `select` is not supported on fetchQuery options | ||||||||||||||||||||||||||||||||||||||||||
| select: (data: string) => data.length, | ||||||||||||||||||||||||||||||||||||||||||
| }, | ||||||||||||||||||||||||||||||||||||||||||
| ]) | ||||||||||||||||||||||||||||||||||||||||||
| }) | ||||||||||||||||||||||||||||||||||||||||||
| }) | ||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||
| describe('fetchInfiniteQuery', () => { | ||||||||||||||||||||||||||||||||||||||||||
| it('should not allow passing select option', () => { | ||||||||||||||||||||||||||||||||||||||||||
| assertType<Parameters<QueryClient['fetchInfiniteQuery']>>([ | ||||||||||||||||||||||||||||||||||||||||||
| { | ||||||||||||||||||||||||||||||||||||||||||
| queryKey: ['key'], | ||||||||||||||||||||||||||||||||||||||||||
| queryFn: () => Promise.resolve({ count: 1 }), | ||||||||||||||||||||||||||||||||||||||||||
| initialPageParam: 1, | ||||||||||||||||||||||||||||||||||||||||||
| getNextPageParam: () => 2, | ||||||||||||||||||||||||||||||||||||||||||
| // @ts-expect-error `select` is not supported on fetchInfiniteQuery options | ||||||||||||||||||||||||||||||||||||||||||
| select: (data) => ({ | ||||||||||||||||||||||||||||||||||||||||||
| pages: data.pages.map( | ||||||||||||||||||||||||||||||||||||||||||
| (x: unknown) => `count: ${(x as { count: number }).count}`, | ||||||||||||||||||||||||||||||||||||||||||
| ), | ||||||||||||||||||||||||||||||||||||||||||
| pageParams: data.pageParams, | ||||||||||||||||||||||||||||||||||||||||||
| }), | ||||||||||||||||||||||||||||||||||||||||||
| }, | ||||||||||||||||||||||||||||||||||||||||||
| ]) | ||||||||||||||||||||||||||||||||||||||||||
| }) | ||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||
| it('should allow passing pages', async () => { | ||||||||||||||||||||||||||||||||||||||||||
| const data = await new QueryClient().fetchInfiniteQuery({ | ||||||||||||||||||||||||||||||||||||||||||
| queryKey: ['key'], | ||||||||||||||||||||||||||||||||||||||||||
| queryFn: () => Promise.resolve('string'), | ||||||||||||||||||||||||||||||||||||||||||
| queryFn: () => Promise.resolve({ count: 1 }), | ||||||||||||||||||||||||||||||||||||||||||
| getNextPageParam: () => 1, | ||||||||||||||||||||||||||||||||||||||||||
| initialPageParam: 1, | ||||||||||||||||||||||||||||||||||||||||||
| pages: 5, | ||||||||||||||||||||||||||||||||||||||||||
| }) | ||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||
| expectTypeOf(data).toEqualTypeOf<InfiniteData<string, number>>() | ||||||||||||||||||||||||||||||||||||||||||
| expectTypeOf(data).toEqualTypeOf<InfiniteData<{ count: number }, number>>() | ||||||||||||||||||||||||||||||||||||||||||
| }) | ||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||
| it('should not allow passing getNextPageParam without pages', () => { | ||||||||||||||||||||||||||||||||||||||||||
| assertType<Parameters<QueryClient['fetchInfiniteQuery']>>([ | ||||||||||||||||||||||||||||||||||||||||||
| { | ||||||||||||||||||||||||||||||||||||||||||
| queryKey: ['key'], | ||||||||||||||||||||||||||||||||||||||||||
| queryFn: () => Promise.resolve('string'), | ||||||||||||||||||||||||||||||||||||||||||
| queryFn: () => Promise.resolve({ count: 1 }), | ||||||||||||||||||||||||||||||||||||||||||
| initialPageParam: 1, | ||||||||||||||||||||||||||||||||||||||||||
| getNextPageParam: () => 1, | ||||||||||||||||||||||||||||||||||||||||||
| }, | ||||||||||||||||||||||||||||||||||||||||||
|
|
@@ -183,6 +215,72 @@ describe('fetchInfiniteQuery', () => { | |||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||
| it('should not allow passing pages without getNextPageParam', () => { | ||||||||||||||||||||||||||||||||||||||||||
| assertType<Parameters<QueryClient['fetchInfiniteQuery']>>([ | ||||||||||||||||||||||||||||||||||||||||||
| // @ts-expect-error Property 'getNextPageParam' is missing | ||||||||||||||||||||||||||||||||||||||||||
| { | ||||||||||||||||||||||||||||||||||||||||||
| queryKey: ['key'], | ||||||||||||||||||||||||||||||||||||||||||
| queryFn: () => Promise.resolve({ count: 1 }), | ||||||||||||||||||||||||||||||||||||||||||
| initialPageParam: 1, | ||||||||||||||||||||||||||||||||||||||||||
| pages: 5, | ||||||||||||||||||||||||||||||||||||||||||
| }, | ||||||||||||||||||||||||||||||||||||||||||
| ]) | ||||||||||||||||||||||||||||||||||||||||||
| }) | ||||||||||||||||||||||||||||||||||||||||||
| }) | ||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||
| describe('query', () => { | ||||||||||||||||||||||||||||||||||||||||||
| it('should allow passing select option', () => { | ||||||||||||||||||||||||||||||||||||||||||
| assertType<Parameters<QueryClient['query']>>([ | ||||||||||||||||||||||||||||||||||||||||||
| { | ||||||||||||||||||||||||||||||||||||||||||
| queryKey: ['key'], | ||||||||||||||||||||||||||||||||||||||||||
| queryFn: () => Promise.resolve('string'), | ||||||||||||||||||||||||||||||||||||||||||
| select: (data) => (data as string).length, | ||||||||||||||||||||||||||||||||||||||||||
| }, | ||||||||||||||||||||||||||||||||||||||||||
| ]) | ||||||||||||||||||||||||||||||||||||||||||
| }) | ||||||||||||||||||||||||||||||||||||||||||
| }) | ||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||
| describe('infiniteQuery', () => { | ||||||||||||||||||||||||||||||||||||||||||
| it('should not allow passing select option', () => { | ||||||||||||||||||||||||||||||||||||||||||
| assertType<Parameters<QueryClient['infiniteQuery']>>([ | ||||||||||||||||||||||||||||||||||||||||||
| { | ||||||||||||||||||||||||||||||||||||||||||
| queryKey: ['key'], | ||||||||||||||||||||||||||||||||||||||||||
| queryFn: () => Promise.resolve({ count: 1 }), | ||||||||||||||||||||||||||||||||||||||||||
| initialPageParam: 1, | ||||||||||||||||||||||||||||||||||||||||||
| getNextPageParam: () => 2, | ||||||||||||||||||||||||||||||||||||||||||
| select: (data) => ({ | ||||||||||||||||||||||||||||||||||||||||||
| pages: data.pages.map( | ||||||||||||||||||||||||||||||||||||||||||
| (x) => `count: ${(x as { count: number }).count}`, | ||||||||||||||||||||||||||||||||||||||||||
| ), | ||||||||||||||||||||||||||||||||||||||||||
| pageParams: data.pageParams, | ||||||||||||||||||||||||||||||||||||||||||
| }), | ||||||||||||||||||||||||||||||||||||||||||
| }, | ||||||||||||||||||||||||||||||||||||||||||
| ]) | ||||||||||||||||||||||||||||||||||||||||||
DogPawHat marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||||||||||||||||||||||||||||||||||||||||||
| }) | ||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||
| it('should allow passing pages', async () => { | ||||||||||||||||||||||||||||||||||||||||||
| const data = await new QueryClient().fetchInfiniteQuery({ | ||||||||||||||||||||||||||||||||||||||||||
| queryKey: ['key'], | ||||||||||||||||||||||||||||||||||||||||||
| queryFn: () => Promise.resolve({ count: 1 }), | ||||||||||||||||||||||||||||||||||||||||||
| getNextPageParam: () => 1, | ||||||||||||||||||||||||||||||||||||||||||
| initialPageParam: 1, | ||||||||||||||||||||||||||||||||||||||||||
| pages: 5, | ||||||||||||||||||||||||||||||||||||||||||
| }) | ||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||
| expectTypeOf(data).toEqualTypeOf<InfiniteData<{ count: number }, number>>() | ||||||||||||||||||||||||||||||||||||||||||
| }) | ||||||||||||||||||||||||||||||||||||||||||
coderabbitai[bot] marked this conversation as resolved.
Show resolved
Hide resolved
|
||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||
| it('should not allow passing getNextPageParam without pages', () => { | ||||||||||||||||||||||||||||||||||||||||||
| assertType<Parameters<QueryClient['infiniteQuery']>>([ | ||||||||||||||||||||||||||||||||||||||||||
| { | ||||||||||||||||||||||||||||||||||||||||||
| queryKey: ['key'], | ||||||||||||||||||||||||||||||||||||||||||
| queryFn: () => Promise.resolve({ count: 1 }), | ||||||||||||||||||||||||||||||||||||||||||
| initialPageParam: 1, | ||||||||||||||||||||||||||||||||||||||||||
| getNextPageParam: () => 1, | ||||||||||||||||||||||||||||||||||||||||||
| }, | ||||||||||||||||||||||||||||||||||||||||||
| ]) | ||||||||||||||||||||||||||||||||||||||||||
| }) | ||||||||||||||||||||||||||||||||||||||||||
|
Comment on lines
+271
to
+280
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Fix misleading test title. The test uses Apply this diff: - it('should not allow passing getNextPageParam without pages', () => {
+ it('should allow passing getNextPageParam without pages', () => {📝 Committable suggestion
Suggested change
🤖 Prompt for AI Agents |
||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||
| it('should not allow passing pages without getNextPageParam', () => { | ||||||||||||||||||||||||||||||||||||||||||
| assertType<Parameters<QueryClient['infiniteQuery']>>([ | ||||||||||||||||||||||||||||||||||||||||||
| // @ts-expect-error Property 'getNextPageParam' is missing | ||||||||||||||||||||||||||||||||||||||||||
| { | ||||||||||||||||||||||||||||||||||||||||||
| queryKey: ['key'], | ||||||||||||||||||||||||||||||||||||||||||
|
|
@@ -227,6 +325,22 @@ describe('fully typed usage', () => { | |||||||||||||||||||||||||||||||||||||||||
| // Construct typed arguments | ||||||||||||||||||||||||||||||||||||||||||
| // | ||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||
| const infiniteQueryOptions: InfiniteQueryExecuteOptions<TData, TError> = { | ||||||||||||||||||||||||||||||||||||||||||
| queryKey: ['key'] as any, | ||||||||||||||||||||||||||||||||||||||||||
| pages: 5, | ||||||||||||||||||||||||||||||||||||||||||
| getNextPageParam: (lastPage) => { | ||||||||||||||||||||||||||||||||||||||||||
| expectTypeOf(lastPage).toEqualTypeOf<TData>() | ||||||||||||||||||||||||||||||||||||||||||
| return 0 | ||||||||||||||||||||||||||||||||||||||||||
| }, | ||||||||||||||||||||||||||||||||||||||||||
| initialPageParam: 0, | ||||||||||||||||||||||||||||||||||||||||||
| select: (data) => { | ||||||||||||||||||||||||||||||||||||||||||
| expectTypeOf(data).toEqualTypeOf<InfiniteData<TData, unknown>>() | ||||||||||||||||||||||||||||||||||||||||||
| return data | ||||||||||||||||||||||||||||||||||||||||||
| }, | ||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||
| const infiniteQueryOptions | ||||||||||||||||||||||||||||||||||||||||||
coderabbitai[bot] marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||
| const queryOptions: EnsureQueryDataOptions<TData, TError> = { | ||||||||||||||||||||||||||||||||||||||||||
| queryKey: ['key'] as any, | ||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||
|
|
@@ -240,6 +354,7 @@ describe('fully typed usage', () => { | |||||||||||||||||||||||||||||||||||||||||
| }, | ||||||||||||||||||||||||||||||||||||||||||
| initialPageParam: 0, | ||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||
| const mutationOptions: MutationOptions<TData, TError> = {} | ||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||
| const queryFilters: QueryFilters<DataTag<QueryKey, TData, TError>> = { | ||||||||||||||||||||||||||||||||||||||||||
|
|
@@ -310,11 +425,22 @@ describe('fully typed usage', () => { | |||||||||||||||||||||||||||||||||||||||||
| const fetchedQuery = await queryClient.fetchQuery(queryOptions) | ||||||||||||||||||||||||||||||||||||||||||
| expectTypeOf(fetchedQuery).toEqualTypeOf<TData>() | ||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||
| const queriedData = await queryClient.query(queryOptions) | ||||||||||||||||||||||||||||||||||||||||||
| expectTypeOf(queriedData).toEqualTypeOf<TData>() | ||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||
| queryClient.prefetchQuery(queryOptions) | ||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||
| const infiniteQuery = await queryClient.fetchInfiniteQuery( | ||||||||||||||||||||||||||||||||||||||||||
| const fetchInfiniteQueryResult = await queryClient.fetchInfiniteQuery( | ||||||||||||||||||||||||||||||||||||||||||
| fetchInfiniteQueryOptions, | ||||||||||||||||||||||||||||||||||||||||||
| ) | ||||||||||||||||||||||||||||||||||||||||||
| expectTypeOf(fetchInfiniteQueryResult).toEqualTypeOf< | ||||||||||||||||||||||||||||||||||||||||||
| InfiniteData<TData, unknown> | ||||||||||||||||||||||||||||||||||||||||||
| >() | ||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||
| const infiniteQuery = await queryClient.infiniteQuery(infiniteQueryOptions) | ||||||||||||||||||||||||||||||||||||||||||
| expectTypeOf(infiniteQuery).toEqualTypeOf<InfiniteData<TData, unknown>>() | ||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||
| const infiniteQuery = await queryClient.infiniteQuery(infiniteQueryOptions) | ||||||||||||||||||||||||||||||||||||||||||
| expectTypeOf(infiniteQuery).toEqualTypeOf<InfiniteData<TData, unknown>>() | ||||||||||||||||||||||||||||||||||||||||||
DogPawHat marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||
| const infiniteQueryData = await queryClient.ensureInfiniteQueryData( | ||||||||||||||||||||||||||||||||||||||||||
|
|
@@ -449,9 +575,19 @@ describe('fully typed usage', () => { | |||||||||||||||||||||||||||||||||||||||||
| const fetchedQuery = await queryClient.fetchQuery(queryOptions) | ||||||||||||||||||||||||||||||||||||||||||
| expectTypeOf(fetchedQuery).toEqualTypeOf<unknown>() | ||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||
| const queriedData = await queryClient.query(queryOptions) | ||||||||||||||||||||||||||||||||||||||||||
| expectTypeOf(queriedData).toEqualTypeOf<unknown>() | ||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||
| queryClient.prefetchQuery(queryOptions) | ||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||
| const infiniteQuery = await queryClient.fetchInfiniteQuery( | ||||||||||||||||||||||||||||||||||||||||||
| const fetchInfiniteQueryResult = await queryClient.fetchInfiniteQuery( | ||||||||||||||||||||||||||||||||||||||||||
| fetchInfiniteQueryOptions, | ||||||||||||||||||||||||||||||||||||||||||
| ) | ||||||||||||||||||||||||||||||||||||||||||
| expectTypeOf(fetchInfiniteQueryResult).toEqualTypeOf< | ||||||||||||||||||||||||||||||||||||||||||
| InfiniteData<unknown, unknown> | ||||||||||||||||||||||||||||||||||||||||||
| >() | ||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||
| const infiniteQuery = await queryClient.infiniteQuery( | ||||||||||||||||||||||||||||||||||||||||||
| fetchInfiniteQueryOptions, | ||||||||||||||||||||||||||||||||||||||||||
| ) | ||||||||||||||||||||||||||||||||||||||||||
| expectTypeOf(infiniteQuery).toEqualTypeOf<InfiniteData<unknown, unknown>>() | ||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||
Uh oh!
There was an error while loading. Please reload this page.