@tanstack/react-query 5.0.0-alpha.6 → 5.0.0-alpha.61
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/build/codemods/__testfixtures__/default-import.input.tsx +94 -0
- package/build/codemods/__testfixtures__/default-import.output.tsx +96 -0
- package/build/codemods/__testfixtures__/named-import.input.tsx +96 -0
- package/build/codemods/__testfixtures__/named-import.output.tsx +98 -0
- package/build/codemods/__testfixtures__/namespaced-import.input.tsx +86 -0
- package/build/codemods/__testfixtures__/namespaced-import.output.tsx +88 -0
- package/build/codemods/__testfixtures__/parameter-is-identifier.input.tsx +49 -0
- package/build/codemods/__testfixtures__/parameter-is-identifier.output.tsx +49 -0
- package/build/codemods/__testfixtures__/parameter-is-object-expression.input.tsx +128 -0
- package/build/codemods/__testfixtures__/parameter-is-object-expression.output.tsx +175 -0
- package/build/codemods/__testfixtures__/replace-import-specifier.input.tsx +10 -0
- package/build/codemods/__testfixtures__/replace-import-specifier.output.tsx +10 -0
- package/build/codemods/__testfixtures__/type-arguments.input.tsx +25 -0
- package/build/codemods/__testfixtures__/type-arguments.output.tsx +31 -0
- package/build/codemods/__tests__/key-transformation.test.js +32 -0
- package/build/codemods/__tests__/replace-import-specifier.test.js +12 -0
- package/build/codemods/remove-overloads/__testfixtures__/default-import.input.tsx +199 -0
- package/build/codemods/remove-overloads/__testfixtures__/default-import.output.tsx +484 -0
- package/build/codemods/remove-overloads/__tests__/remove-overloads.test.js +6 -0
- package/build/codemods/remove-overloads/remove-overloads.js +59 -0
- package/build/codemods/remove-overloads/transformers/filter-aware-usage-transformer.js +153 -0
- package/build/codemods/remove-overloads/transformers/query-fn-aware-usage-transformer.js +188 -0
- package/build/codemods/remove-overloads/utils/index.js +124 -0
- package/build/codemods/remove-overloads/utils/unknown-usage-error.js +27 -0
- package/build/codemods/src/utils/index.js +205 -0
- package/build/codemods/src/v4/key-transformation.js +138 -0
- package/build/codemods/src/v4/replace-import-specifier.js +25 -0
- package/build/codemods/transformers/query-cache-transformer.js +116 -0
- package/build/codemods/transformers/query-client-transformer.js +48 -0
- package/build/codemods/transformers/use-query-like-transformer.js +32 -0
- package/build/codemods/utils/replacers/key-replacer.js +164 -0
- package/build/lib/HydrationBoundary.cjs +50 -0
- package/build/lib/{HydrationBoundary.mjs.map → HydrationBoundary.cjs.map} +1 -1
- package/build/lib/HydrationBoundary.d.ts +1 -0
- package/build/lib/HydrationBoundary.d.ts.map +1 -0
- package/build/lib/HydrationBoundary.js +9 -29
- package/build/lib/HydrationBoundary.js.map +1 -1
- package/build/lib/QueryClientProvider.cjs +54 -0
- package/build/lib/QueryClientProvider.cjs.map +1 -0
- package/build/lib/QueryClientProvider.d.ts +2 -1
- package/build/lib/QueryClientProvider.d.ts.map +1 -0
- package/build/lib/QueryClientProvider.js +7 -29
- package/build/lib/QueryClientProvider.js.map +1 -1
- package/build/lib/QueryErrorResetBoundary.cjs +60 -0
- package/build/lib/{QueryErrorResetBoundary.mjs.map → QueryErrorResetBoundary.cjs.map} +1 -1
- package/build/lib/QueryErrorResetBoundary.d.ts +2 -1
- package/build/lib/QueryErrorResetBoundary.d.ts.map +1 -0
- package/build/lib/QueryErrorResetBoundary.js +7 -28
- package/build/lib/QueryErrorResetBoundary.js.map +1 -1
- package/build/lib/__tests__/HydrationBoundary.test.d.ts +1 -0
- package/build/lib/__tests__/HydrationBoundary.test.d.ts.map +1 -0
- package/build/lib/__tests__/QueryClientProvider.test.d.ts +1 -0
- package/build/lib/__tests__/QueryClientProvider.test.d.ts.map +1 -0
- package/build/lib/__tests__/QueryResetErrorBoundary.test.d.ts +1 -0
- package/build/lib/__tests__/QueryResetErrorBoundary.test.d.ts.map +1 -0
- package/build/lib/__tests__/ssr-hydration.test.d.ts +1 -0
- package/build/lib/__tests__/ssr-hydration.test.d.ts.map +1 -0
- package/build/lib/__tests__/ssr.test.d.ts +1 -0
- package/build/lib/__tests__/ssr.test.d.ts.map +1 -0
- package/build/lib/__tests__/suspense.test.d.ts +1 -0
- package/build/lib/__tests__/suspense.test.d.ts.map +1 -0
- package/build/lib/__tests__/useInfiniteQuery.test.d.ts +1 -0
- package/build/lib/__tests__/useInfiniteQuery.test.d.ts.map +1 -0
- package/build/lib/__tests__/useInfiniteQuery.type.test.d.ts +1 -0
- package/build/lib/__tests__/useInfiniteQuery.type.test.d.ts.map +1 -0
- package/build/lib/__tests__/useIsFetching.test.d.ts +1 -0
- package/build/lib/__tests__/useIsFetching.test.d.ts.map +1 -0
- package/build/lib/__tests__/useMutation.test.d.ts +1 -0
- package/build/lib/__tests__/useMutation.test.d.ts.map +1 -0
- package/build/lib/__tests__/useMutationState.test.d.ts +1 -0
- package/build/lib/__tests__/useMutationState.test.d.ts.map +1 -0
- package/build/lib/__tests__/useQueries.test.d.ts +1 -0
- package/build/lib/__tests__/useQueries.test.d.ts.map +1 -0
- package/build/lib/__tests__/useQuery.test.d.ts +1 -0
- package/build/lib/__tests__/useQuery.test.d.ts.map +1 -0
- package/build/lib/__tests__/useQuery.types.test.d.ts +1 -0
- package/build/lib/__tests__/useQuery.types.test.d.ts.map +1 -0
- package/build/lib/__tests__/utils.d.ts +6 -5
- package/build/lib/__tests__/utils.d.ts.map +1 -0
- package/build/lib/errorBoundaryUtils.cjs +51 -0
- package/build/lib/errorBoundaryUtils.cjs.map +1 -0
- package/build/lib/errorBoundaryUtils.d.ts +4 -3
- package/build/lib/errorBoundaryUtils.d.ts.map +1 -0
- package/build/lib/errorBoundaryUtils.js +8 -30
- package/build/lib/errorBoundaryUtils.js.map +1 -1
- package/build/lib/index.cjs +39 -0
- package/build/lib/index.cjs.map +1 -0
- package/build/lib/index.d.ts +2 -1
- package/build/lib/index.d.ts.map +1 -0
- package/build/lib/index.js +11 -37
- package/build/lib/index.js.map +1 -1
- package/build/lib/isRestoring.cjs +31 -0
- package/build/lib/isRestoring.cjs.map +1 -0
- package/build/lib/isRestoring.d.ts +1 -0
- package/build/lib/isRestoring.d.ts.map +1 -0
- package/build/lib/isRestoring.js +5 -26
- package/build/lib/isRestoring.js.map +1 -1
- package/build/lib/{suspense.mjs → suspense.cjs} +8 -10
- package/build/lib/suspense.cjs.map +1 -0
- package/build/lib/suspense.d.ts +3 -5
- package/build/lib/suspense.d.ts.map +1 -0
- package/build/lib/suspense.js +3 -15
- package/build/lib/suspense.js.map +1 -1
- package/build/lib/types.d.ts +11 -10
- package/build/lib/types.d.ts.map +1 -0
- package/build/lib/useBaseQuery.cjs +80 -0
- package/build/lib/useBaseQuery.cjs.map +1 -0
- package/build/lib/useBaseQuery.d.ts +1 -0
- package/build/lib/useBaseQuery.d.ts.map +1 -0
- package/build/lib/useBaseQuery.js +30 -54
- package/build/lib/useBaseQuery.js.map +1 -1
- package/build/lib/useInfiniteQuery.cjs +15 -0
- package/build/lib/useInfiniteQuery.cjs.map +1 -0
- package/build/lib/useInfiniteQuery.d.ts +1 -0
- package/build/lib/useInfiniteQuery.d.ts.map +1 -0
- package/build/lib/useInfiniteQuery.js +6 -7
- package/build/lib/useInfiniteQuery.js.map +1 -1
- package/build/lib/useIsFetching.cjs +34 -0
- package/build/lib/useIsFetching.cjs.map +1 -0
- package/build/lib/useIsFetching.d.ts +1 -0
- package/build/lib/useIsFetching.d.ts.map +1 -0
- package/build/lib/useIsFetching.js +7 -27
- package/build/lib/useIsFetching.js.map +1 -1
- package/build/lib/useMutation.cjs +54 -0
- package/build/lib/useMutation.cjs.map +1 -0
- package/build/lib/useMutation.d.ts +1 -0
- package/build/lib/useMutation.d.ts.map +1 -0
- package/build/lib/useMutation.js +12 -32
- package/build/lib/useMutation.js.map +1 -1
- package/build/lib/useMutationState.cjs +60 -0
- package/build/lib/useMutationState.cjs.map +1 -0
- package/build/lib/useMutationState.d.ts +4 -3
- package/build/lib/useMutationState.d.ts.map +1 -0
- package/build/lib/useMutationState.js +13 -34
- package/build/lib/useMutationState.js.map +1 -1
- package/build/lib/useQueries.cjs +99 -0
- package/build/lib/useQueries.cjs.map +1 -0
- package/build/lib/useQueries.d.ts +10 -8
- package/build/lib/useQueries.d.ts.map +1 -0
- package/build/lib/useQueries.js +52 -67
- package/build/lib/useQueries.js.map +1 -1
- package/build/lib/useQuery.cjs +19 -0
- package/build/lib/useQuery.cjs.map +1 -0
- package/build/lib/useQuery.d.ts +5 -2
- package/build/lib/useQuery.d.ts.map +1 -0
- package/build/lib/useQuery.js +8 -5
- package/build/lib/useQuery.js.map +1 -1
- package/build/lib/{utils.esm.js → utils.cjs} +4 -2
- package/build/lib/{utils.mjs.map → utils.cjs.map} +1 -1
- package/build/lib/utils.d.ts +1 -0
- package/build/lib/utils.d.ts.map +1 -0
- package/build/lib/utils.js +1 -3
- package/build/lib/utils.js.map +1 -1
- package/package.json +24 -15
- package/src/__tests__/QueryResetErrorBoundary.test.tsx +752 -620
- package/src/__tests__/ssr-hydration.test.tsx +2 -2
- package/src/__tests__/suspense.test.tsx +6 -88
- package/src/__tests__/useInfiniteQuery.type.test.tsx +0 -27
- package/src/__tests__/useMutation.test.tsx +4 -4
- package/src/__tests__/useMutationState.test.tsx +23 -0
- package/src/__tests__/useQueries.test.tsx +206 -83
- package/src/__tests__/useQuery.test.tsx +246 -338
- package/src/__tests__/useQuery.types.test.tsx +21 -1
- package/src/errorBoundaryUtils.ts +6 -5
- package/src/index.ts +1 -1
- package/src/suspense.ts +9 -15
- package/src/useBaseQuery.ts +12 -23
- package/src/useInfiniteQuery.ts +1 -0
- package/src/useIsFetching.ts +1 -0
- package/src/useMutation.ts +2 -1
- package/src/useMutationState.ts +4 -3
- package/src/useQueries.ts +44 -26
- package/src/useQuery.ts +23 -0
- package/build/lib/HydrationBoundary.esm.js +0 -28
- package/build/lib/HydrationBoundary.esm.js.map +0 -1
- package/build/lib/HydrationBoundary.mjs +0 -28
- package/build/lib/QueryClientProvider.esm.js +0 -30
- package/build/lib/QueryClientProvider.esm.js.map +0 -1
- package/build/lib/QueryClientProvider.mjs +0 -30
- package/build/lib/QueryClientProvider.mjs.map +0 -1
- package/build/lib/QueryErrorResetBoundary.esm.js +0 -37
- package/build/lib/QueryErrorResetBoundary.esm.js.map +0 -1
- package/build/lib/QueryErrorResetBoundary.mjs +0 -37
- package/build/lib/errorBoundaryUtils.esm.js +0 -27
- package/build/lib/errorBoundaryUtils.esm.js.map +0 -1
- package/build/lib/errorBoundaryUtils.mjs +0 -27
- package/build/lib/errorBoundaryUtils.mjs.map +0 -1
- package/build/lib/index.esm.js +0 -12
- package/build/lib/index.esm.js.map +0 -1
- package/build/lib/index.mjs +0 -12
- package/build/lib/index.mjs.map +0 -1
- package/build/lib/isRestoring.esm.js +0 -8
- package/build/lib/isRestoring.esm.js.map +0 -1
- package/build/lib/isRestoring.mjs +0 -8
- package/build/lib/isRestoring.mjs.map +0 -1
- package/build/lib/suspense.esm.js +0 -24
- package/build/lib/suspense.esm.js.map +0 -1
- package/build/lib/suspense.mjs.map +0 -1
- package/build/lib/useBaseQuery.esm.js +0 -62
- package/build/lib/useBaseQuery.esm.js.map +0 -1
- package/build/lib/useBaseQuery.mjs +0 -62
- package/build/lib/useBaseQuery.mjs.map +0 -1
- package/build/lib/useInfiniteQuery.esm.js +0 -12
- package/build/lib/useInfiniteQuery.esm.js.map +0 -1
- package/build/lib/useInfiniteQuery.mjs +0 -12
- package/build/lib/useInfiniteQuery.mjs.map +0 -1
- package/build/lib/useIsFetching.esm.js +0 -12
- package/build/lib/useIsFetching.esm.js.map +0 -1
- package/build/lib/useIsFetching.mjs +0 -12
- package/build/lib/useIsFetching.mjs.map +0 -1
- package/build/lib/useMutation.esm.js +0 -32
- package/build/lib/useMutation.esm.js.map +0 -1
- package/build/lib/useMutation.mjs +0 -32
- package/build/lib/useMutation.mjs.map +0 -1
- package/build/lib/useMutationState.esm.js +0 -37
- package/build/lib/useMutationState.esm.js.map +0 -1
- package/build/lib/useMutationState.mjs +0 -37
- package/build/lib/useMutationState.mjs.map +0 -1
- package/build/lib/useQueries.esm.js +0 -72
- package/build/lib/useQueries.esm.js.map +0 -1
- package/build/lib/useQueries.mjs +0 -69
- package/build/lib/useQueries.mjs.map +0 -1
- package/build/lib/useQuery.esm.js +0 -11
- package/build/lib/useQuery.esm.js.map +0 -1
- package/build/lib/useQuery.mjs +0 -11
- package/build/lib/useQuery.mjs.map +0 -1
- package/build/lib/utils.esm.js.map +0 -1
- package/build/lib/utils.mjs +0 -10
- package/build/umd/index.development.js +0 -3040
- package/build/umd/index.development.js.map +0 -1
- package/build/umd/index.production.js +0 -2
- package/build/umd/index.production.js.map +0 -1
|
@@ -0,0 +1,484 @@
|
|
|
1
|
+
import * as React from 'react'
|
|
2
|
+
import {
|
|
3
|
+
useIsFetching,
|
|
4
|
+
useIsMutating,
|
|
5
|
+
useQueryClient,
|
|
6
|
+
} from '@tanstack/react-query'
|
|
7
|
+
import { queryKeysFromAnotherModule } from '../another/module'
|
|
8
|
+
|
|
9
|
+
export const WithKnownParameters = () => {
|
|
10
|
+
useIsFetching({
|
|
11
|
+
queryKey: ['foo', 'bar']
|
|
12
|
+
})
|
|
13
|
+
useIsFetching({
|
|
14
|
+
queryKey: ['foo', 'bar'],
|
|
15
|
+
type: 'all',
|
|
16
|
+
exact: true
|
|
17
|
+
})
|
|
18
|
+
useIsFetching({
|
|
19
|
+
queryKey: ['foo', 'bar'],
|
|
20
|
+
type: 'all',
|
|
21
|
+
exact: true
|
|
22
|
+
}, { context: undefined })
|
|
23
|
+
useIsFetching({
|
|
24
|
+
queryKey: ['foo', 'bar'],
|
|
25
|
+
type: 'all',
|
|
26
|
+
exact: true
|
|
27
|
+
})
|
|
28
|
+
useIsFetching({
|
|
29
|
+
queryKey: ['foo', 'bar'],
|
|
30
|
+
type: 'all',
|
|
31
|
+
exact: true
|
|
32
|
+
}, { context: undefined })
|
|
33
|
+
useIsFetching({ queryKey: ['foo', 'bar'], type: 'all', exact: true })
|
|
34
|
+
useIsFetching({ queryKey: ['foo', 'bar'], type: 'all', exact: true }, { context: undefined })
|
|
35
|
+
|
|
36
|
+
useIsMutating({
|
|
37
|
+
mutationKey: ['foo', 'bar']
|
|
38
|
+
})
|
|
39
|
+
useIsMutating({
|
|
40
|
+
mutationKey: ['foo', 'bar'],
|
|
41
|
+
exact: true
|
|
42
|
+
})
|
|
43
|
+
useIsMutating({
|
|
44
|
+
mutationKey: ['foo', 'bar'],
|
|
45
|
+
exact: true
|
|
46
|
+
}, { context: undefined })
|
|
47
|
+
useIsMutating({ mutationKey: ['foo', 'bar'], exact: true })
|
|
48
|
+
useIsMutating({ mutationKey: ['foo', 'bar'], exact: true }, { context: undefined })
|
|
49
|
+
|
|
50
|
+
// QueryClient methods
|
|
51
|
+
// --- Instantiated hook call.
|
|
52
|
+
const queryClient = useQueryClient()
|
|
53
|
+
queryClient.cancelQueries({
|
|
54
|
+
queryKey: ['foo', 'bar']
|
|
55
|
+
})
|
|
56
|
+
queryClient.cancelQueries({
|
|
57
|
+
queryKey: ['foo', 'bar'],
|
|
58
|
+
type: 'all',
|
|
59
|
+
exact: true
|
|
60
|
+
})
|
|
61
|
+
queryClient.cancelQueries({
|
|
62
|
+
queryKey: ['foo', 'bar'],
|
|
63
|
+
type: 'all',
|
|
64
|
+
exact: true
|
|
65
|
+
}, { silent: true })
|
|
66
|
+
queryClient.cancelQueries({
|
|
67
|
+
queryKey: ['foo', 'bar'],
|
|
68
|
+
type: 'all',
|
|
69
|
+
exact: true
|
|
70
|
+
})
|
|
71
|
+
queryClient.cancelQueries({
|
|
72
|
+
queryKey: ['foo', 'bar'],
|
|
73
|
+
type: 'all',
|
|
74
|
+
exact: true
|
|
75
|
+
}, { silent: true })
|
|
76
|
+
queryClient.cancelQueries({ queryKey: ['foo', 'bar'], type: 'all', exact: true })
|
|
77
|
+
queryClient.cancelQueries({ queryKey: ['foo', 'bar'], type: 'all', exact: true }, { silent: true })
|
|
78
|
+
|
|
79
|
+
queryClient.getQueriesData({
|
|
80
|
+
queryKey: ['foo', 'bar']
|
|
81
|
+
})
|
|
82
|
+
queryClient.getQueriesData({ queryKey: ['foo', 'bar'], type: 'all', exact: true })
|
|
83
|
+
|
|
84
|
+
queryClient.invalidateQueries({
|
|
85
|
+
queryKey: ['foo', 'bar']
|
|
86
|
+
})
|
|
87
|
+
queryClient.invalidateQueries({
|
|
88
|
+
queryKey: ['foo', 'bar'],
|
|
89
|
+
type: 'all',
|
|
90
|
+
exact: true
|
|
91
|
+
})
|
|
92
|
+
queryClient.invalidateQueries({
|
|
93
|
+
queryKey: ['foo', 'bar'],
|
|
94
|
+
type: 'all',
|
|
95
|
+
exact: true
|
|
96
|
+
}, { cancelRefetch: false, throwOnError: true })
|
|
97
|
+
queryClient.invalidateQueries({
|
|
98
|
+
queryKey: ['foo', 'bar'],
|
|
99
|
+
type: 'all',
|
|
100
|
+
exact: true
|
|
101
|
+
})
|
|
102
|
+
queryClient.invalidateQueries({
|
|
103
|
+
queryKey: ['foo', 'bar'],
|
|
104
|
+
type: 'all',
|
|
105
|
+
exact: true
|
|
106
|
+
}, { cancelRefetch: false, throwOnError: true })
|
|
107
|
+
queryClient.invalidateQueries({ queryKey: ['foo', 'bar'], type: 'all', exact: true })
|
|
108
|
+
queryClient.invalidateQueries({ queryKey: ['foo', 'bar'], type: 'all', exact: true }, { cancelRefetch: false, throwOnError: true })
|
|
109
|
+
|
|
110
|
+
queryClient.isFetching({
|
|
111
|
+
queryKey: ['foo', 'bar']
|
|
112
|
+
})
|
|
113
|
+
queryClient.isFetching({
|
|
114
|
+
queryKey: ['foo', 'bar'],
|
|
115
|
+
type: 'all',
|
|
116
|
+
exact: true
|
|
117
|
+
})
|
|
118
|
+
queryClient.isFetching({
|
|
119
|
+
queryKey: ['foo', 'bar'],
|
|
120
|
+
type: 'all',
|
|
121
|
+
exact: true
|
|
122
|
+
})
|
|
123
|
+
queryClient.isFetching({ queryKey: ['foo', 'bar'], type: 'all', exact: true })
|
|
124
|
+
|
|
125
|
+
queryClient.refetchQueries({
|
|
126
|
+
queryKey: ['foo', 'bar']
|
|
127
|
+
})
|
|
128
|
+
queryClient.refetchQueries({
|
|
129
|
+
queryKey: ['foo', 'bar'],
|
|
130
|
+
type: 'all',
|
|
131
|
+
exact: true
|
|
132
|
+
})
|
|
133
|
+
queryClient.refetchQueries({
|
|
134
|
+
queryKey: ['foo', 'bar'],
|
|
135
|
+
type: 'all',
|
|
136
|
+
exact: true
|
|
137
|
+
}, { cancelRefetch: false, throwOnError: true })
|
|
138
|
+
queryClient.refetchQueries({
|
|
139
|
+
queryKey: ['foo', 'bar'],
|
|
140
|
+
type: 'all',
|
|
141
|
+
exact: true
|
|
142
|
+
})
|
|
143
|
+
queryClient.refetchQueries({
|
|
144
|
+
queryKey: ['foo', 'bar'],
|
|
145
|
+
type: 'all',
|
|
146
|
+
exact: true
|
|
147
|
+
}, { cancelRefetch: false, throwOnError: true })
|
|
148
|
+
queryClient.refetchQueries({ queryKey: ['foo', 'bar'], type: 'all', exact: true })
|
|
149
|
+
queryClient.refetchQueries({ queryKey: ['foo', 'bar'], type: 'all', exact: true }, { cancelRefetch: false, throwOnError: true })
|
|
150
|
+
|
|
151
|
+
queryClient.removeQueries({
|
|
152
|
+
queryKey: ['foo', 'bar']
|
|
153
|
+
})
|
|
154
|
+
queryClient.removeQueries({
|
|
155
|
+
queryKey: ['foo', 'bar'],
|
|
156
|
+
type: 'all',
|
|
157
|
+
exact: true
|
|
158
|
+
})
|
|
159
|
+
queryClient.removeQueries({ queryKey: ['foo', 'bar'], type: 'all', exact: true })
|
|
160
|
+
|
|
161
|
+
queryClient.resetQueries({
|
|
162
|
+
queryKey: ['foo', 'bar']
|
|
163
|
+
})
|
|
164
|
+
queryClient.resetQueries({
|
|
165
|
+
queryKey: ['foo', 'bar'],
|
|
166
|
+
type: 'all',
|
|
167
|
+
exact: true
|
|
168
|
+
})
|
|
169
|
+
queryClient.resetQueries({
|
|
170
|
+
queryKey: ['foo', 'bar'],
|
|
171
|
+
type: 'all',
|
|
172
|
+
exact: true
|
|
173
|
+
}, { cancelRefetch: false, throwOnError: true })
|
|
174
|
+
queryClient.resetQueries({
|
|
175
|
+
queryKey: ['foo', 'bar'],
|
|
176
|
+
type: 'all',
|
|
177
|
+
exact: true
|
|
178
|
+
})
|
|
179
|
+
queryClient.resetQueries({
|
|
180
|
+
queryKey: ['foo', 'bar'],
|
|
181
|
+
type: 'all',
|
|
182
|
+
exact: true
|
|
183
|
+
}, { cancelRefetch: false, throwOnError: true })
|
|
184
|
+
queryClient.resetQueries({ queryKey: ['foo', 'bar'], exact: true })
|
|
185
|
+
queryClient.resetQueries({ queryKey: ['foo', 'bar'], exact: true }, { cancelRefetch: false, throwOnError: true })
|
|
186
|
+
|
|
187
|
+
queryClient.setQueriesData(['foo', 'bar'], null)
|
|
188
|
+
queryClient.setQueriesData(['foo', 'bar'], null, { updatedAt: 1000 })
|
|
189
|
+
queryClient.setQueriesData({ queryKey: ['foo', 'bar'] }, null)
|
|
190
|
+
queryClient.setQueriesData({ queryKey: ['foo', 'bar'] }, null, { updatedAt: 1000 })
|
|
191
|
+
|
|
192
|
+
queryClient.fetchQuery({
|
|
193
|
+
queryKey: ['foo', 'bar']
|
|
194
|
+
})
|
|
195
|
+
queryClient.fetchQuery({
|
|
196
|
+
queryKey: ['foo', 'bar'],
|
|
197
|
+
staleTime: 1000
|
|
198
|
+
})
|
|
199
|
+
queryClient.fetchQuery({
|
|
200
|
+
queryKey: ['foo', 'bar'],
|
|
201
|
+
queryFn: () => 'data',
|
|
202
|
+
staleTime: 1000
|
|
203
|
+
})
|
|
204
|
+
queryClient.fetchQuery({
|
|
205
|
+
queryKey: ['foo', 'bar'],
|
|
206
|
+
queryFn: () => 'data',
|
|
207
|
+
staleTime: 1000
|
|
208
|
+
})
|
|
209
|
+
queryClient.fetchQuery({
|
|
210
|
+
queryKey: ['foo', 'bar'],
|
|
211
|
+
queryFn: function myFn() { return 'data' },
|
|
212
|
+
staleTime: 1000
|
|
213
|
+
})
|
|
214
|
+
queryClient.fetchQuery({ queryKey: ['foo', 'bar'], queryFn: () => 'data', retry: true })
|
|
215
|
+
|
|
216
|
+
const queryCache = queryClient.getQueryCache()
|
|
217
|
+
|
|
218
|
+
queryCache.find({
|
|
219
|
+
queryKey: ['foo', 'bar']
|
|
220
|
+
})
|
|
221
|
+
queryCache.find({
|
|
222
|
+
queryKey: ['foo', 'bar'],
|
|
223
|
+
type: 'all',
|
|
224
|
+
exact: true
|
|
225
|
+
})
|
|
226
|
+
queryCache.find({
|
|
227
|
+
queryKey: ['foo', 'bar'],
|
|
228
|
+
type: 'all',
|
|
229
|
+
exact: true
|
|
230
|
+
})
|
|
231
|
+
|
|
232
|
+
queryCache.findAll({
|
|
233
|
+
queryKey: ['foo', 'bar']
|
|
234
|
+
})
|
|
235
|
+
queryCache.findAll({
|
|
236
|
+
queryKey: ['foo', 'bar'],
|
|
237
|
+
type: 'all',
|
|
238
|
+
exact: true
|
|
239
|
+
})
|
|
240
|
+
queryCache.findAll({
|
|
241
|
+
queryKey: ['foo', 'bar'],
|
|
242
|
+
type: 'all',
|
|
243
|
+
exact: true
|
|
244
|
+
})
|
|
245
|
+
queryCache.findAll({ queryKey: ['foo', 'bar'], type: 'all', exact: true })
|
|
246
|
+
|
|
247
|
+
return <div>Example Component</div>
|
|
248
|
+
}
|
|
249
|
+
|
|
250
|
+
const globalQueryKey = ['module', 'level']
|
|
251
|
+
|
|
252
|
+
export const WithIdentifiers = () => {
|
|
253
|
+
const queryKey = ['foo', 'bar']
|
|
254
|
+
const mutationKey = ['posts', 'articles']
|
|
255
|
+
const filters = { type: 'all', exact: true } as const
|
|
256
|
+
const options = { context: undefined } as const
|
|
257
|
+
const mutationOptions = { exact: true, fetching: false } as const
|
|
258
|
+
const cancelOptions = { silent: true } as const
|
|
259
|
+
const invalidateOptions = { cancelRefetch: true, throwOnError: true } as const
|
|
260
|
+
const refetchOptions = { cancelRefetch: false, throwOnError: true } as const
|
|
261
|
+
const resetOptions = { cancelRefetch: false, throwOnError: true } as const
|
|
262
|
+
const fetchOptions = { queryFn: () => 'data', retry: true } as const
|
|
263
|
+
const queryFn = () => 'data'
|
|
264
|
+
|
|
265
|
+
useIsFetching({
|
|
266
|
+
queryKey: queryKey
|
|
267
|
+
})
|
|
268
|
+
useIsFetching({
|
|
269
|
+
queryKey: queryKey,
|
|
270
|
+
...filters
|
|
271
|
+
})
|
|
272
|
+
useIsFetching({
|
|
273
|
+
queryKey: queryKey,
|
|
274
|
+
...filters
|
|
275
|
+
}, options)
|
|
276
|
+
useIsFetching({
|
|
277
|
+
queryKey: queryKey,
|
|
278
|
+
type: 'all',
|
|
279
|
+
exact: true
|
|
280
|
+
})
|
|
281
|
+
useIsFetching({
|
|
282
|
+
queryKey: queryKey,
|
|
283
|
+
type: 'all',
|
|
284
|
+
exact: true
|
|
285
|
+
}, { context: undefined })
|
|
286
|
+
useIsFetching({
|
|
287
|
+
queryKey: queryKey,
|
|
288
|
+
...filters
|
|
289
|
+
}, options)
|
|
290
|
+
useIsFetching({ queryKey: queryKey, ...filters })
|
|
291
|
+
useIsFetching({ queryKey: queryKey, ...filters }, { context: undefined })
|
|
292
|
+
|
|
293
|
+
useIsMutating({
|
|
294
|
+
mutationKey: mutationKey
|
|
295
|
+
})
|
|
296
|
+
useIsMutating({
|
|
297
|
+
mutationKey: mutationKey,
|
|
298
|
+
exact: true,
|
|
299
|
+
status: 'idle'
|
|
300
|
+
})
|
|
301
|
+
useIsMutating({
|
|
302
|
+
mutationKey: mutationKey,
|
|
303
|
+
...mutationOptions,
|
|
304
|
+
exact: false
|
|
305
|
+
})
|
|
306
|
+
useIsMutating({ mutationKey, ...mutationOptions })
|
|
307
|
+
useIsMutating({ mutationKey: ['foo', 'bar'], exact: true, status: 'idle' })
|
|
308
|
+
|
|
309
|
+
// QueryClient methods
|
|
310
|
+
// --- Instantiated hook call.
|
|
311
|
+
const queryClient = useQueryClient()
|
|
312
|
+
queryClient.cancelQueries({
|
|
313
|
+
queryKey: queryKey
|
|
314
|
+
})
|
|
315
|
+
queryClient.cancelQueries({
|
|
316
|
+
queryKey: queryKey,
|
|
317
|
+
...filters
|
|
318
|
+
})
|
|
319
|
+
queryClient.cancelQueries({
|
|
320
|
+
queryKey: queryKey,
|
|
321
|
+
...filters
|
|
322
|
+
}, cancelOptions)
|
|
323
|
+
queryClient.cancelQueries({
|
|
324
|
+
queryKey: queryKey,
|
|
325
|
+
type: 'all',
|
|
326
|
+
exact: true
|
|
327
|
+
})
|
|
328
|
+
queryClient.cancelQueries({
|
|
329
|
+
queryKey: queryKey,
|
|
330
|
+
type: 'all',
|
|
331
|
+
exact: true
|
|
332
|
+
}, { revert: true })
|
|
333
|
+
queryClient.cancelQueries({
|
|
334
|
+
queryKey: queryKey,
|
|
335
|
+
...filters
|
|
336
|
+
}, cancelOptions)
|
|
337
|
+
queryClient.cancelQueries({ queryKey: queryKey, type: 'all', exact: true })
|
|
338
|
+
queryClient.cancelQueries({ queryKey: ['foo', 'bar'], ...filters }, cancelOptions)
|
|
339
|
+
|
|
340
|
+
queryClient.getQueriesData({
|
|
341
|
+
queryKey: globalQueryKey
|
|
342
|
+
})
|
|
343
|
+
queryClient.getQueriesData({ queryKey: globalQueryKey, ...filters })
|
|
344
|
+
queryClient.getQueriesData({ queryKey: ['foo', 'bar'], type: 'all' })
|
|
345
|
+
|
|
346
|
+
queryClient.invalidateQueries({
|
|
347
|
+
queryKey: queryKey
|
|
348
|
+
})
|
|
349
|
+
queryClient.invalidateQueries({
|
|
350
|
+
queryKey: queryKey,
|
|
351
|
+
...filters
|
|
352
|
+
})
|
|
353
|
+
queryClient.invalidateQueries({
|
|
354
|
+
queryKey: queryKey,
|
|
355
|
+
...filters
|
|
356
|
+
}, invalidateOptions)
|
|
357
|
+
queryClient.invalidateQueries({
|
|
358
|
+
queryKey: queryKey,
|
|
359
|
+
stale: true,
|
|
360
|
+
...filters
|
|
361
|
+
})
|
|
362
|
+
queryClient.invalidateQueries({
|
|
363
|
+
queryKey: queryKey,
|
|
364
|
+
stale: true,
|
|
365
|
+
...filters
|
|
366
|
+
}, invalidateOptions)
|
|
367
|
+
queryClient.invalidateQueries({ queryKey: globalQueryKey, ...filters, stale: true })
|
|
368
|
+
queryClient.invalidateQueries({ queryKey: globalQueryKey, ...filters, stale: true }, invalidateOptions)
|
|
369
|
+
|
|
370
|
+
queryClient.isFetching({
|
|
371
|
+
queryKey: globalQueryKey
|
|
372
|
+
})
|
|
373
|
+
queryClient.isFetching({
|
|
374
|
+
queryKey: globalQueryKey,
|
|
375
|
+
...filters
|
|
376
|
+
})
|
|
377
|
+
queryClient.isFetching({
|
|
378
|
+
queryKey: globalQueryKey,
|
|
379
|
+
type: 'all',
|
|
380
|
+
exact: true
|
|
381
|
+
})
|
|
382
|
+
queryClient.isFetching({
|
|
383
|
+
queryKey: globalQueryKey,
|
|
384
|
+
...filters
|
|
385
|
+
})
|
|
386
|
+
queryClient.isFetching({ queryKey: globalQueryKey, ...filters, stale: true })
|
|
387
|
+
// Stays as it is because the code couldn't infer the type of the "queryKeysFromAnotherModule" identifier.
|
|
388
|
+
queryClient.isFetching(queryKeysFromAnotherModule)
|
|
389
|
+
|
|
390
|
+
queryClient.refetchQueries({
|
|
391
|
+
queryKey: queryKey
|
|
392
|
+
})
|
|
393
|
+
queryClient.refetchQueries({
|
|
394
|
+
queryKey: queryKey,
|
|
395
|
+
...filters
|
|
396
|
+
})
|
|
397
|
+
queryClient.refetchQueries({
|
|
398
|
+
queryKey: queryKey,
|
|
399
|
+
...filters
|
|
400
|
+
}, refetchOptions)
|
|
401
|
+
queryClient.refetchQueries({
|
|
402
|
+
queryKey: queryKey,
|
|
403
|
+
...filters
|
|
404
|
+
}, { ...refetchOptions, cancelRefetch: true })
|
|
405
|
+
queryClient.refetchQueries({ queryKey: queryKey, ...filters })
|
|
406
|
+
queryClient.refetchQueries({ queryKey: queryKey, ...filters }, { ...refetchOptions, cancelRefetch: true })
|
|
407
|
+
// Stays as it is because the code couldn't infer the type of the "queryKeysFromAnotherModule" identifier.
|
|
408
|
+
queryClient.refetchQueries(queryKeysFromAnotherModule)
|
|
409
|
+
queryClient.refetchQueries(queryKeysFromAnotherModule, filters)
|
|
410
|
+
queryClient.refetchQueries(queryKeysFromAnotherModule, filters, refetchOptions)
|
|
411
|
+
|
|
412
|
+
queryClient.removeQueries({
|
|
413
|
+
queryKey: queryKey
|
|
414
|
+
})
|
|
415
|
+
queryClient.removeQueries({
|
|
416
|
+
queryKey: queryKey,
|
|
417
|
+
...filters
|
|
418
|
+
})
|
|
419
|
+
queryClient.removeQueries({
|
|
420
|
+
queryKey: queryKey,
|
|
421
|
+
...filters,
|
|
422
|
+
stale: true
|
|
423
|
+
})
|
|
424
|
+
queryClient.removeQueries({ queryKey, ...filters, stale: true })
|
|
425
|
+
// Stays as it is because the code couldn't infer the type of the "queryKeysFromAnotherModule" identifier.
|
|
426
|
+
queryClient.removeQueries(queryKeysFromAnotherModule)
|
|
427
|
+
queryClient.removeQueries(queryKeysFromAnotherModule, filters)
|
|
428
|
+
|
|
429
|
+
queryClient.resetQueries({
|
|
430
|
+
queryKey: queryKey
|
|
431
|
+
})
|
|
432
|
+
queryClient.resetQueries({
|
|
433
|
+
queryKey: queryKey,
|
|
434
|
+
...filters
|
|
435
|
+
})
|
|
436
|
+
queryClient.resetQueries({
|
|
437
|
+
queryKey: queryKey,
|
|
438
|
+
...filters
|
|
439
|
+
}, resetOptions)
|
|
440
|
+
queryClient.resetQueries({
|
|
441
|
+
queryKey: queryKey,
|
|
442
|
+
...filters,
|
|
443
|
+
stale: true
|
|
444
|
+
})
|
|
445
|
+
queryClient.resetQueries({
|
|
446
|
+
queryKey: queryKey,
|
|
447
|
+
...filters,
|
|
448
|
+
stale: true
|
|
449
|
+
}, resetOptions)
|
|
450
|
+
queryClient.resetQueries({ queryKey, ...filters, stale: true })
|
|
451
|
+
queryClient.resetQueries({ queryKey, ...filters, stale: true }, resetOptions)
|
|
452
|
+
// Stays as it is because the code couldn't infer the type of the "queryKeysFromAnotherModule" identifier.
|
|
453
|
+
queryClient.resetQueries(queryKeysFromAnotherModule)
|
|
454
|
+
queryClient.resetQueries(queryKeysFromAnotherModule, filters)
|
|
455
|
+
queryClient.resetQueries(queryKeysFromAnotherModule, filters, resetOptions)
|
|
456
|
+
|
|
457
|
+
queryClient.fetchQuery({
|
|
458
|
+
queryKey: queryKey
|
|
459
|
+
})
|
|
460
|
+
queryClient.fetchQuery({
|
|
461
|
+
queryKey: queryKey,
|
|
462
|
+
...fetchOptions
|
|
463
|
+
})
|
|
464
|
+
queryClient.fetchQuery({
|
|
465
|
+
queryKey: queryKey,
|
|
466
|
+
networkMode: 'always',
|
|
467
|
+
...fetchOptions
|
|
468
|
+
})
|
|
469
|
+
queryClient.fetchQuery({
|
|
470
|
+
queryKey: queryKey,
|
|
471
|
+
queryFn: queryFn,
|
|
472
|
+
...fetchOptions
|
|
473
|
+
})
|
|
474
|
+
queryClient.fetchQuery({
|
|
475
|
+
queryKey: queryKey,
|
|
476
|
+
queryFn: () => 'data',
|
|
477
|
+
networkMode: 'always',
|
|
478
|
+
...fetchOptions
|
|
479
|
+
})
|
|
480
|
+
// Stays as it is because the code couldn't infer the type of the "queryKeysFromAnotherModule" identifier.
|
|
481
|
+
queryClient.fetchQuery(queryKeysFromAnotherModule)
|
|
482
|
+
queryClient.fetchQuery(queryKeysFromAnotherModule, fetchOptions)
|
|
483
|
+
queryClient.fetchQuery(queryKeysFromAnotherModule, queryFn, fetchOptions)
|
|
484
|
+
}
|
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
// eslint-disable-next-line @typescript-eslint/no-var-requires
|
|
2
|
+
const createUtilsObject = require('../../utils')
|
|
3
|
+
// eslint-disable-next-line @typescript-eslint/no-var-requires
|
|
4
|
+
const transformFilterAwareUsages = require('./transformers/filter-aware-usage-transformer')
|
|
5
|
+
// eslint-disable-next-line @typescript-eslint/no-var-requires
|
|
6
|
+
const transformQueryFnAwareUsages = require('./transformers/query-fn-aware-usage-transformer')
|
|
7
|
+
|
|
8
|
+
module.exports = (file, api) => {
|
|
9
|
+
const jscodeshift = api.jscodeshift
|
|
10
|
+
const root = jscodeshift(file.source)
|
|
11
|
+
const utils = createUtilsObject({ root, jscodeshift })
|
|
12
|
+
const filePath = file.path
|
|
13
|
+
|
|
14
|
+
const dependencies = { jscodeshift, utils, root, filePath }
|
|
15
|
+
|
|
16
|
+
transformFilterAwareUsages({
|
|
17
|
+
...dependencies,
|
|
18
|
+
config: {
|
|
19
|
+
keyName: 'queryKey',
|
|
20
|
+
queryClientMethods: [
|
|
21
|
+
'cancelQueries',
|
|
22
|
+
'getQueriesData',
|
|
23
|
+
'invalidateQueries',
|
|
24
|
+
'isFetching',
|
|
25
|
+
'refetchQueries',
|
|
26
|
+
'removeQueries',
|
|
27
|
+
'resetQueries',
|
|
28
|
+
// 'setQueriesData',
|
|
29
|
+
],
|
|
30
|
+
hooks: ['useIsFetching'],
|
|
31
|
+
},
|
|
32
|
+
})
|
|
33
|
+
|
|
34
|
+
transformFilterAwareUsages({
|
|
35
|
+
...dependencies,
|
|
36
|
+
config: {
|
|
37
|
+
keyName: 'mutationKey',
|
|
38
|
+
queryClientMethods: [],
|
|
39
|
+
hooks: ['useIsMutating'],
|
|
40
|
+
},
|
|
41
|
+
})
|
|
42
|
+
|
|
43
|
+
transformQueryFnAwareUsages({
|
|
44
|
+
...dependencies,
|
|
45
|
+
config: {
|
|
46
|
+
keyName: 'queryKey',
|
|
47
|
+
queryClientMethods: [
|
|
48
|
+
'ensureQueryData',
|
|
49
|
+
'fetchQuery',
|
|
50
|
+
'prefetchQuery',
|
|
51
|
+
'fetchInfiniteQuery',
|
|
52
|
+
'prefetchInfiniteQuery',
|
|
53
|
+
],
|
|
54
|
+
hooks: [],
|
|
55
|
+
},
|
|
56
|
+
})
|
|
57
|
+
|
|
58
|
+
return root.toSource({ quote: 'single' })
|
|
59
|
+
}
|
|
@@ -0,0 +1,153 @@
|
|
|
1
|
+
// eslint-disable-next-line @typescript-eslint/no-var-requires
|
|
2
|
+
const createV5UtilsObject = require('../utils')
|
|
3
|
+
// eslint-disable-next-line @typescript-eslint/no-var-requires
|
|
4
|
+
const UnknownUsageError = require('../utils/unknown-usage-error')
|
|
5
|
+
// eslint-disable-next-line @typescript-eslint/no-var-requires
|
|
6
|
+
const createQueryClientTransformer = require('../../../utils/transformers/query-client-transformer')
|
|
7
|
+
// eslint-disable-next-line @typescript-eslint/no-var-requires
|
|
8
|
+
const createQueryCacheTransformer = require('../../../utils/transformers/query-cache-transformer')
|
|
9
|
+
// eslint-disable-next-line @typescript-eslint/no-var-requires
|
|
10
|
+
const createUseQueryLikeTransformer = require('../../../utils/transformers/use-query-like-transformer')
|
|
11
|
+
|
|
12
|
+
/**
|
|
13
|
+
* @param {import('jscodeshift').api} jscodeshift
|
|
14
|
+
* @param {Object} utils
|
|
15
|
+
* @param {import('jscodeshift').Collection} root
|
|
16
|
+
* @param {string} filePath
|
|
17
|
+
* @param {{keyName: "mutationKey"|"queryKey", queryClientMethods: ReadonlyArray<string>, hooks: ReadonlyArray<string>}} config
|
|
18
|
+
*/
|
|
19
|
+
const transformFilterAwareUsages = ({
|
|
20
|
+
jscodeshift,
|
|
21
|
+
utils,
|
|
22
|
+
root,
|
|
23
|
+
filePath,
|
|
24
|
+
config,
|
|
25
|
+
}) => {
|
|
26
|
+
const v5Utils = createV5UtilsObject({ jscodeshift, utils })
|
|
27
|
+
|
|
28
|
+
/**
|
|
29
|
+
* @param {import('jscodeshift').CallExpression} node
|
|
30
|
+
* @param {"mutationKey"|"queryKey"} keyName
|
|
31
|
+
* @returns {boolean}
|
|
32
|
+
*/
|
|
33
|
+
const canSkipReplacement = (node, keyName) => {
|
|
34
|
+
const callArguments = node.arguments
|
|
35
|
+
|
|
36
|
+
const hasKeyProperty = () =>
|
|
37
|
+
callArguments[0].properties.some(
|
|
38
|
+
(property) =>
|
|
39
|
+
utils.isObjectProperty(property) && property.key.name !== keyName,
|
|
40
|
+
)
|
|
41
|
+
|
|
42
|
+
/**
|
|
43
|
+
* This call has at least one argument. If it's an object expression and contains the "queryKey" or "mutationKey"
|
|
44
|
+
* field, the transformation can be skipped, because it's already matching the expected signature.
|
|
45
|
+
*/
|
|
46
|
+
return (
|
|
47
|
+
callArguments.length > 0 &&
|
|
48
|
+
utils.isObjectExpression(callArguments[0]) &&
|
|
49
|
+
hasKeyProperty()
|
|
50
|
+
)
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
/**
|
|
54
|
+
* This function checks whether the given object property is a spread element or a property that's not named
|
|
55
|
+
* "queryKey" or "mutationKey".
|
|
56
|
+
*
|
|
57
|
+
* @param {import('jscodeshift').ObjectProperty} property
|
|
58
|
+
* @returns {boolean}
|
|
59
|
+
*/
|
|
60
|
+
const predicate = (property) => {
|
|
61
|
+
const isSpreadElement = utils.isSpreadElement(property)
|
|
62
|
+
const isObjectProperty = utils.isObjectProperty(property)
|
|
63
|
+
|
|
64
|
+
return (
|
|
65
|
+
isSpreadElement ||
|
|
66
|
+
(isObjectProperty && property.key.name !== config.keyName)
|
|
67
|
+
)
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
const replacer = (path) => {
|
|
71
|
+
const node = path.node
|
|
72
|
+
|
|
73
|
+
try {
|
|
74
|
+
// If the given method/function call matches certain criteria, the node doesn't need to be replaced, this step can be skipped.
|
|
75
|
+
if (canSkipReplacement(node, config.keyName)) {
|
|
76
|
+
return node
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
/**
|
|
80
|
+
* Here we attempt to determine the first parameter of the function call. If it's an array expression or an
|
|
81
|
+
* identifier that references an array expression then we create an object property from it.
|
|
82
|
+
*
|
|
83
|
+
* @type {import('jscodeshift').Property|undefined}
|
|
84
|
+
*/
|
|
85
|
+
const keyProperty = v5Utils.transformArgumentToKey(
|
|
86
|
+
path,
|
|
87
|
+
node.arguments[0],
|
|
88
|
+
config.keyName,
|
|
89
|
+
filePath,
|
|
90
|
+
)
|
|
91
|
+
|
|
92
|
+
/**
|
|
93
|
+
* The first parameter couldn't be transformed into an object property, so it's time to throw an exception,
|
|
94
|
+
* it will notify the consumers that they need to rewrite this usage manually.
|
|
95
|
+
*/
|
|
96
|
+
if (!keyProperty) {
|
|
97
|
+
throw new UnknownUsageError(node, filePath)
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
const parameters = [jscodeshift.objectExpression([keyProperty])]
|
|
101
|
+
const secondParameter = node.arguments[1]
|
|
102
|
+
|
|
103
|
+
if (secondParameter) {
|
|
104
|
+
const createdObjectExpression = parameters[0]
|
|
105
|
+
|
|
106
|
+
/**
|
|
107
|
+
* If it has a second argument, and it's an object expression, then we get the properties from it
|
|
108
|
+
* (except the "queryKey" or "mutationKey" properties), because these arguments will also be moved to the
|
|
109
|
+
* newly created object expression.
|
|
110
|
+
*/
|
|
111
|
+
if (utils.isObjectExpression(secondParameter)) {
|
|
112
|
+
v5Utils.copyPropertiesFromSource(
|
|
113
|
+
secondParameter,
|
|
114
|
+
createdObjectExpression,
|
|
115
|
+
predicate,
|
|
116
|
+
)
|
|
117
|
+
} else {
|
|
118
|
+
// Otherwise, we simply spread the second parameter in the newly created object expression.
|
|
119
|
+
createdObjectExpression.properties.push(
|
|
120
|
+
jscodeshift.spreadElement(secondParameter),
|
|
121
|
+
)
|
|
122
|
+
}
|
|
123
|
+
}
|
|
124
|
+
|
|
125
|
+
// The rest of the parameters can be simply pushed to the parameters object so all will be kept.
|
|
126
|
+
parameters.push(...node.arguments.slice(2))
|
|
127
|
+
|
|
128
|
+
return jscodeshift.callExpression(node.original.callee, parameters)
|
|
129
|
+
} catch (error) {
|
|
130
|
+
utils.warn(
|
|
131
|
+
error.name === UnknownUsageError.name
|
|
132
|
+
? error.message
|
|
133
|
+
: `An unknown error occurred while processing the "${filePath}" file. Please review this file, because the codemod couldn't be applied.`,
|
|
134
|
+
)
|
|
135
|
+
|
|
136
|
+
return node
|
|
137
|
+
}
|
|
138
|
+
}
|
|
139
|
+
|
|
140
|
+
createQueryClientTransformer({ jscodeshift, utils, root }).execute(
|
|
141
|
+
config.queryClientMethods,
|
|
142
|
+
replacer,
|
|
143
|
+
)
|
|
144
|
+
|
|
145
|
+
createUseQueryLikeTransformer({ jscodeshift, utils, root }).execute(
|
|
146
|
+
config.hooks,
|
|
147
|
+
replacer,
|
|
148
|
+
)
|
|
149
|
+
|
|
150
|
+
createQueryCacheTransformer({ jscodeshift, utils, root }).execute(replacer)
|
|
151
|
+
}
|
|
152
|
+
|
|
153
|
+
module.exports = transformFilterAwareUsages
|