Skip to content
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

Version 4 codemods #3195

Merged
merged 61 commits into from
Feb 18, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
61 commits
Select commit Hold shift + click to select a range
3a5b414
chore: add `jscodeshift` library to dev-dependencies
balazsmatepetro Nov 19, 2021
5e74106
chore: add `@types/jscodeshift` library to dev-dependencies
balazsmatepetro Jan 13, 2022
439e0bd
chore: add an empty `jest` config file under the `codemods` directory
balazsmatepetro Nov 19, 2021
454a38b
chore: add a very basic codemod implementation and tests
balazsmatepetro Nov 19, 2021
1f383ff
chore: fix `prettier` errors in `use_query` codemod
balazsmatepetro Nov 23, 2021
c2b9e9f
chore: add missing `export` keywords to test suites in case of `use_q…
balazsmatepetro Nov 23, 2021
ff8fcf0
feat(codemod): add basic codemods for query client methods
balazsmatepetro Jan 10, 2022
c09256a
feat(codemod): add basic `useQueries` codemods
balazsmatepetro Jan 11, 2022
9482de1
refactor(codemod): rework `useQuery` related codemods
balazsmatepetro Jan 13, 2022
2dfc3d8
feat(codemod): move files under `v4` directory
balazsmatepetro Jan 14, 2022
980f30f
chore(codemod): move `jscodeshift` library from `dependencies` to `de…
balazsmatepetro Jan 17, 2022
80adc1b
chore(codemod): pick up codemods test by `npm test`
balazsmatepetro Jan 17, 2022
32d2672
refactor(codemod): remove `without-parameter` test case in case of `q…
balazsmatepetro Jan 17, 2022
ca60534
chore(codemod): remove duplications from `queryClient` codemod testfi…
balazsmatepetro Jan 17, 2022
fd7ab8c
chore(codemod): rename `first-parameter-is-identifier` and `object-ex…
balazsmatepetro Jan 17, 2022
e26cb47
chore(codemod): rework `first-parameter-is-identifier` and `object-ex…
balazsmatepetro Jan 18, 2022
d7e0fc6
chore(codemod): remove duplications from `useQuery` codemod testfixtures
balazsmatepetro Jan 18, 2022
dfb9942
chore(codemod): add missing methods to the object syntax aware query …
balazsmatepetro Jan 18, 2022
4d1fd50
chore(codemod): add some more test cases to the `parameter-is-object`…
balazsmatepetro Jan 18, 2022
7d787c6
feat(codemod): add basic `useMutation` codemods
balazsmatepetro Jan 18, 2022
9ae1a68
refactor(codemod): rename `queryKey` replacer and error, because now …
balazsmatepetro Jan 18, 2022
702c792
feat(codemod): add support for template literals
balazsmatepetro Jan 18, 2022
34ca27b
refactor(codemod): rename `object-syntax-aware` test to `query-client…
balazsmatepetro Jan 18, 2022
8b1287b
refactor(codemod): move testfixtures to the root level of `__testfixt…
balazsmatepetro Jan 18, 2022
546b4fe
refactor(codemod): combine the two `queryClient` codemods and test su…
balazsmatepetro Jan 18, 2022
f38f79b
refactor(codemod): move `useMutation` related parts and testfixutes t…
balazsmatepetro Jan 18, 2022
f47359c
refactor(codemod): remove the whole `use_mutation` library
balazsmatepetro Jan 18, 2022
e01efc8
feat(codemod): add support for the following hook calls:
balazsmatepetro Jan 18, 2022
6fe4245
refactor(codemod): move `useQueries` related parts and testfixutes to…
balazsmatepetro Jan 18, 2022
a2ee669
refactor(codemod): remove the whole `use_queries` library
balazsmatepetro Jan 18, 2022
55bf53b
refactor(codemod): introduce `transformUseQueryLikeUsages` function
balazsmatepetro Jan 18, 2022
ada4dd0
refactor(codemod): do some refinements on the following tests:
balazsmatepetro Jan 18, 2022
cc5ffc5
fix(codemod): in the case of JS, the string literal might be interpre…
balazsmatepetro Jan 18, 2022
6e743df
fix(codemod): remove `type` filter from import declarations
balazsmatepetro Jan 18, 2022
768e044
refactor(codemod): move `QueryClient` related parts and testfixutes t…
balazsmatepetro Jan 19, 2022
9cb414c
refactor(codemod): remove the whole `query_client_methods` library
balazsmatepetro Jan 19, 2022
b1e1e87
refactor(codemod): simplify entry point of the codemod
balazsmatepetro Jan 19, 2022
3154592
feat(codemod): add basic `QueryCache` codemods
balazsmatepetro Jan 20, 2022
bb6ffca
fix(codemod): do not transform array expression query keys
balazsmatepetro Jan 27, 2022
076e1b4
fix(examples/playground): fix invalid usage of `invalidateQueries`
balazsmatepetro Jan 27, 2022
5f96b89
feat(codemod): show file path in console warnings
balazsmatepetro Jan 27, 2022
1fcb2f7
refactor(codemod): remove `use_query` directory
balazsmatepetro Jan 27, 2022
955e92a
refactor(codemod): rename `use-query` to `key-transformation`
balazsmatepetro Jan 27, 2022
029d2da
refactor(codemod): replace the transformer name in `key-transformatio…
balazsmatepetro Jan 27, 2022
227b684
chore(codemod): add codemod and utilities to the bundle
balazsmatepetro Jan 27, 2022
aca109d
refactor(codemod): rename function
balazsmatepetro Jan 27, 2022
069ff29
fix(codemod): keep `typeArguments` of the node
balazsmatepetro Jan 27, 2022
2f870eb
Merge remote-tracking branch 'upstream/alpha' into version-4-codemods
balazsmatepetro Jan 27, 2022
0b9c8fe
refactor(codemod): move `query-cache` test cases to `default-import`
balazsmatepetro Jan 27, 2022
12c3beb
feat(codemod): add support for named imports in case of `QueryCache` …
balazsmatepetro Feb 1, 2022
1afc35a
fix(codemod): always return `Identifier` instance in case of `findImp…
balazsmatepetro Feb 3, 2022
912f325
feat(codemod): add support for namespaced imports in case of `QueryCa…
balazsmatepetro Feb 3, 2022
04d0e2a
refactor(codemod): re-use the previously written utility functions in…
balazsmatepetro Feb 3, 2022
72795a5
refactor(codemod): re-use the previously written utility functions in…
balazsmatepetro Feb 3, 2022
0a1a0a5
refactor(codemod): rename `hook-call-transformer` to `use-query-like`…
balazsmatepetro Feb 3, 2022
9fc5725
chore(codemod): add todo about the `react-query` import check
balazsmatepetro Feb 3, 2022
1988134
refactor(codemod): make the `use-query-like-transformer` to look the …
balazsmatepetro Feb 3, 2022
c5192a4
fix(codemod): do not log warnings in the test environment
balazsmatepetro Feb 17, 2022
a672f64
docs(codemod): add instructions how to apply codemods
balazsmatepetro Feb 17, 2022
787f7d9
chore(examples): apply codemod on the `examples` directory
balazsmatepetro Feb 17, 2022
cc14525
docs(codemod): update `Codemod` section
balazsmatepetro Feb 17, 2022
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions codemods/jest.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
module.exports = {
testMatch: ['<rootDir>/**/*.test.js'],
}
94 changes: 94 additions & 0 deletions codemods/v4/__testfixtures__/default-import.input.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,94 @@
import * as React from 'react'
import {
QueryCache,
QueryClient,
useInfiniteQuery,
useIsFetching,
useIsMutating,
useMutation,
useQueries,
useQuery,
useQueryClient,
} from 'react-query'

