@tanstack/react-query 5.0.0-alpha.3 → 5.0.0-alpha.31
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/utils/index.js +205 -0
- package/build/codemods/utils/transformers/query-cache-transformer.js +116 -0
- package/build/codemods/utils/transformers/query-client-transformer.js +48 -0
- package/build/codemods/utils/transformers/use-query-like-transformer.js +32 -0
- package/build/codemods/v4/__testfixtures__/default-import.input.tsx +94 -0
- package/build/codemods/v4/__testfixtures__/default-import.output.tsx +96 -0
- package/build/codemods/v4/__testfixtures__/named-import.input.tsx +96 -0
- package/build/codemods/v4/__testfixtures__/named-import.output.tsx +98 -0
- package/build/codemods/v4/__testfixtures__/namespaced-import.input.tsx +86 -0
- package/build/codemods/v4/__testfixtures__/namespaced-import.output.tsx +88 -0
- package/build/codemods/v4/__testfixtures__/parameter-is-identifier.input.tsx +49 -0
- package/build/codemods/v4/__testfixtures__/parameter-is-identifier.output.tsx +49 -0
- package/build/codemods/v4/__testfixtures__/parameter-is-object-expression.input.tsx +128 -0
- package/build/codemods/v4/__testfixtures__/parameter-is-object-expression.output.tsx +175 -0
- package/build/codemods/v4/__testfixtures__/replace-import-specifier.input.tsx +10 -0
- package/build/codemods/v4/__testfixtures__/replace-import-specifier.output.tsx +10 -0
- package/build/codemods/v4/__testfixtures__/type-arguments.input.tsx +25 -0
- package/build/codemods/v4/__testfixtures__/type-arguments.output.tsx +31 -0
- package/build/codemods/v4/__tests__/key-transformation.test.js +32 -0
- package/build/codemods/v4/__tests__/replace-import-specifier.test.js +12 -0
- package/build/codemods/v4/key-transformation.js +138 -0
- package/build/codemods/v4/replace-import-specifier.js +25 -0
- package/build/codemods/v4/utils/replacers/key-replacer.js +164 -0
- package/build/codemods/v5/remove-overloads/__testfixtures__/default-import.input.tsx +199 -0
- package/build/codemods/v5/remove-overloads/__testfixtures__/default-import.output.tsx +484 -0
- package/build/codemods/v5/remove-overloads/__tests__/remove-overloads.test.js +6 -0
- package/build/codemods/v5/remove-overloads/remove-overloads.js +59 -0
- package/build/codemods/v5/remove-overloads/transformers/filter-aware-usage-transformer.js +153 -0
- package/build/codemods/v5/remove-overloads/transformers/query-fn-aware-usage-transformer.js +188 -0
- package/build/codemods/v5/remove-overloads/utils/index.js +124 -0
- package/build/codemods/v5/remove-overloads/utils/unknown-usage-error.js +26 -0
- package/build/lib/HydrationBoundary.d.ts +1 -0
- package/build/lib/HydrationBoundary.d.ts.map +1 -0
- package/build/lib/HydrationBoundary.esm.js +1 -0
- package/build/lib/HydrationBoundary.esm.js.map +1 -1
- package/build/lib/HydrationBoundary.js +1 -0
- package/build/lib/HydrationBoundary.js.map +1 -1
- package/build/lib/HydrationBoundary.mjs +1 -0
- package/build/lib/HydrationBoundary.mjs.map +1 -1
- package/build/lib/QueryClientProvider.d.ts +1 -0
- package/build/lib/QueryClientProvider.d.ts.map +1 -0
- package/build/lib/QueryClientProvider.esm.js +1 -0
- package/build/lib/QueryClientProvider.esm.js.map +1 -1
- package/build/lib/QueryClientProvider.js +1 -0
- package/build/lib/QueryClientProvider.js.map +1 -1
- package/build/lib/QueryClientProvider.mjs +1 -0
- package/build/lib/QueryClientProvider.mjs.map +1 -1
- package/build/lib/QueryErrorResetBoundary.d.ts +1 -0
- package/build/lib/QueryErrorResetBoundary.d.ts.map +1 -0
- package/build/lib/QueryErrorResetBoundary.esm.js +1 -0
- package/build/lib/QueryErrorResetBoundary.esm.js.map +1 -1
- package/build/lib/QueryErrorResetBoundary.js +1 -0
- package/build/lib/QueryErrorResetBoundary.js.map +1 -1
- package/build/lib/QueryErrorResetBoundary.mjs +1 -0
- package/build/lib/QueryErrorResetBoundary.mjs.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 -3
- 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 +3 -3
- package/build/lib/__tests__/utils.d.ts.map +1 -0
- package/build/lib/errorBoundaryUtils.d.ts +4 -3
- package/build/lib/errorBoundaryUtils.d.ts.map +1 -0
- package/build/lib/errorBoundaryUtils.esm.js +4 -3
- package/build/lib/errorBoundaryUtils.esm.js.map +1 -1
- package/build/lib/errorBoundaryUtils.js +4 -3
- package/build/lib/errorBoundaryUtils.js.map +1 -1
- package/build/lib/errorBoundaryUtils.mjs +4 -3
- package/build/lib/errorBoundaryUtils.mjs.map +1 -1
- package/build/lib/index.d.ts +2 -1
- package/build/lib/index.d.ts.map +1 -0
- package/build/lib/index.esm.js +1 -1
- package/build/lib/index.js +1 -0
- package/build/lib/index.js.map +1 -1
- package/build/lib/index.mjs +1 -1
- package/build/lib/isRestoring.d.ts +1 -0
- package/build/lib/isRestoring.d.ts.map +1 -0
- package/build/lib/isRestoring.esm.js +1 -0
- package/build/lib/isRestoring.esm.js.map +1 -1
- package/build/lib/isRestoring.js +1 -0
- package/build/lib/isRestoring.js.map +1 -1
- package/build/lib/isRestoring.mjs +1 -0
- package/build/lib/isRestoring.mjs.map +1 -1
- package/build/lib/suspense.d.ts +2 -1
- package/build/lib/suspense.d.ts.map +1 -0
- package/build/lib/suspense.esm.js +2 -9
- package/build/lib/suspense.esm.js.map +1 -1
- package/build/lib/suspense.js +2 -9
- package/build/lib/suspense.js.map +1 -1
- package/build/lib/suspense.mjs +1 -8
- package/build/lib/suspense.mjs.map +1 -1
- package/build/lib/types.d.ts +1 -0
- package/build/lib/types.d.ts.map +1 -0
- package/build/lib/useBaseQuery.d.ts +1 -0
- package/build/lib/useBaseQuery.d.ts.map +1 -0
- package/build/lib/useBaseQuery.esm.js +2 -12
- package/build/lib/useBaseQuery.esm.js.map +1 -1
- package/build/lib/useBaseQuery.js +2 -12
- package/build/lib/useBaseQuery.js.map +1 -1
- package/build/lib/useBaseQuery.mjs +2 -12
- package/build/lib/useBaseQuery.mjs.map +1 -1
- package/build/lib/useInfiniteQuery.d.ts +1 -0
- package/build/lib/useInfiniteQuery.d.ts.map +1 -0
- package/build/lib/useInfiniteQuery.esm.js +1 -0
- package/build/lib/useInfiniteQuery.esm.js.map +1 -1
- package/build/lib/useInfiniteQuery.js +1 -0
- package/build/lib/useInfiniteQuery.js.map +1 -1
- package/build/lib/useInfiniteQuery.mjs +1 -0
- package/build/lib/useInfiniteQuery.mjs.map +1 -1
- package/build/lib/useIsFetching.d.ts +1 -0
- package/build/lib/useIsFetching.d.ts.map +1 -0
- package/build/lib/useIsFetching.esm.js +1 -0
- package/build/lib/useIsFetching.esm.js.map +1 -1
- package/build/lib/useIsFetching.js +1 -0
- package/build/lib/useIsFetching.js.map +1 -1
- package/build/lib/useIsFetching.mjs +1 -0
- package/build/lib/useIsFetching.mjs.map +1 -1
- package/build/lib/useMutation.d.ts +1 -0
- package/build/lib/useMutation.d.ts.map +1 -0
- package/build/lib/useMutation.esm.js +2 -1
- package/build/lib/useMutation.esm.js.map +1 -1
- package/build/lib/useMutation.js +2 -1
- package/build/lib/useMutation.js.map +1 -1
- package/build/lib/useMutation.mjs +2 -1
- package/build/lib/useMutation.mjs.map +1 -1
- package/build/lib/useMutationState.d.ts +4 -3
- package/build/lib/useMutationState.d.ts.map +1 -0
- package/build/lib/useMutationState.esm.js +1 -0
- package/build/lib/useMutationState.esm.js.map +1 -1
- package/build/lib/useMutationState.js +1 -0
- package/build/lib/useMutationState.js.map +1 -1
- package/build/lib/useMutationState.mjs +1 -0
- package/build/lib/useMutationState.mjs.map +1 -1
- package/build/lib/useQueries.d.ts +3 -3
- package/build/lib/useQueries.d.ts.map +1 -0
- package/build/lib/useQueries.esm.js +20 -16
- package/build/lib/useQueries.esm.js.map +1 -1
- package/build/lib/useQueries.js +20 -16
- package/build/lib/useQueries.js.map +1 -1
- package/build/lib/useQueries.mjs +12 -11
- package/build/lib/useQueries.mjs.map +1 -1
- package/build/lib/useQuery.d.ts +3 -0
- package/build/lib/useQuery.d.ts.map +1 -0
- package/build/lib/useQuery.esm.js +6 -1
- package/build/lib/useQuery.esm.js.map +1 -1
- package/build/lib/useQuery.js +6 -0
- package/build/lib/useQuery.js.map +1 -1
- package/build/lib/useQuery.mjs +6 -1
- package/build/lib/useQuery.mjs.map +1 -1
- package/build/lib/utils.d.ts +1 -0
- package/build/lib/utils.d.ts.map +1 -0
- package/build/umd/index.development.js +124 -155
- package/build/umd/index.development.js.map +1 -1
- package/build/umd/index.production.js +1 -1
- package/build/umd/index.production.js.map +1 -1
- package/package.json +9 -4
- package/src/__tests__/HydrationBoundary.test.tsx +4 -3
- package/src/__tests__/QueryClientProvider.test.tsx +2 -1
- package/src/__tests__/QueryResetErrorBoundary.test.tsx +753 -620
- package/src/__tests__/ssr-hydration.test.tsx +11 -10
- package/src/__tests__/ssr.test.tsx +4 -7
- package/src/__tests__/suspense.test.tsx +17 -98
- package/src/__tests__/useInfiniteQuery.test.tsx +18 -16
- package/src/__tests__/useInfiniteQuery.type.test.tsx +94 -13
- package/src/__tests__/useMutation.test.tsx +25 -24
- package/src/__tests__/useMutationState.test.tsx +24 -58
- package/src/__tests__/useQueries.test.tsx +34 -163
- package/src/__tests__/useQuery.test.tsx +234 -365
- package/src/__tests__/useQuery.types.test.tsx +21 -1
- package/src/__tests__/utils.tsx +3 -2
- package/src/errorBoundaryUtils.ts +6 -5
- package/src/index.ts +1 -1
- package/src/suspense.ts +3 -11
- package/src/useBaseQuery.ts +2 -20
- 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 +20 -19
- package/src/useQuery.ts +23 -0
|
@@ -0,0 +1,205 @@
|
|
|
1
|
+
module.exports = ({ root, jscodeshift }) => {
|
|
2
|
+
const findImportIdentifierOf = (importSpecifiers, identifier) => {
|
|
3
|
+
const specifier = importSpecifiers
|
|
4
|
+
.filter((node) => node.value.imported.name === identifier)
|
|
5
|
+
.paths()
|
|
6
|
+
|
|
7
|
+
if (specifier.length > 0) {
|
|
8
|
+
return specifier[0].value.local
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
return jscodeshift.identifier(identifier)
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
const findImportSpecifiers = () =>
|
|
15
|
+
root
|
|
16
|
+
.find(jscodeshift.ImportDeclaration, {
|
|
17
|
+
source: {
|
|
18
|
+
value: 'react-query',
|
|
19
|
+
},
|
|
20
|
+
})
|
|
21
|
+
.find(jscodeshift.ImportSpecifier, {})
|
|
22
|
+
|
|
23
|
+
const locateImports = (identifiers) => {
|
|
24
|
+
const findNamespaceImportIdentifier = () => {
|
|
25
|
+
const specifier = root
|
|
26
|
+
.find(jscodeshift.ImportDeclaration, {
|
|
27
|
+
source: {
|
|
28
|
+
value: 'react-query',
|
|
29
|
+
},
|
|
30
|
+
})
|
|
31
|
+
.find(jscodeshift.ImportNamespaceSpecifier)
|
|
32
|
+
.paths()
|
|
33
|
+
|
|
34
|
+
return specifier.length > 0 ? specifier[0].value.local : null
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
/**
|
|
38
|
+
* First, we search for the namespace import identifier because if we have any, we assume the consumer uses
|
|
39
|
+
* namespace imports. In this case, we won't search for named imports at all.
|
|
40
|
+
*/
|
|
41
|
+
const namespaceImportIdentifier = findNamespaceImportIdentifier()
|
|
42
|
+
|
|
43
|
+
if (namespaceImportIdentifier) {
|
|
44
|
+
const identifierMap = {}
|
|
45
|
+
|
|
46
|
+
for (const identifier of identifiers) {
|
|
47
|
+
identifierMap[identifier] = jscodeshift.identifier(identifier)
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
return {
|
|
51
|
+
namespace: namespaceImportIdentifier,
|
|
52
|
+
...identifierMap,
|
|
53
|
+
}
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
const importSpecifiers = findImportSpecifiers()
|
|
57
|
+
const identifierMap = {}
|
|
58
|
+
|
|
59
|
+
for (const identifier of identifiers) {
|
|
60
|
+
identifierMap[identifier] = findImportIdentifierOf(
|
|
61
|
+
importSpecifiers,
|
|
62
|
+
identifier,
|
|
63
|
+
)
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
return {
|
|
67
|
+
namespace: null,
|
|
68
|
+
...identifierMap,
|
|
69
|
+
}
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
const findAllMethodCalls = () =>
|
|
73
|
+
root
|
|
74
|
+
// First, we need to find all method calls.
|
|
75
|
+
.find(jscodeshift.CallExpression, {
|
|
76
|
+
callee: {
|
|
77
|
+
type: jscodeshift.MemberExpression.name,
|
|
78
|
+
property: {
|
|
79
|
+
type: jscodeshift.Identifier.name,
|
|
80
|
+
},
|
|
81
|
+
},
|
|
82
|
+
})
|
|
83
|
+
|
|
84
|
+
const findQueryClientIdentifiers = (importIdentifiers) =>
|
|
85
|
+
root
|
|
86
|
+
.find(jscodeshift.VariableDeclarator, {})
|
|
87
|
+
.filter((node) => {
|
|
88
|
+
if (node.value.init) {
|
|
89
|
+
const initializer = node.value.init
|
|
90
|
+
|
|
91
|
+
return (
|
|
92
|
+
isClassInstantiationOf(
|
|
93
|
+
initializer,
|
|
94
|
+
getSelectorByImports(importIdentifiers, 'QueryClient'),
|
|
95
|
+
) ||
|
|
96
|
+
isFunctionCallOf(
|
|
97
|
+
initializer,
|
|
98
|
+
getSelectorByImports(importIdentifiers, 'useQueryClient'),
|
|
99
|
+
)
|
|
100
|
+
)
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
return false
|
|
104
|
+
})
|
|
105
|
+
.paths()
|
|
106
|
+
.map((node) => node.value.id.name)
|
|
107
|
+
|
|
108
|
+
const isCallExpression = (node) =>
|
|
109
|
+
jscodeshift.match(node, { type: jscodeshift.CallExpression.name })
|
|
110
|
+
|
|
111
|
+
const isIdentifier = (node) =>
|
|
112
|
+
jscodeshift.match(node, { type: jscodeshift.Identifier.name })
|
|
113
|
+
|
|
114
|
+
const isMemberExpression = (node) =>
|
|
115
|
+
jscodeshift.match(node, { type: jscodeshift.MemberExpression.name })
|
|
116
|
+
|
|
117
|
+
const isNewExpression = (node) =>
|
|
118
|
+
jscodeshift.match(node, { type: jscodeshift.NewExpression.name })
|
|
119
|
+
|
|
120
|
+
const isArrayExpression = (node) =>
|
|
121
|
+
jscodeshift.match(node, { type: jscodeshift.ArrayExpression.name })
|
|
122
|
+
|
|
123
|
+
const isObjectExpression = (node) =>
|
|
124
|
+
jscodeshift.match(node, { type: jscodeshift.ObjectExpression.name })
|
|
125
|
+
|
|
126
|
+
const isObjectProperty = (node) =>
|
|
127
|
+
jscodeshift.match(node, { type: jscodeshift.ObjectProperty.name })
|
|
128
|
+
|
|
129
|
+
const isSpreadElement = (node) =>
|
|
130
|
+
jscodeshift.match(node, { type: jscodeshift.SpreadElement.name })
|
|
131
|
+
|
|
132
|
+
/**
|
|
133
|
+
* @param {import('jscodeshift').Node} node
|
|
134
|
+
* @returns {boolean}
|
|
135
|
+
*/
|
|
136
|
+
const isFunctionDefinition = (node) => {
|
|
137
|
+
const isArrowFunctionExpression = jscodeshift.match(node, {
|
|
138
|
+
type: jscodeshift.ArrowFunctionExpression.name,
|
|
139
|
+
})
|
|
140
|
+
const isFunctionExpression = jscodeshift.match(node, {
|
|
141
|
+
type: jscodeshift.FunctionExpression.name,
|
|
142
|
+
})
|
|
143
|
+
|
|
144
|
+
return isArrowFunctionExpression || isFunctionExpression
|
|
145
|
+
}
|
|
146
|
+
|
|
147
|
+
const warn = (message) => {
|
|
148
|
+
if (process.env.NODE_ENV !== 'test') {
|
|
149
|
+
console.warn(message)
|
|
150
|
+
}
|
|
151
|
+
}
|
|
152
|
+
|
|
153
|
+
const isClassInstantiationOf = (node, selector) => {
|
|
154
|
+
if (!isNewExpression(node)) {
|
|
155
|
+
return false
|
|
156
|
+
}
|
|
157
|
+
|
|
158
|
+
const parts = selector.split('.')
|
|
159
|
+
|
|
160
|
+
return parts.length === 1
|
|
161
|
+
? isIdentifier(node.callee) && node.callee.name === parts[0]
|
|
162
|
+
: isMemberExpression(node.callee) &&
|
|
163
|
+
node.callee.object.name === parts[0] &&
|
|
164
|
+
node.callee.property.name === parts[1]
|
|
165
|
+
}
|
|
166
|
+
|
|
167
|
+
const isFunctionCallOf = (node, selector) => {
|
|
168
|
+
if (!isCallExpression(node)) {
|
|
169
|
+
return false
|
|
170
|
+
}
|
|
171
|
+
|
|
172
|
+
const parts = selector.split('.')
|
|
173
|
+
|
|
174
|
+
return parts.length === 1
|
|
175
|
+
? isIdentifier(node.callee) && node.callee.name === parts[0]
|
|
176
|
+
: isMemberExpression(node.callee) &&
|
|
177
|
+
node.callee.object.name === parts[0] &&
|
|
178
|
+
node.callee.property.name === parts[1]
|
|
179
|
+
}
|
|
180
|
+
|
|
181
|
+
const getSelectorByImports = (imports, path) =>
|
|
182
|
+
imports.namespace
|
|
183
|
+
? `${imports.namespace.name}.${imports[path].name}`
|
|
184
|
+
: imports[path].name
|
|
185
|
+
|
|
186
|
+
return {
|
|
187
|
+
findAllMethodCalls,
|
|
188
|
+
getSelectorByImports,
|
|
189
|
+
isCallExpression,
|
|
190
|
+
isClassInstantiationOf,
|
|
191
|
+
isFunctionCallOf,
|
|
192
|
+
isIdentifier,
|
|
193
|
+
isMemberExpression,
|
|
194
|
+
isArrayExpression,
|
|
195
|
+
isObjectExpression,
|
|
196
|
+
isObjectProperty,
|
|
197
|
+
isSpreadElement,
|
|
198
|
+
isFunctionDefinition,
|
|
199
|
+
locateImports,
|
|
200
|
+
warn,
|
|
201
|
+
queryClient: {
|
|
202
|
+
findQueryClientIdentifiers,
|
|
203
|
+
},
|
|
204
|
+
}
|
|
205
|
+
}
|
|
@@ -0,0 +1,116 @@
|
|
|
1
|
+
module.exports = ({ jscodeshift, utils, root }) => {
|
|
2
|
+
const isGetQueryCacheMethodCall = (
|
|
3
|
+
initializer,
|
|
4
|
+
importIdentifiers,
|
|
5
|
+
knownQueryClientIds,
|
|
6
|
+
) => {
|
|
7
|
+
const isKnownQueryClient = (node) =>
|
|
8
|
+
utils.isIdentifier(node) && knownQueryClientIds.includes(node.name)
|
|
9
|
+
|
|
10
|
+
const isGetQueryCacheIdentifier = (node) =>
|
|
11
|
+
utils.isIdentifier(node) && node.name === 'getQueryCache'
|
|
12
|
+
|
|
13
|
+
const isValidInitializer = (node) =>
|
|
14
|
+
utils.isCallExpression(node) && utils.isMemberExpression(node.callee)
|
|
15
|
+
|
|
16
|
+
if (isValidInitializer(initializer)) {
|
|
17
|
+
const instance = initializer.callee.object
|
|
18
|
+
|
|
19
|
+
return (
|
|
20
|
+
isGetQueryCacheIdentifier(initializer.callee.property) &&
|
|
21
|
+
(isKnownQueryClient(instance) ||
|
|
22
|
+
utils.isFunctionCallOf(
|
|
23
|
+
instance,
|
|
24
|
+
utils.getSelectorByImports(importIdentifiers, 'useQueryClient'),
|
|
25
|
+
))
|
|
26
|
+
)
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
return false
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
const findQueryCacheInstantiations = (
|
|
33
|
+
importIdentifiers,
|
|
34
|
+
knownQueryClientIds,
|
|
35
|
+
) =>
|
|
36
|
+
root.find(jscodeshift.VariableDeclarator, {}).filter((node) => {
|
|
37
|
+
if (node.value.init) {
|
|
38
|
+
const initializer = node.value.init
|
|
39
|
+
|
|
40
|
+
return (
|
|
41
|
+
utils.isClassInstantiationOf(
|
|
42
|
+
initializer,
|
|
43
|
+
utils.getSelectorByImports(importIdentifiers, 'QueryCache'),
|
|
44
|
+
) ||
|
|
45
|
+
isGetQueryCacheMethodCall(
|
|
46
|
+
initializer,
|
|
47
|
+
importIdentifiers,
|
|
48
|
+
knownQueryClientIds,
|
|
49
|
+
)
|
|
50
|
+
)
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
return false
|
|
54
|
+
})
|
|
55
|
+
|
|
56
|
+
const filterQueryCacheMethodCalls = (node) =>
|
|
57
|
+
utils.isIdentifier(node) && ['find', 'findAll'].includes(node.name)
|
|
58
|
+
|
|
59
|
+
const findQueryCacheMethodCalls = (importIdentifiers) => {
|
|
60
|
+
/**
|
|
61
|
+
* Here we collect all query client instantiations. We have to make aware of them because the query cache can be
|
|
62
|
+
* accessed by the query client as well.
|
|
63
|
+
*/
|
|
64
|
+
const queryClientIdentifiers =
|
|
65
|
+
utils.queryClient.findQueryClientIdentifiers(importIdentifiers)
|
|
66
|
+
/**
|
|
67
|
+
* Here we collect all query cache instantiations. The reason is simple: the methods can be called on query cache
|
|
68
|
+
* instances, to locate the possible usages we need to be aware of the identifier names.
|
|
69
|
+
*/
|
|
70
|
+
const queryCacheIdentifiers = findQueryCacheInstantiations(
|
|
71
|
+
importIdentifiers,
|
|
72
|
+
queryClientIdentifiers,
|
|
73
|
+
)
|
|
74
|
+
.paths()
|
|
75
|
+
.map((node) => node.value.id.name)
|
|
76
|
+
|
|
77
|
+
return (
|
|
78
|
+
utils
|
|
79
|
+
// First, we need to find all method calls.
|
|
80
|
+
.findAllMethodCalls()
|
|
81
|
+
// Then we narrow the collection to all `fetch` and `fetchAll` methods.
|
|
82
|
+
.filter((node) =>
|
|
83
|
+
filterQueryCacheMethodCalls(node.value.callee.property),
|
|
84
|
+
)
|
|
85
|
+
.filter((node) => {
|
|
86
|
+
const object = node.value.callee.object
|
|
87
|
+
|
|
88
|
+
// If the method is called on a `QueryCache` instance, we keep it in the collection.
|
|
89
|
+
if (utils.isIdentifier(object)) {
|
|
90
|
+
return queryCacheIdentifiers.includes(object.name)
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
// If the method is called on a `QueryClient` instance, we keep it in the collection.
|
|
94
|
+
if (utils.isCallExpression(object)) {
|
|
95
|
+
return isGetQueryCacheMethodCall(
|
|
96
|
+
object,
|
|
97
|
+
importIdentifiers,
|
|
98
|
+
queryClientIdentifiers,
|
|
99
|
+
)
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
return false
|
|
103
|
+
})
|
|
104
|
+
)
|
|
105
|
+
}
|
|
106
|
+
|
|
107
|
+
const execute = (replacer) => {
|
|
108
|
+
findQueryCacheMethodCalls(
|
|
109
|
+
utils.locateImports(['QueryCache', 'QueryClient', 'useQueryClient']),
|
|
110
|
+
).replaceWith(replacer)
|
|
111
|
+
}
|
|
112
|
+
|
|
113
|
+
return {
|
|
114
|
+
execute,
|
|
115
|
+
}
|
|
116
|
+
}
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
module.exports = ({ jscodeshift, utils, root }) => {
|
|
2
|
+
const filterQueryClientMethodCalls = (node, methods) =>
|
|
3
|
+
utils.isIdentifier(node) && methods.includes(node.name)
|
|
4
|
+
|
|
5
|
+
const findQueryClientMethodCalls = (importIdentifiers, methods) => {
|
|
6
|
+
/**
|
|
7
|
+
* Here we collect all query client instantiations. We have to make aware of them because some method calls might
|
|
8
|
+
* be invoked on these instances.
|
|
9
|
+
*/
|
|
10
|
+
const queryClientIdentifiers =
|
|
11
|
+
utils.queryClient.findQueryClientIdentifiers(importIdentifiers)
|
|
12
|
+
|
|
13
|
+
return (
|
|
14
|
+
utils
|
|
15
|
+
// First, we need to find all method calls.
|
|
16
|
+
.findAllMethodCalls()
|
|
17
|
+
// Then we narrow the collection to `QueryClient` methods.
|
|
18
|
+
.filter((node) =>
|
|
19
|
+
filterQueryClientMethodCalls(node.value.callee.property, methods),
|
|
20
|
+
)
|
|
21
|
+
.filter((node) => {
|
|
22
|
+
const object = node.value.callee.object
|
|
23
|
+
|
|
24
|
+
// If the method is called on a `QueryClient` instance, we keep it in the collection.
|
|
25
|
+
if (utils.isIdentifier(object)) {
|
|
26
|
+
return queryClientIdentifiers.includes(object.name)
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
// If the method is called on the return value of `useQueryClient` hook, we keep it in the collection.
|
|
30
|
+
return utils.isFunctionCallOf(
|
|
31
|
+
object,
|
|
32
|
+
utils.getSelectorByImports(importIdentifiers, 'useQueryClient'),
|
|
33
|
+
)
|
|
34
|
+
})
|
|
35
|
+
)
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
const execute = (methods, replacer) => {
|
|
39
|
+
findQueryClientMethodCalls(
|
|
40
|
+
utils.locateImports(['QueryClient', 'useQueryClient']),
|
|
41
|
+
methods,
|
|
42
|
+
).replaceWith(replacer)
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
return {
|
|
46
|
+
execute,
|
|
47
|
+
}
|
|
48
|
+
}
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
module.exports = ({ jscodeshift, utils, root }) => {
|
|
2
|
+
const filterUseQueryLikeHookCalls = (node, importIdentifiers, hooks) => {
|
|
3
|
+
for (const hook of hooks) {
|
|
4
|
+
const selector = utils.getSelectorByImports(importIdentifiers, hook)
|
|
5
|
+
|
|
6
|
+
if (utils.isFunctionCallOf(node, selector)) {
|
|
7
|
+
return true
|
|
8
|
+
}
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
return false
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
const findUseQueryLikeHookCalls = (importIdentifiers, hooks) =>
|
|
15
|
+
root
|
|
16
|
+
// First, we need to find all call expressions.
|
|
17
|
+
.find(jscodeshift.CallExpression, {})
|
|
18
|
+
// Then we narrow the collection to the `useQuery` like hook calls.
|
|
19
|
+
.filter((node) =>
|
|
20
|
+
filterUseQueryLikeHookCalls(node.value, importIdentifiers, hooks),
|
|
21
|
+
)
|
|
22
|
+
|
|
23
|
+
const execute = (hooks, replacer) => {
|
|
24
|
+
findUseQueryLikeHookCalls(utils.locateImports(hooks), hooks).replaceWith(
|
|
25
|
+
replacer,
|
|
26
|
+
)
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
return {
|
|
30
|
+
execute,
|
|
31
|
+
}
|
|
32
|
+
}
|
|
@@ -0,0 +1,94 @@
|
|
|
1
|
+
import * as React from 'react'
|
|
2
|
+
import {
|
|
3
|
+
QueryCache,
|
|
4
|
+
QueryClient,
|
|
5
|
+
useInfiniteQuery,
|
|
6
|
+
useIsFetching,
|
|
7
|
+
useIsMutating,
|
|
8
|
+
useMutation,
|
|
9
|
+
useQueries,
|
|
10
|
+
useQuery,
|
|
11
|
+
useQueryClient,
|
|
12
|
+
} from 'react-query'
|
|
13
|
+
|
|
14
|
+
export const Examples = () => {
|
|
15
|
+
useQuery('todos')
|
|
16
|
+
useInfiniteQuery('todos')
|
|
17
|
+
useMutation('todos')
|
|
18
|
+
useIsFetching('todos')
|
|
19
|
+
useIsMutating('todos')
|
|
20
|
+
useQueries([query1, query2])
|
|
21
|
+
// QueryClient methods
|
|
22
|
+
// --- Instantiated hook call.
|
|
23
|
+
const queryClient = useQueryClient()
|
|
24
|
+
queryClient.getMutationDefaults('todos')
|
|
25
|
+
queryClient.getQueriesData('todos')
|
|
26
|
+
queryClient.getQueryData('todos')
|
|
27
|
+
queryClient.getQueryDefaults('todos')
|
|
28
|
+
queryClient.getQueryState('todos')
|
|
29
|
+
queryClient.isFetching('todos')
|
|
30
|
+
queryClient.setMutationDefaults('todos', { mutationFn: async () => null })
|
|
31
|
+
queryClient.setQueriesData('todos', () => null)
|
|
32
|
+
queryClient.setQueryData('todos', () => null)
|
|
33
|
+
queryClient.setQueryDefaults('todos', { queryFn: async () => null })
|
|
34
|
+
queryClient.cancelQueries('todos')
|
|
35
|
+
queryClient.fetchInfiniteQuery('todos')
|
|
36
|
+
queryClient.fetchQuery('todos')
|
|
37
|
+
queryClient.invalidateQueries('todos')
|
|
38
|
+
queryClient.prefetchInfiniteQuery('todos')
|
|
39
|
+
queryClient.prefetchQuery('todos')
|
|
40
|
+
queryClient.refetchQueries('todos')
|
|
41
|
+
queryClient.removeQueries('todos')
|
|
42
|
+
queryClient.resetQueries('todos')
|
|
43
|
+
// --- Direct hook call.
|
|
44
|
+
useQueryClient().getMutationDefaults('todos')
|
|
45
|
+
useQueryClient().getQueriesData('todos')
|
|
46
|
+
useQueryClient().getQueryData('todos')
|
|
47
|
+
useQueryClient().getQueryDefaults('todos')
|
|
48
|
+
useQueryClient().getQueryState('todos')
|
|
49
|
+
useQueryClient().isFetching('todos')
|
|
50
|
+
useQueryClient().setMutationDefaults('todos', {
|
|
51
|
+
mutationFn: async () => null,
|
|
52
|
+
})
|
|
53
|
+
useQueryClient().setQueriesData('todos', () => null)
|
|
54
|
+
useQueryClient().setQueryData('todos', () => null)
|
|
55
|
+
useQueryClient().setQueryDefaults('todos', { queryFn: async () => null })
|
|
56
|
+
useQueryClient().cancelQueries('todos')
|
|
57
|
+
useQueryClient().fetchInfiniteQuery('todos')
|
|
58
|
+
useQueryClient().fetchQuery('todos')
|
|
59
|
+
useQueryClient().invalidateQueries('todos')
|
|
60
|
+
useQueryClient().prefetchInfiniteQuery('todos')
|
|
61
|
+
useQueryClient().prefetchQuery('todos')
|
|
62
|
+
useQueryClient().refetchQueries('todos')
|
|
63
|
+
useQueryClient().removeQueries('todos')
|
|
64
|
+
useQueryClient().resetQueries('todos')
|
|
65
|
+
// QueryCache
|
|
66
|
+
// --- NewExpression
|
|
67
|
+
const queryCache1 = new QueryCache({
|
|
68
|
+
onError: (error) => console.log(error),
|
|
69
|
+
onSuccess: (success) => console.log(success)
|
|
70
|
+
})
|
|
71
|
+
queryCache1.find('todos')
|
|
72
|
+
queryCache1.findAll('todos')
|
|
73
|
+
// --- Instantiated hook call.
|
|
74
|
+
const queryClient1 = useQueryClient()
|
|
75
|
+
queryClient1.getQueryCache().find('todos')
|
|
76
|
+
queryClient1.getQueryCache().findAll('todos')
|
|
77
|
+
//
|
|
78
|
+
const queryClient2 = new QueryClient({})
|
|
79
|
+
queryClient2.getQueryCache().find('todos')
|
|
80
|
+
queryClient2.getQueryCache().findAll('todos')
|
|
81
|
+
//
|
|
82
|
+
const queryCache2 = queryClient1.getQueryCache()
|
|
83
|
+
queryCache2.find('todos')
|
|
84
|
+
queryCache2.findAll('todos')
|
|
85
|
+
// --- Direct hook call.
|
|
86
|
+
useQueryClient().getQueryCache().find('todos')
|
|
87
|
+
useQueryClient().getQueryCache().findAll('todos')
|
|
88
|
+
//
|
|
89
|
+
const queryCache3 = useQueryClient().getQueryCache()
|
|
90
|
+
queryCache3.find('todos')
|
|
91
|
+
queryCache3.findAll('todos')
|
|
92
|
+
|
|
93
|
+
return <div>Example Component</div>
|
|
94
|
+
}
|
|
@@ -0,0 +1,96 @@
|
|
|
1
|
+
import * as React from 'react'
|
|
2
|
+
import {
|
|
3
|
+
QueryCache,
|
|
4
|
+
QueryClient,
|
|
5
|
+
useInfiniteQuery,
|
|
6
|
+
useIsFetching,
|
|
7
|
+
useIsMutating,
|
|
8
|
+
useMutation,
|
|
9
|
+
useQueries,
|
|
10
|
+
useQuery,
|
|
11
|
+
useQueryClient,
|
|
12
|
+
} from 'react-query'
|
|
13
|
+
|
|
14
|
+
export const Examples = () => {
|
|
15
|
+
useQuery(['todos'])
|
|
16
|
+
useInfiniteQuery(['todos'])
|
|
17
|
+
useMutation(['todos'])
|
|
18
|
+
useIsFetching(['todos'])
|
|
19
|
+
useIsMutating(['todos'])
|
|
20
|
+
useQueries({
|
|
21
|
+
queries: [query1, query2]
|
|
22
|
+
})
|
|
23
|
+
// QueryClient methods
|
|
24
|
+
// --- Instantiated hook call.
|
|
25
|
+
const queryClient = useQueryClient()
|
|
26
|
+
queryClient.getMutationDefaults(['todos'])
|
|
27
|
+
queryClient.getQueriesData(['todos'])
|
|
28
|
+
queryClient.getQueryData(['todos'])
|
|
29
|
+
queryClient.getQueryDefaults(['todos'])
|
|
30
|
+
queryClient.getQueryState(['todos'])
|
|
31
|
+
queryClient.isFetching(['todos'])
|
|
32
|
+
queryClient.setMutationDefaults(['todos'], { mutationFn: async () => null })
|
|
33
|
+
queryClient.setQueriesData(['todos'], () => null)
|
|
34
|
+
queryClient.setQueryData(['todos'], () => null)
|
|
35
|
+
queryClient.setQueryDefaults(['todos'], { queryFn: async () => null })
|
|
36
|
+
queryClient.cancelQueries(['todos'])
|
|
37
|
+
queryClient.fetchInfiniteQuery(['todos'])
|
|
38
|
+
queryClient.fetchQuery(['todos'])
|
|
39
|
+
queryClient.invalidateQueries(['todos'])
|
|
40
|
+
queryClient.prefetchInfiniteQuery(['todos'])
|
|
41
|
+
queryClient.prefetchQuery(['todos'])
|
|
42
|
+
queryClient.refetchQueries(['todos'])
|
|
43
|
+
queryClient.removeQueries(['todos'])
|
|
44
|
+
queryClient.resetQueries(['todos'])
|
|
45
|
+
// --- Direct hook call.
|
|
46
|
+
useQueryClient().getMutationDefaults(['todos'])
|
|
47
|
+
useQueryClient().getQueriesData(['todos'])
|
|
48
|
+
useQueryClient().getQueryData(['todos'])
|
|
49
|
+
useQueryClient().getQueryDefaults(['todos'])
|
|
50
|
+
useQueryClient().getQueryState(['todos'])
|
|
51
|
+
useQueryClient().isFetching(['todos'])
|
|
52
|
+
useQueryClient().setMutationDefaults(['todos'], {
|
|
53
|
+
mutationFn: async () => null,
|
|
54
|
+
})
|
|
55
|
+
useQueryClient().setQueriesData(['todos'], () => null)
|
|
56
|
+
useQueryClient().setQueryData(['todos'], () => null)
|
|
57
|
+
useQueryClient().setQueryDefaults(['todos'], { queryFn: async () => null })
|
|
58
|
+
useQueryClient().cancelQueries(['todos'])
|
|
59
|
+
useQueryClient().fetchInfiniteQuery(['todos'])
|
|
60
|
+
useQueryClient().fetchQuery(['todos'])
|
|
61
|
+
useQueryClient().invalidateQueries(['todos'])
|
|
62
|
+
useQueryClient().prefetchInfiniteQuery(['todos'])
|
|
63
|
+
useQueryClient().prefetchQuery(['todos'])
|
|
64
|
+
useQueryClient().refetchQueries(['todos'])
|
|
65
|
+
useQueryClient().removeQueries(['todos'])
|
|
66
|
+
useQueryClient().resetQueries(['todos'])
|
|
67
|
+
// QueryCache
|
|
68
|
+
// --- NewExpression
|
|
69
|
+
const queryCache1 = new QueryCache({
|
|
70
|
+
onError: (error) => console.log(error),
|
|
71
|
+
onSuccess: (success) => console.log(success)
|
|
72
|
+
})
|
|
73
|
+
queryCache1.find(['todos'])
|
|
74
|
+
queryCache1.findAll(['todos'])
|
|
75
|
+
// --- Instantiated hook call.
|
|
76
|
+
const queryClient1 = useQueryClient()
|
|
77
|
+
queryClient1.getQueryCache().find(['todos'])
|
|
78
|
+
queryClient1.getQueryCache().findAll(['todos'])
|
|
79
|
+
//
|
|
80
|
+
const queryClient2 = new QueryClient({})
|
|
81
|
+
queryClient2.getQueryCache().find(['todos'])
|
|
82
|
+
queryClient2.getQueryCache().findAll(['todos'])
|
|
83
|
+
//
|
|
84
|
+
const queryCache2 = queryClient1.getQueryCache()
|
|
85
|
+
queryCache2.find(['todos'])
|
|
86
|
+
queryCache2.findAll(['todos'])
|
|
87
|
+
// --- Direct hook call.
|
|
88
|
+
useQueryClient().getQueryCache().find(['todos'])
|
|
89
|
+
useQueryClient().getQueryCache().findAll(['todos'])
|
|
90
|
+
//
|
|
91
|
+
const queryCache3 = useQueryClient().getQueryCache()
|
|
92
|
+
queryCache3.find(['todos'])
|
|
93
|
+
queryCache3.findAll(['todos'])
|
|
94
|
+
|
|
95
|
+
return <div>Example Component</div>
|
|
96
|
+
}
|
|
@@ -0,0 +1,96 @@
|
|
|
1
|
+
import * as React from 'react'
|
|
2
|
+
import {
|
|
3
|
+
QueryCache as RenamedQueryCache,
|
|
4
|
+
QueryClient as RenamedQueryClient,
|
|
5
|
+
useInfiniteQuery as useRenamedInfiniteQuery,
|
|
6
|
+
useIsFetching as useRenamedIsFetching,
|
|
7
|
+
useIsMutating as useRenamedIsMutating,
|
|
8
|
+
useMutation as useRenamedMutation,
|
|
9
|
+
useQueries as useRenamedQueries,
|
|
10
|
+
useQuery as useRenamedQuery,
|
|
11
|
+
useQueryClient as useRenamedQueryClient,
|
|
12
|
+
} from 'react-query'
|
|
13
|
+
|
|
14
|
+
export const Examples = () => {
|
|
15
|
+
useRenamedQuery('todos')
|
|
16
|
+
useRenamedInfiniteQuery('todos')
|
|
17
|
+
useRenamedMutation('todos')
|
|
18
|
+
useRenamedIsFetching('todos')
|
|
19
|
+
useRenamedIsMutating('todos')
|
|
20
|
+
useRenamedQueries([query1, query2])
|
|
21
|
+
// QueryClient methods
|
|
22
|
+
// --- Instantiated hook call.
|
|
23
|
+
const queryClient = useRenamedQueryClient()
|
|
24
|
+
queryClient.getMutationDefaults('todos')
|
|
25
|
+
queryClient.getQueriesData('todos')
|
|
26
|
+
queryClient.getQueryData('todos')
|
|
27
|
+
queryClient.getQueryDefaults('todos')
|
|
28
|
+
queryClient.getQueryState('todos')
|
|
29
|
+
queryClient.isFetching('todos')
|
|
30
|
+
queryClient.setMutationDefaults('todos', { mutationFn: async () => null })
|
|
31
|
+
queryClient.setQueriesData('todos', () => null)
|
|
32
|
+
queryClient.setQueryData('todos', () => null)
|
|
33
|
+
queryClient.setQueryDefaults('todos', { queryFn: async () => null })
|
|
34
|
+
queryClient.cancelQueries('todos')
|
|
35
|
+
queryClient.fetchInfiniteQuery('todos')
|
|
36
|
+
queryClient.fetchQuery('todos')
|
|
37
|
+
queryClient.invalidateQueries('todos')
|
|
38
|
+
queryClient.prefetchInfiniteQuery('todos')
|
|
39
|
+
queryClient.prefetchQuery('todos')
|
|
40
|
+
queryClient.refetchQueries('todos')
|
|
41
|
+
queryClient.removeQueries('todos')
|
|
42
|
+
queryClient.resetQueries('todos')
|
|
43
|
+
// --- Direct hook call.
|
|
44
|
+
useRenamedQueryClient().getMutationDefaults('todos')
|
|
45
|
+
useRenamedQueryClient().getQueriesData('todos')
|
|
46
|
+
useRenamedQueryClient().getQueryData('todos')
|
|
47
|
+
useRenamedQueryClient().getQueryDefaults('todos')
|
|
48
|
+
useRenamedQueryClient().getQueryState('todos')
|
|
49
|
+
useRenamedQueryClient().isFetching('todos')
|
|
50
|
+
useRenamedQueryClient().setMutationDefaults('todos', {
|
|
51
|
+
mutationFn: async () => null,
|
|
52
|
+
})
|
|
53
|
+
useRenamedQueryClient().setQueriesData('todos', () => null)
|
|
54
|
+
useRenamedQueryClient().setQueryData('todos', () => null)
|
|
55
|
+
useRenamedQueryClient().setQueryDefaults('todos', {
|
|
56
|
+
queryFn: async () => null,
|
|
57
|
+
})
|
|
58
|
+
useRenamedQueryClient().cancelQueries('todos')
|
|
59
|
+
useRenamedQueryClient().fetchInfiniteQuery('todos')
|
|
60
|
+
useRenamedQueryClient().fetchQuery('todos')
|
|
61
|
+
useRenamedQueryClient().invalidateQueries('todos')
|
|
62
|
+
useRenamedQueryClient().prefetchInfiniteQuery('todos')
|
|
63
|
+
useRenamedQueryClient().prefetchQuery('todos')
|
|
64
|
+
useRenamedQueryClient().refetchQueries('todos')
|
|
65
|
+
useRenamedQueryClient().removeQueries('todos')
|
|
66
|
+
useRenamedQueryClient().resetQueries('todos')
|
|
67
|
+
// QueryCache
|
|
68
|
+
// --- NewExpression
|
|
69
|
+
const queryCache1 = new RenamedQueryCache({
|
|
70
|
+
onError: (error) => console.log(error),
|
|
71
|
+
onSuccess: (success) => console.log(success)
|
|
72
|
+
})
|
|
73
|
+
queryCache1.find('todos')
|
|
74
|
+
queryCache1.findAll('todos')
|
|
75
|
+
// --- Instantiated hook call.
|
|
76
|
+
const queryClient1 = useRenamedQueryClient()
|
|
77
|
+
queryClient1.getQueryCache().find('todos')
|
|
78
|
+
queryClient1.getQueryCache().findAll('todos')
|
|
79
|
+
//
|
|
80
|
+
const queryClient2 = new RenamedQueryClient({})
|
|
81
|
+
queryClient2.getQueryCache().find('todos')
|
|
82
|
+
queryClient2.getQueryCache().findAll('todos')
|
|
83
|
+
//
|
|
84
|
+
const queryCache2 = queryClient1.getQueryCache()
|
|
85
|
+
queryCache2.find('todos')
|
|
86
|
+
queryCache2.findAll('todos')
|
|
87
|
+
// --- Direct hook call.
|
|
88
|
+
useRenamedQueryClient().getQueryCache().find('todos')
|
|
89
|
+
useRenamedQueryClient().getQueryCache().findAll('todos')
|
|
90
|
+
//
|
|
91
|
+
const queryCache3 = useRenamedQueryClient().getQueryCache()
|
|
92
|
+
queryCache3.find('todos')
|
|
93
|
+
queryCache3.findAll('todos')
|
|
94
|
+
|
|
95
|
+
return <div>Example Component</div>
|
|
96
|
+
}
|