@@ -5,10 +5,10 @@ import { ASTUtils } from '../../utils/ast-utils'
55import { objectKeys } from '../../utils/object-utils'
66
77const QUERY_CALLS = {
8- useQuery : { key : 'queryKey' , fn : 'queryFn' } ,
9- createQuery : { key : 'queryKey' , fn : 'queryFn' } ,
10- useMutation : { key : 'mutationKey' , fn : 'mutationFn' } ,
11- createMutation : { key : 'mutationKey' , fn : 'mutationFn' } ,
8+ useQuery : { key : 'queryKey' , fn : 'queryFn' , type : 'query' } ,
9+ createQuery : { key : 'queryKey' , fn : 'queryFn' , type : 'query' } ,
10+ useMutation : { key : 'mutationKey' , fn : 'mutationFn' , type : 'mutation' } ,
11+ createMutation : { key : 'mutationKey' , fn : 'mutationFn' , type : 'mutation' } ,
1212}
1313
1414const messages = {
@@ -208,25 +208,38 @@ function runCheckOnNode(params: {
208208 fix ( fixer ) {
209209 const optionsObjectProperties : string [ ] = [ ]
210210
211- // queryKey
212- const firstArgument = callNode . arguments [ 0 ]
213- const queryKey = sourceCode . getText ( firstArgument )
214- const queryKeyProperty =
215- queryKey === callProps . key
216- ? callProps . key
217- : `${ callProps . key } : ${ queryKey } `
218-
219- optionsObjectProperties . push ( queryKeyProperty )
220-
221- // queryFn
222- if ( secondArgument && secondArgument !== optionsObject ) {
223- const queryFn = sourceCode . getText ( secondArgument )
224- const queryFnProperty =
225- queryFn === callProps . fn
211+ if ( callProps . type === 'query' || callNode . arguments . length > 1 ) {
212+ // queryKey
213+ const firstArgument = callNode . arguments [ 0 ]
214+ const queryKey = sourceCode . getText ( firstArgument )
215+ const queryKeyProperty =
216+ queryKey === callProps . key
217+ ? callProps . key
218+ : `${ callProps . key } : ${ queryKey } `
219+
220+ optionsObjectProperties . push ( queryKeyProperty )
221+
222+ // queryFn
223+ if ( secondArgument && secondArgument !== optionsObject ) {
224+ const queryFn = sourceCode . getText ( secondArgument )
225+ const queryFnProperty =
226+ queryFn === callProps . fn
227+ ? callProps . fn
228+ : `${ callProps . fn } : ${ queryFn } `
229+
230+ optionsObjectProperties . push ( queryFnProperty )
231+ }
232+ }
233+
234+ if ( callProps . type === 'mutation' && callNode . arguments . length === 1 ) {
235+ const firstArgument = callNode . arguments [ 0 ]
236+ const mutationFn = sourceCode . getText ( firstArgument )
237+ const mutationFnProperty =
238+ mutationFn === callProps . fn
226239 ? callProps . fn
227- : `${ callProps . fn } : ${ queryFn } `
240+ : `${ callProps . fn } : ${ mutationFn } `
228241
229- optionsObjectProperties . push ( queryFnProperty )
242+ optionsObjectProperties . push ( mutationFnProperty )
230243 }
231244
232245 // options
0 commit comments