export const Examples = () => {
useQuery('todos')
useInfiniteQuery('todos')
useMutation('todos')
useIsFetching('todos')
useIsMutating('todos')
useQueries([query1, query2])
// QueryClient methods
// --- Instantiated hook call.
const queryClient = useQueryClient()
queryClient.getMutationDefaults('todos')
queryClient.getQueriesData('todos')
queryClient.getQueryData('todos')
queryClient.getQueryDefaults('todos')
queryClient.getQueryState('todos')
queryClient.isFetching('todos')
queryClient.setMutationDefaults('todos', { mutationFn: async () => null })
queryClient.setQueriesData('todos', () => null)
queryClient.setQueryData('todos', () => null)
queryClient.setQueryDefaults('todos', { queryFn: async () => null })
queryClient.cancelQueries('todos')
queryClient.fetchInfiniteQuery('todos')
queryClient.fetchQuery('todos')
queryClient.invalidateQueries('todos')
queryClient.prefetchInfiniteQuery('todos')
queryClient.prefetchQuery('todos')
queryClient.refetchQueries('todos')
queryClient.removeQueries('todos')
queryClient.resetQueries('todos')
// --- Direct hook call.
useQueryClient().getMutationDefaults('todos')
useQueryClient().getQueriesData('todos')
useQueryClient().getQueryData('todos')
useQueryClient().getQueryDefaults('todos')
useQueryClient().getQueryState('todos')
useQueryClient().isFetching('todos')
useQueryClient().setMutationDefaults('todos', {
mutationFn: async () => null,
})
useQueryClient().setQueriesData('todos', () => null)
useQueryClient().setQueryData('todos', () => null)
useQueryClient().setQueryDefaults('todos', { queryFn: async () => null })
useQueryClient().cancelQueries('todos')
useQueryClient().fetchInfiniteQuery('todos')
useQueryClient().fetchQuery('todos')
useQueryClient().invalidateQueries('todos')
useQueryClient().prefetchInfiniteQuery('todos')
useQueryClient().prefetchQuery('todos')
useQueryClient().refetchQueries('todos')
useQueryClient().removeQueries('todos')
useQueryClient().resetQueries('todos')
// QueryCache
// --- NewExpression
const queryCache1 = new QueryCache({
onError: (error) => console.log(error),
onSuccess: (success) => console.log(success)
})
queryCache1.find('todos')
queryCache1.findAll('todos')
// --- Instantiated hook call.
const queryClient1 = useQueryClient()
queryClient1.getQueryCache().find('todos')
queryClient1.getQueryCache().findAll('todos')
//
const queryClient2 = new QueryClient({})
queryClient2.getQueryCache().find('todos')
queryClient2.getQueryCache().findAll('todos')
//
const queryCache2 = queryClient1.getQueryCache()
queryCache2.find('todos')
queryCache2.findAll('todos')
// --- Direct hook call.
useQueryClient().getQueryCache().find('todos')
useQueryClient().getQueryCache().findAll('todos')
//
const queryCache3 = useQueryClient().getQueryCache()
queryCache3.find('todos')
queryCache3.findAll('todos')

return <div>Example Component</div>
}
96 changes: 96 additions & 0 deletions codemods/v4/__testfixtures__/default-import.output.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,96 @@
import * as React from 'react'
import {
QueryCache,
QueryClient,
useInfiniteQuery,
useIsFetching,
useIsMutating,
useMutation,
useQueries,
useQuery,
useQueryClient,
} from 'react-query'

