-
-
Notifications
You must be signed in to change notification settings - Fork 3.7k
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
Open
DogPawHat
wants to merge
24
commits into
TanStack:main
Choose a base branch
from
DogPawHat:implement-simplified-imperitive-methods
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from 16 commits
Commits
Show all changes
24 commits
Select commit
Hold shift + click to select a range
6dd8fbf
init query rename and delegation
DogPawHat c824b11
update spelling
DogPawHat 4f5f27a
add respect for select
DogPawHat c7bea26
react query options testing
DogPawHat 269ed8e
update changeset
DogPawHat f0217b4
ci: apply automated fixes
autofix-ci[bot] 19b13cf
fixes
DogPawHat 311b3ba
more type fixes
DogPawHat fd8ea67
fix typo
DogPawHat 058fd5c
typo again
DogPawHat a2c989b
Type fix
DogPawHat a78d0fe
revert delegations
DogPawHat de3f12d
typo
DogPawHat 1ed5851
client update async
DogPawHat 5c40184
REVERT IF OPUS FUCKED UP
DogPawHat bf15113
pages nit
DogPawHat 88d795b
Merge branch 'main' into implement-simplified-imperitive-methods
DogPawHat a905c54
ci: apply automated fixes
autofix-ci[bot] f89cc80
use a stub query options function
DogPawHat fedf7b5
use query and infiniteQuery functions directly for type inference
DogPawHat a743447
Merge branch 'main' into implement-simplified-imperitive-methods
DogPawHat c7baef7
lint array fix
DogPawHat 0c6ea77
remove explicit typing
DogPawHat 3b0207d
Merge branch 'main' into implement-simplified-imperitive-methods
DogPawHat File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Some comments aren't visible on the classic Files Changed page.
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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 | ||
| --- | ||
|
|
||
| renamed imperative methods |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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 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, | ||
| }), | ||
| }, | ||
| ]) | ||
| }) | ||
|
|
||
| it('should allow passing pages', async () => { | ||
| const data = await new QueryClient().infiniteQuery({ | ||
| queryKey: ['key'], | ||
| queryFn: () => Promise.resolve({ count: 1 }), | ||
| getNextPageParam: () => 1, | ||
| initialPageParam: 1, | ||
| pages: 5, | ||
| }) | ||
|
|
||
| expectTypeOf(data).toEqualTypeOf<InfiniteData<{ count: number }, number>>() | ||
| }) | ||
|
|
||
| it('should allow passing getNextPageParam without pages', () => { | ||
| assertType<Parameters<QueryClient['infiniteQuery']>>([ | ||
| { | ||
| queryKey: ['key'], | ||
| queryFn: () => Promise.resolve({ count: 1 }), | ||
| initialPageParam: 1, | ||
| getNextPageParam: () => 1, | ||
| }, | ||
| ]) | ||
| }) | ||
|
|
||
| it('should not allow passing pages without getNextPageParam', () => { | ||
| assertType<Parameters<QueryClient['infiniteQuery']>>([ | ||
| // @ts-expect-error Property 'getNextPageParam' is missing | ||
| { | ||
| queryKey: ['key'], | ||
|
|
@@ -227,6 +325,16 @@ 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, | ||
| } | ||
|
|
||
| const queryOptions: EnsureQueryDataOptions<TData, TError> = { | ||
| queryKey: ['key'] as any, | ||
| } | ||
|
|
@@ -240,6 +348,7 @@ describe('fully typed usage', () => { | |
| }, | ||
| initialPageParam: 0, | ||
| } | ||
|
|
||
| const mutationOptions: MutationOptions<TData, TError> = {} | ||
|
|
||
| const queryFilters: QueryFilters<DataTag<QueryKey, TData, TError>> = { | ||
|
|
@@ -310,11 +419,19 @@ 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 infiniteQueryData = await queryClient.ensureInfiniteQueryData( | ||
|
|
@@ -449,9 +566,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>>() | ||
|
|
||
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
shouldn’t string be inferred here?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It inferrs as unknown in this case, because I think the generic in
assertTypeOfhas already intialisedTQueryFnDatatounknownThere was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ended up making a stub
queryOptionsfn to make the inference work with select. but the assertType still fails comparing string to unknown.