Skip to content

Commit d1698fa

Browse files
manudelidanielpza
andcommitted
feat: backport v5 apis to v4
Co-authored-by: Daniel Perez <[email protected]>
1 parent 4e6432a commit d1698fa

22 files changed

+3076
-225
lines changed

.nvmrc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
v16.19.0
1+
22.12.0

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,7 @@
7575
"eslint-plugin-import": "^2.27.5",
7676
"eslint-plugin-react": "^7.32.2",
7777
"eslint-plugin-react-hooks": "^4.6.0",
78+
"expect-type": "^1.2.1",
7879
"git-log-parser": "^1.2.0",
7980
"jest": "^27.5.1",
8081
"jsonfile": "^6.1.0",

packages/query-core/src/mutationObserver.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -141,14 +141,16 @@ export class MutationObserver<
141141
? this.currentMutation.state
142142
: getDefaultState<TData, TError, TVariables, TContext>()
143143

144+
const isLoading = state.status === 'loading'
144145
const result: MutationObserverBaseResult<
145146
TData,
146147
TError,
147148
TVariables,
148149
TContext
149150
> = {
150151
...state,
151-
isLoading: state.status === 'loading',
152+
isLoading,
153+
isPending: isLoading,
152154
isSuccess: state.status === 'success',
153155
isError: state.status === 'error',
154156
isIdle: state.status === 'idle',

packages/query-core/src/queryCache.ts

Lines changed: 37 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ import { notifyManager } from './notifyManager'
44
import { Subscribable } from './subscribable'
55
import type { QueryFilters } from './utils'
66
import type { Action, QueryState } from './query'
7-
import type { NotifyEvent, QueryKey, QueryOptions } from './types'
7+
import type { NotifyEvent, OmitKeyof, QueryKey, QueryOptions } from './types'
88
import type { QueryClient } from './queryClient'
99
import type { QueryObserver } from './queryObserver'
1010

@@ -166,8 +166,21 @@ export class QueryCache extends Subscribable<QueryCacheListener> {
166166
}
167167

168168
find<TQueryFnData = unknown, TError = unknown, TData = TQueryFnData>(
169-
arg1: QueryKey,
170-
arg2?: QueryFilters,
169+
filters: QueryFilters,
170+
): Query<TQueryFnData, TError, TData> | undefined
171+
/**
172+
* @deprecated This method should be used with only one object argument.
173+
*/
174+
find<TQueryFnData = unknown, TError = unknown, TData = TQueryFnData>(
175+
queryKey: QueryKey,
176+
filters?: OmitKeyof<QueryFilters, 'queryKey'>,
177+
): Query<TQueryFnData, TError, TData> | undefined
178+
/**
179+
* @deprecated This method should be used with only one object argument.
180+
*/
181+
find<TQueryFnData = unknown, TError = unknown, TData = TQueryFnData>(
182+
arg1: QueryKey | QueryFilters,
183+
arg2?: OmitKeyof<QueryFilters, 'queryKey'>,
171184
): Query<TQueryFnData, TError, TData> | undefined {
172185
const [filters] = parseFilterArgs(arg1, arg2)
173186

@@ -178,10 +191,28 @@ export class QueryCache extends Subscribable<QueryCacheListener> {
178191
return this.queries.find((query) => matchQuery(filters, query))
179192
}
180193

181-
findAll(queryKey?: QueryKey, filters?: QueryFilters): Query[]
182194
findAll(filters?: QueryFilters): Query[]
183-
findAll(arg1?: QueryKey | QueryFilters, arg2?: QueryFilters): Query[]
184-
findAll(arg1?: QueryKey | QueryFilters, arg2?: QueryFilters): Query[] {
195+
/**
196+
* @deprecated This method should be used with only one object argument.
197+
*/
198+
findAll(
199+
queryKey?: QueryKey,
200+
filters?: OmitKeyof<QueryFilters, 'queryKey'>,
201+
): Query[]
202+
/**
203+
* @deprecated This method should be used with only one object argument.
204+
*/
205+
findAll(
206+
arg1?: QueryKey | QueryFilters,
207+
arg2?: OmitKeyof<QueryFilters, 'queryKey'>,
208+
): Query[]
209+
/**
210+
* @deprecated This method should be used with only one object argument.
211+
*/
212+
findAll(
213+
arg1?: QueryKey | QueryFilters,
214+
arg2?: OmitKeyof<QueryFilters, 'queryKey'>,
215+
): Query[] {
185216
const [filters] = parseFilterArgs(arg1, arg2)
186217
return Object.keys(filters).length > 0
187218
? this.queries.filter((query) => matchQuery(filters, query))

0 commit comments

Comments
 (0)