export const Examples = () => {
useQuery(['todos'])
useInfiniteQuery(['todos'])
useMutation(['todos'])
useIsFetching(['todos'])
useIsMutating(['todos'])
useQueries({
queries: [query1, query2]
})
// QueryClient methods
// --- Instantiated hook call.
const queryClient = useQueryClient()
queryClient.getMutationDefaults(['todos'])
queryClient.getQueriesData(['todos'])
queryClient.getQueryData(['todos'])
queryClient.getQueryDefaults(['todos'])
queryClient.getQueryState(['todos'])
queryClient.isFetching(['todos'])
queryClient.setMutationDefaults(['todos'], { mutationFn: async () => null })
queryClient.setQueriesData(['todos'], () => null)
queryClient.setQueryData(['todos'], () => null)
queryClient.setQueryDefaults(['todos'], { queryFn: async () => null })
queryClient.cancelQueries(['todos'])
queryClient.fetchInfiniteQuery(['todos'])
queryClient.fetchQuery(['todos'])
queryClient.invalidateQueries(['todos'])
queryClient.prefetchInfiniteQuery(['todos'])
queryClient.prefetchQuery(['todos'])
queryClient.refetchQueries(['todos'])
queryClient.removeQueries(['todos'])
queryClient.resetQueries(['todos'])
// --- Direct hook call.
useQueryClient().getMutationDefaults(['todos'])
useQueryClient().getQueriesData(['todos'])
useQueryClient().getQueryData(['todos'])
useQueryClient().getQueryDefaults(['todos'])
useQueryClient().getQueryState(['todos'])
useQueryClient().isFetching(['todos'])
useQueryClient().setMutationDefaults(['todos'], {
mutationFn: async () => null,
})
useQueryClient().setQueriesData(['todos'], () => null)
useQueryClient().setQueryData(['todos'], () => null)
useQueryClient().setQueryDefaults(['todos'], { queryFn: async () => null })
useQueryClient().cancelQueries(['todos'])
useQueryClient().fetchInfiniteQuery(['todos'])
useQueryClient().fetchQuery(['todos'])
useQueryClient().invalidateQueries(['todos'])
useQueryClient().prefetchInfiniteQuery(['todos'])
useQueryClient().prefetchQuery(['todos'])
useQueryClient().refetchQueries(['todos'])
useQueryClient().removeQueries(['todos'])
useQueryClient().resetQueries(['todos'])
// QueryCache
// --- NewExpression
const queryCache1 = new QueryCache({
onError: (error) => console.log(error),
onSuccess: (success) => console.log(success)
})
queryCache1.find(['todos'])
queryCache1.findAll(['todos'])
// --- Instantiated hook call.
const queryClient1 = useQueryClient()
queryClient1.getQueryCache().find(['todos'])
queryClient1.getQueryCache().findAll(['todos'])
//
const queryClient2 = new QueryClient({})
queryClient2.getQueryCache().find(['todos'])
queryClient2.getQueryCache().findAll(['todos'])
//
const queryCache2 = queryClient1.getQueryCache()
queryCache2.find(['todos'])
queryCache2.findAll(['todos'])
// --- Direct hook call.
useQueryClient().getQueryCache().find(['todos'])
useQueryClient().getQueryCache().findAll(['todos'])
//
const queryCache3 = useQueryClient().getQueryCache()
queryCache3.find(['todos'])
queryCache3.findAll(['todos'])

return <div>Example Component</div>
}
96 changes: 96 additions & 0 deletions codemods/v4/__testfixtures__/named-import.input.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,96 @@
import * as React from 'react'
import {
QueryCache as RenamedQueryCache,
QueryClient as RenamedQueryClient,
useInfiniteQuery as useRenamedInfiniteQuery,
useIsFetching as useRenamedIsFetching,
useIsMutating as useRenamedIsMutating,
useMutation as useRenamedMutation,
useQueries as useRenamedQueries,
useQuery as useRenamedQuery,
useQueryClient as useRenamedQueryClient,
} from 'react-query'

