File tree Expand file tree Collapse file tree 2 files changed +15
-1
lines changed Expand file tree Collapse file tree 2 files changed +15
-1
lines changed Original file line number Diff line number Diff line change @@ -107,7 +107,10 @@ export class QueryClient {
107
107
options ?: SetDataOptions
108
108
) : TData {
109
109
const parsedOptions = parseQueryArgs ( queryKey )
110
- return this . queryCache . build ( this , parsedOptions ) . setData ( updater , options )
110
+ const defaultedOptions = this . defaultQueryOptions ( parsedOptions )
111
+ return this . queryCache
112
+ . build ( this , defaultedOptions )
113
+ . setData ( updater , options )
111
114
}
112
115
113
116
getQueryState < TData = unknown , TError = undefined > (
Original file line number Diff line number Diff line change @@ -91,6 +91,17 @@ describe('queryCache', () => {
91
91
} ) . not . toThrow ( )
92
92
} )
93
93
94
+ test ( 'setQueryData should use default options' , ( ) => {
95
+ const key = queryKey ( )
96
+ const testClient = new QueryClient ( {
97
+ defaultOptions : { queries : { queryKeyHashFn : ( ) => 'someKey' } } ,
98
+ } )
99
+ const testCache = testClient . getQueryCache ( )
100
+ testClient . setQueryData ( key , 'data' )
101
+ expect ( testClient . getQueryData ( key ) ) . toBe ( 'data' )
102
+ expect ( testCache . find ( key ) ) . toBe ( testCache . get ( 'someKey' ) )
103
+ } )
104
+
94
105
// https://github.com/tannerlinsley/react-query/issues/652
95
106
test ( 'fetchQuery should not retry by default' , async ( ) => {
96
107
const consoleMock = mockConsoleError ( )
You can’t perform that action at this time.
0 commit comments