export const Examples = () => {
useRenamedQuery('todos')
useRenamedInfiniteQuery('todos')
useRenamedMutation('todos')
useRenamedIsFetching('todos')
useRenamedIsMutating('todos')
useRenamedQueries([query1, query2])
// QueryClient methods
// --- Instantiated hook call.
const queryClient = useRenamedQueryClient()
queryClient.getMutationDefaults('todos')
queryClient.getQueriesData('todos')
queryClient.getQueryData('todos')
queryClient.getQueryDefaults('todos')
queryClient.getQueryState('todos')
queryClient.isFetching('todos')
queryClient.setMutationDefaults('todos', { mutationFn: async () => null })
queryClient.setQueriesData('todos', () => null)
queryClient.setQueryData('todos', () => null)
queryClient.setQueryDefaults('todos', { queryFn: async () => null })
queryClient.cancelQueries('todos')
queryClient.fetchInfiniteQuery('todos')
queryClient.fetchQuery('todos')
queryClient.invalidateQueries('todos')
queryClient.prefetchInfiniteQuery('todos')
queryClient.prefetchQuery('todos')
queryClient.refetchQueries('todos')
queryClient.removeQueries('todos')
queryClient.resetQueries('todos')
// --- Direct hook call.
useRenamedQueryClient().getMutationDefaults('todos')
useRenamedQueryClient().getQueriesData('todos')
useRenamedQueryClient().getQueryData('todos')
useRenamedQueryClient().getQueryDefaults('todos')
useRenamedQueryClient().getQueryState('todos')
useRenamedQueryClient().isFetching('todos')
useRenamedQueryClient().setMutationDefaults('todos', {
mutationFn: async () => null,
})
useRenamedQueryClient().setQueriesData('todos', () => null)
useRenamedQueryClient().setQueryData('todos', () => null)
useRenamedQueryClient().setQueryDefaults('todos', {
queryFn: async () => null,
})
useRenamedQueryClient().cancelQueries('todos')
useRenamedQueryClient().fetchInfiniteQuery('todos')
useRenamedQueryClient().fetchQuery('todos')
useRenamedQueryClient().invalidateQueries('todos')
useRenamedQueryClient().prefetchInfiniteQuery('todos')
useRenamedQueryClient().prefetchQuery('todos')
useRenamedQueryClient().refetchQueries('todos')
useRenamedQueryClient().removeQueries('todos')
useRenamedQueryClient().resetQueries('todos')
// QueryCache
// --- NewExpression
const queryCache1 = new RenamedQueryCache({
onError: (error) => console.log(error),
onSuccess: (success) => console.log(success)
})
queryCache1.find('todos')
queryCache1.findAll('todos')
// --- Instantiated hook call.
const queryClient1 = useRenamedQueryClient()
queryClient1.getQueryCache().find('todos')
queryClient1.getQueryCache().findAll('todos')
//
const queryClient2 = new RenamedQueryClient({})
queryClient2.getQueryCache().find('todos')
queryClient2.getQueryCache().findAll('todos')
//
const queryCache2 = queryClient1.getQueryCache()
queryCache2.find('todos')
queryCache2.findAll('todos')
// --- Direct hook call.
useRenamedQueryClient().getQueryCache().find('todos')
useRenamedQueryClient().getQueryCache().findAll('todos')
//
const queryCache3 = useRenamedQueryClient().getQueryCache()
queryCache3.find('todos')
queryCache3.findAll('todos')

return <div>Example Component</div>
}
98 changes: 98 additions & 0 deletions codemods/v4/__testfixtures__/named-import.output.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,98 @@
import * as React from 'react'
import {
QueryCache as RenamedQueryCache,
QueryClient as RenamedQueryClient,
useInfiniteQuery as useRenamedInfiniteQuery,
useIsFetching as useRenamedIsFetching,
useIsMutating as useRenamedIsMutating,
useMutation as useRenamedMutation,
useQueries as useRenamedQueries,
useQuery as useRenamedQuery,
useQueryClient as useRenamedQueryClient,
} from 'react-query'

export const Examples = () => {
useRenamedQuery(['todos'])
useRenamedInfiniteQuery(['todos'])
useRenamedMutation(['todos'])
useRenamedIsFetching(['todos'])
useRenamedIsMutating(['todos'])
useRenamedQueries({
queries: [query1, query2]
})
// QueryClient methods
// --- Instantiated hook call.
const queryClient = useRenamedQueryClient()
queryClient.getMutationDefaults(['todos'])
queryClient.getQueriesData(['todos'])
queryClient.getQueryData(['todos'])
queryClient.getQueryDefaults(['todos'])
queryClient.getQueryState(['todos'])
queryClient.isFetching(['todos'])
queryClient.setMutationDefaults(['todos'], { mutationFn: async () => null })
queryClient.setQueriesData(['todos'], () => null)
queryClient.setQueryData(['todos'], () => null)
queryClient.setQueryDefaults(['todos'], { queryFn: async () => null })
queryClient.cancelQueries(['todos'])
queryClient.fetchInfiniteQuery(['todos'])
queryClient.fetchQuery(['todos'])
queryClient.invalidateQueries(['todos'])
queryClient.prefetchInfiniteQuery(['todos'])
queryClient.prefetchQuery(['todos'])
queryClient.refetchQueries(['todos'])
queryClient.removeQueries(['todos'])
queryClient.resetQueries(['todos'])
// --- Direct hook call.
useRenamedQueryClient().getMutationDefaults(['todos'])
useRenamedQueryClient().getQueriesData(['todos'])
useRenamedQueryClient().getQueryData(['todos'])
useRenamedQueryClient().getQueryDefaults(['todos'])
useRenamedQueryClient().getQueryState(['todos'])
useRenamedQueryClient().isFetching(['todos'])
useRenamedQueryClient().setMutationDefaults(['todos'], {
mutationFn: async () => null,
})
useRenamedQueryClient().setQueriesData(['todos'], () => null)
useRenamedQueryClient().setQueryData(['todos'], () => null)
useRenamedQueryClient().setQueryDefaults(['todos'], {
queryFn: async () => null,
})
useRenamedQueryClient().cancelQueries(['todos'])
useRenamedQueryClient().fetchInfiniteQuery(['todos'])
useRenamedQueryClient().fetchQuery(['todos'])
useRenamedQueryClient().invalidateQueries(['todos'])
useRenamedQueryClient().prefetchInfiniteQuery(['todos'])
useRenamedQueryClient().prefetchQuery(['todos'])
useRenamedQueryClient().refetchQueries(['todos'])
useRenamedQueryClient().removeQueries(['todos'])
useRenamedQueryClient().resetQueries(['todos'])
// QueryCache
// --- NewExpression
const queryCache1 = new RenamedQueryCache({
onError: (error) => console.log(error),
onSuccess: (success) => console.log(success)
})
queryCache1.find(['todos'])
queryCache1.findAll(['todos'])
// --- Instantiated hook call.
const queryClient1 = useRenamedQueryClient()
queryClient1.getQueryCache().find(['todos'])
queryClient1.getQueryCache().findAll(['todos'])
//
const queryClient2 = new RenamedQueryClient({})
queryClient2.getQueryCache().find(['todos'])
queryClient2.getQueryCache().findAll(['todos'])
//
const queryCache2 = queryClient1.getQueryCache()
queryCache2.find(['todos'])
queryCache2.findAll(['todos'])
// --- Direct hook call.
useRenamedQueryClient().getQueryCache().find(['todos'])
useRenamedQueryClient().getQueryCache().findAll(['todos'])
//
const queryCache3 = useRenamedQueryClient().getQueryCache()
queryCache3.find(['todos'])
queryCache3.findAll(['todos'])

return <div>Example Component</div>
}
Loading