Repository: tannerlinsley/react-query
Pull request #808 (2020-07-29 16:56:51)

fix(QueryCache): Use default configuration used for QueryCache instance for context
## Context

See test cases but when using `useQuery` with no config provider and a custom query cache provider, the `defaultConfig` was not being merged correctly in `queryCache.buildQuery`.

A previously failing test:

```js
test('uses defaultConfig for queries when they don\'t provide their own config', async () => {
    const cache = makeQueryCache({
      defaultConfig: {
        queries: {
          staleTime: Infinity,
        },
      },
    })

    function Page() {
      const { data } = useQuery('test', async () => {
        await sleep(10)
        return 'test'
      })

      return (
        <div>
          <h1>{data}</h1>
        </div>
      )
    }

    const rendered = render(
      <ReactQueryCacheProvider queryCache={cache}>
        <Page />
      </ReactQueryCacheProvider>
    )

    await waitFor(() => rendered.getByText('test'))

    expect(cache.getQuery('test')).toBeDefined()
    expect(cache.getQuery('test').config.staleTime).toBe(Infinity)
    cache.clear({ notify: false })
  })
```

`useConfigContext` was falling back to `defaultConfigRef` but when using `makeQueryCache`, the ref is not updated (on purpose) when merging in `defaultConfig`.

Now the actual merged `configRef` for the query cache is exposed so that we can access it in `useConfigContext`.

## Wrong `queryCache` variable being passed

I fixed another two issues with `buildQuery` and `notifyGlobalListeners` that was passing the `queryCache` module variable instead of `this` in the new refactored TS code.

## Exposing the config ref

~I'm not _sure_ whether you want it exposed off the instance like that or through some other means (since this would also consumers to mess with it?). However, it does address the issue.~

I am exposing it through `QueryCache.getDefaultConfig` which could be used to freeze or clone the config to prevent mutation.

Exposing it like this would mean:

- It's in the public API
- It should be added to API docs
- People could mess with it

I can document this as a new API, I could freeze it, whatever we think would make sense. We just need to get a reference to the merged queryCache-specific config.

## Changes

- Use `useQueryCache` in `useConfigContext` to fallback to queryCache's `configRef`
- Expose `QueryCache.getDefaultConfig()` method
- Fix passing default `queryCache` ref in `notifyGlobalListeners`
- Fix passing default `queryCache` ref in `buildQuery`

vercel[bot]: This pull request is being automatically deployed with Vercel ([learn more](https://vercel.link/github-learn-more)).
To see the status of your deployment, click on the icon next to each commit.
kamranayub: I am currently "integration" testing this in our repo.
kamranayub: Just seeing weird issues locally when testing where the query cache I am creating and providing via `ReactQueryCacheProvider` isn't actually being used in the component. Not sure yet what is causing that, whether it's a package linking issue or an actual issue with the code.
kamranayub: OK, the issue is that there were two major bugs with `makeQueryCache` and `QueryCache` usage because they were unknowingly passing `queryCache` module variable in a few places accidentally. I will fix those issues in this too.
kamranayub: Alrighty, this is working now as I would expect!

Patch:
diff --git a/.github/ISSUE_TEMPLATE/bug_report.md b/.github/ISSUE_TEMPLATE/bug_report.md
index dd84ea782..d7cd68d7f 100644
--- a/.github/ISSUE_TEMPLATE/bug_report.md
+++ b/.github/ISSUE_TEMPLATE/bug_report.md
@@ -25,14 +25,14 @@ If applicable, add screenshots to help explain your problem.
 
 **Desktop (please complete the following information):**
  - OS: [e.g. iOS]
- - Browser [e.g. chrome, safari]
- - Version [e.g. 22]
+ - Browser: [e.g. chrome, safari]
+ - Version: [e.g. 22]
 
 **Smartphone (please complete the following information):**
  - Device: [e.g. iPhone6]
  - OS: [e.g. iOS8.1]
- - Browser [e.g. stock browser, safari]
- - Version [e.g. 22]
+ - Browser: [e.g. stock browser, safari]
+ - Version: [e.g. 22]
 
 **Additional context**
 Add any other context about the problem here.
diff --git a/src/core/queryCache.ts b/src/core/queryCache.ts
index 08f34f591..923043ec9 100644
--- a/src/core/queryCache.ts
+++ b/src/core/queryCache.ts
@@ -115,7 +115,11 @@ export class QueryCache {
       0
     )
 
-    this.globalListeners.forEach(d => d(queryCache, query))
+    this.globalListeners.forEach(d => d(this, query))
+  }
+
+  getDefaultConfig() {
+    return this.configRef.current
   }
 
   subscribe(listener: QueryCacheListener): () => void {
@@ -242,7 +246,7 @@ export class QueryCache {
 
     if (!query) {
       query = new Query<TResult, TError>({
-        queryCache,
+        queryCache: this,
         queryKey,
         queryHash,
         config,
@@ -403,9 +407,9 @@ export class QueryCache {
   }
 }
 
-export const queryCache = makeQueryCache({ frozen: isServer })
-
-export const queryCaches = [queryCache]
+const defaultQueryCache = makeQueryCache({ frozen: isServer })
+export { defaultQueryCache as queryCache }
+export const queryCaches = [defaultQueryCache]
 
 export function makeQueryCache(config?: QueryCacheConfig) {
   return new QueryCache(config)
diff --git a/src/react/ReactQueryConfigProvider.tsx b/src/react/ReactQueryConfigProvider.tsx
index 47f40fd53..b05064858 100644
--- a/src/react/ReactQueryConfigProvider.tsx
+++ b/src/react/ReactQueryConfigProvider.tsx
@@ -1,14 +1,19 @@
 import React from 'react'
-
 import { DEFAULT_CONFIG, defaultConfigRef } from '../core/config'
 import { ReactQueryConfig } from '../core/types'
+import { useQueryCache } from './ReactQueryCacheProvider'
 
 const configContext = React.createContext<ReactQueryConfig | undefined>(
   undefined
 )
 
 export function useConfigContext() {
-  return React.useContext(configContext) || defaultConfigRef.current
+  const queryCache = useQueryCache()
+  return (
+    React.useContext(configContext) ||
+    queryCache.getDefaultConfig() ||
+    defaultConfigRef.current
+  )
 }
 
 export interface ReactQueryProviderConfig extends ReactQueryConfig {}
diff --git a/types/index.d.ts b/types/index.d.ts
index dc6e925cc..4b4bed2b2 100644
--- a/types/index.d.ts
+++ b/types/index.d.ts
@@ -635,16 +635,16 @@ export interface QueryCache {
 export const queryCache: QueryCache
 export const queryCaches: QueryCache[]
 
-export interface MakeQueryCacheOptions {
+export interface MakeQueryCacheOptions<TError = Error> {
   frozen?: boolean
-  defaultConfig?: BaseQueryOptions
+  defaultConfig?: ReactQueryProviderConfig<TError>
 }
 
 /**
  * a factory that creates a new query cache
  */
-export function makeQueryCache(
-  makeQueryCacheOptions?: MakeQueryCacheOptions
+export function makeQueryCache<TError = Error>(
+  makeQueryCacheOptions?: MakeQueryCacheOptions<TError>
 ): QueryCache
 
 /**


Test patch:
diff --git a/src/core/tests/queryCache.test.tsx b/src/core/tests/queryCache.test.tsx
index 45028ce3f..070958bff 100644
--- a/src/core/tests/queryCache.test.tsx
+++ b/src/core/tests/queryCache.test.tsx
@@ -1,5 +1,5 @@
 import { sleep } from './utils'
-import { queryCache, queryCaches } from '../'
+import { queryCache as defaultQueryCache, queryCaches } from '../'
 import { makeQueryCache } from '../queryCache'
 
 describe('queryCache', () => {
@@ -10,25 +10,28 @@ describe('queryCache', () => {
   test('setQueryData does not crash if query could not be found', () => {
     const user = { userId: 1 }
     expect(() =>
-      queryCache.setQueryData(['USER', user], (prevUser?: typeof user) => ({
-        ...prevUser!,
-        name: 'Edvin',
-      }))
+      defaultQueryCache.setQueryData(
+        ['USER', user],
+        (prevUser?: typeof user) => ({
+          ...prevUser!,
+          name: 'Edvin',
+        })
+      )
     ).not.toThrow()
   })
 
   test('setQueryData does not crash when variable is null', () => {
-    queryCache.setQueryData(['USER', { userId: null }], 'Old Data')
+    defaultQueryCache.setQueryData(['USER', { userId: null }], 'Old Data')
 
     expect(() =>
-      queryCache.setQueryData(['USER', { userId: null }], 'New Data')
+      defaultQueryCache.setQueryData(['USER', { userId: null }], 'New Data')
     ).not.toThrow()
   })
 
   // https://github.com/tannerlinsley/react-query/issues/652
   test('prefetchQuery should not retry by default', async () => {
     await expect(
-      queryCache.prefetchQuery(
+      defaultQueryCache.prefetchQuery(
         'key',
         async () => {
           throw new Error('error')
@@ -41,16 +44,16 @@ describe('queryCache', () => {
 
   test('prefetchQuery returns the cached data on cache hits', async () => {
     const fetchFn = () => Promise.resolve('data')
-    const first = await queryCache.prefetchQuery('key', fetchFn)
-    const second = await queryCache.prefetchQuery('key', fetchFn)
+    const first = await defaultQueryCache.prefetchQuery('key', fetchFn)
+    const second = await defaultQueryCache.prefetchQuery('key', fetchFn)
 
     expect(second).toBe(first)
   })
 
   test('prefetchQuery should not force fetch', async () => {
-    queryCache.setQueryData('key', 'og', { staleTime: 100 })
+    defaultQueryCache.setQueryData('key', 'og', { staleTime: 100 })
     const fetchFn = () => Promise.resolve('new')
-    const first = await queryCache.prefetchQuery(
+    const first = await defaultQueryCache.prefetchQuery(
       'key',
       fetchFn,
       {
@@ -65,7 +68,7 @@ describe('queryCache', () => {
 
   test('prefetchQuery should throw error when throwOnError is true', async () => {
     await expect(
-      queryCache.prefetchQuery(
+      defaultQueryCache.prefetchQuery(
         'key',
         async () => {
           throw new Error('error')
@@ -81,9 +84,9 @@ describe('queryCache', () => {
   test('should notify listeners when new query is added', async () => {
     const callback = jest.fn()
 
-    queryCache.subscribe(callback)
+    defaultQueryCache.subscribe(callback)
 
-    queryCache.prefetchQuery('test', () => 'data')
+    defaultQueryCache.prefetchQuery('test', () => 'data')
 
     await sleep(100)
 
@@ -93,22 +96,24 @@ describe('queryCache', () => {
   test('should include the queryCache and query when notifying listeners', async () => {
     const callback = jest.fn()
 
-    queryCache.subscribe(callback)
+    defaultQueryCache.subscribe(callback)
 
-    queryCache.prefetchQuery('test', () => 'data')
-    const query = queryCache.getQuery('test')
+    defaultQueryCache.prefetchQuery('test', () => 'data')
+    const query = defaultQueryCache.getQuery('test')
 
     await sleep(100)
 
-    expect(callback).toHaveBeenCalledWith(queryCache, query)
+    expect(callback).toHaveBeenCalledWith(defaultQueryCache, query)
   })
 
   test('should notify subscribers when new query with initialData is added', async () => {
     const callback = jest.fn()
 
-    queryCache.subscribe(callback)
+    defaultQueryCache.subscribe(callback)
 
-    queryCache.prefetchQuery('test', () => 'data', { initialData: 'initial' })
+    defaultQueryCache.prefetchQuery('test', () => 'data', {
+      initialData: 'initial',
+    })
 
     await sleep(100)
 
@@ -116,68 +121,70 @@ describe('queryCache', () => {
   })
 
   test('setQueryData creates a new query if query was not found', () => {
-    queryCache.setQueryData('foo', 'bar')
+    defaultQueryCache.setQueryData('foo', 'bar')
 
-    expect(queryCache.getQueryData('foo')).toBe('bar')
+    expect(defaultQueryCache.getQueryData('foo')).toBe('bar')
   })
 
   test('setQueryData creates a new query if query was not found', () => {
-    queryCache.setQueryData('baz', 'qux')
+    defaultQueryCache.setQueryData('baz', 'qux')
 
-    expect(queryCache.getQueryData('baz')).toBe('qux')
+    expect(defaultQueryCache.getQueryData('baz')).toBe('qux')
   })
 
   test('removeQueries does not crash when exact is provided', async () => {
     const fetchFn = () => Promise.resolve('data')
 
     // check the query was added to the cache
-    await queryCache.prefetchQuery('key', fetchFn)
-    expect(queryCache.getQuery('key')).toBeTruthy()
+    await defaultQueryCache.prefetchQuery('key', fetchFn)
+    expect(defaultQueryCache.getQuery('key')).toBeTruthy()
 
     // check the error doesn't occur
-    expect(() => queryCache.removeQueries('key', { exact: true })).not.toThrow()
+    expect(() =>
+      defaultQueryCache.removeQueries('key', { exact: true })
+    ).not.toThrow()
 
     // check query was successful removed
-    expect(queryCache.getQuery('key')).toBeFalsy()
+    expect(defaultQueryCache.getQuery('key')).toBeFalsy()
   })
 
   test('setQueryData should schedule stale timeout, if staleTime is set', async () => {
-    queryCache.setQueryData('key', 'test data', { staleTime: 10 })
+    defaultQueryCache.setQueryData('key', 'test data', { staleTime: 10 })
     // @ts-expect-error
-    expect(queryCache.getQuery('key')!.staleTimeout).not.toBeUndefined()
+    expect(defaultQueryCache.getQuery('key')!.staleTimeout).not.toBeUndefined()
   })
 
   test('setQueryData should not schedule stale timeout by default', async () => {
-    queryCache.setQueryData('key', 'test data')
+    defaultQueryCache.setQueryData('key', 'test data')
     // @ts-expect-error
-    expect(queryCache.getQuery('key')!.staleTimeout).toBeUndefined()
+    expect(defaultQueryCache.getQuery('key')!.staleTimeout).toBeUndefined()
   })
 
   test('setQueryData should not schedule stale timeout, if staleTime is set to `Infinity`', async () => {
-    queryCache.setQueryData('key', 'test data', { staleTime: Infinity })
+    defaultQueryCache.setQueryData('key', 'test data', { staleTime: Infinity })
     // @ts-expect-error
-    expect(queryCache.getQuery('key')!.staleTimeout).toBeUndefined()
+    expect(defaultQueryCache.getQuery('key')!.staleTimeout).toBeUndefined()
   })
 
   test('setQueryData schedules stale timeouts appropriately', async () => {
-    queryCache.setQueryData('key', 'test data', { staleTime: 100 })
+    defaultQueryCache.setQueryData('key', 'test data', { staleTime: 100 })
 
-    expect(queryCache.getQuery('key')!.state.data).toEqual('test data')
-    expect(queryCache.getQuery('key')!.state.isStale).toEqual(false)
+    expect(defaultQueryCache.getQuery('key')!.state.data).toEqual('test data')
+    expect(defaultQueryCache.getQuery('key')!.state.isStale).toEqual(false)
 
     await new Promise(resolve => setTimeout(resolve, 100))
 
-    expect(queryCache.getQuery('key')!.state.isStale).toEqual(true)
+    expect(defaultQueryCache.getQuery('key')!.state.isStale).toEqual(true)
   })
 
   test('setQueryData updater function works as expected', () => {
     const updater = jest.fn(oldData => `new data + ${oldData}`)
 
-    queryCache.setQueryData('updater', 'test data')
-    queryCache.setQueryData('updater', updater)
+    defaultQueryCache.setQueryData('updater', 'test data')
+    defaultQueryCache.setQueryData('updater', updater)
 
     expect(updater).toHaveBeenCalled()
-    expect(queryCache.getQuery('updater')!.state.data).toEqual(
+    expect(defaultQueryCache.getQuery('updater')!.state.data).toEqual(
       'new data + test data'
     )
   })
@@ -186,10 +193,10 @@ describe('queryCache', () => {
     const fetchData1 = () => Promise.resolve('data1')
     const fetchData2 = () => Promise.resolve('data2')
     const fetchDifferentData = () => Promise.resolve('data3')
-    await queryCache.prefetchQuery(['data', { page: 1 }], fetchData1)
-    await queryCache.prefetchQuery(['data', { page: 2 }], fetchData2)
-    await queryCache.prefetchQuery(['differentData'], fetchDifferentData)
-    const queries = queryCache.getQueries('data')
+    await defaultQueryCache.prefetchQuery(['data', { page: 1 }], fetchData1)
+    await defaultQueryCache.prefetchQuery(['data', { page: 2 }], fetchData2)
+    await defaultQueryCache.prefetchQuery(['differentData'], fetchDifferentData)
+    const queries = defaultQueryCache.getQueries('data')
     const data = queries.map(query => query.state.data)
     expect(data).toEqual(['data1', 'data2'])
   })
@@ -197,10 +204,12 @@ describe('queryCache', () => {
   test('stale timeout dispatch is not called if query is no longer in the query cache', async () => {
     const queryKey = 'key'
     const fetchData = () => Promise.resolve('data')
-    await queryCache.prefetchQuery(queryKey, fetchData, { staleTime: 100 })
-    const query = queryCache.getQuery(queryKey)
+    await defaultQueryCache.prefetchQuery(queryKey, fetchData, {
+      staleTime: 100,
+    })
+    const query = defaultQueryCache.getQuery(queryKey)
     expect(query!.state.isStale).toBe(false)
-    queryCache.removeQueries(queryKey)
+    defaultQueryCache.removeQueries(queryKey)
     await sleep(50)
     expect(query!.state.isStale).toBe(false)
   })
@@ -208,11 +217,11 @@ describe('queryCache', () => {
   test('query interval is cleared when unsubscribed to a refetchInterval query', async () => {
     const queryKey = 'key'
     const fetchData = () => Promise.resolve('data')
-    await queryCache.prefetchQuery(queryKey, fetchData, {
+    await defaultQueryCache.prefetchQuery(queryKey, fetchData, {
       cacheTime: 0,
       refetchInterval: 1,
     })
-    const query = queryCache.getQuery(queryKey)!
+    const query = defaultQueryCache.getQuery(queryKey)!
     const instance = query.subscribe()
     instance.updateConfig(query.config)
     // @ts-expect-error
@@ -221,47 +230,82 @@ describe('queryCache', () => {
     // @ts-expect-error
     expect(instance.refetchIntervalId).toBeUndefined()
     await sleep(10)
-    expect(queryCache.getQuery(queryKey)).toBeUndefined()
+    expect(defaultQueryCache.getQuery(queryKey)).toBeUndefined()
   })
 
   test('query is garbage collected when unsubscribed to', async () => {
     const queryKey = 'key'
     const fetchData = () => Promise.resolve('data')
-    await queryCache.prefetchQuery(queryKey, fetchData, { cacheTime: 0 })
-    const query = queryCache.getQuery(queryKey)!
+    await defaultQueryCache.prefetchQuery(queryKey, fetchData, { cacheTime: 0 })
+    const query = defaultQueryCache.getQuery(queryKey)!
     expect(query.state.markedForGarbageCollection).toBe(false)
     const instance = query.subscribe()
     instance.unsubscribe()
     expect(query.state.markedForGarbageCollection).toBe(true)
     await sleep(10)
-    expect(queryCache.getQuery(queryKey)).toBeUndefined()
+    expect(defaultQueryCache.getQuery(queryKey)).toBeUndefined()
   })
 
   test('query is not garbage collected unless markedForGarbageCollection is true', async () => {
     const queryKey = 'key'
     const fetchData = () => Promise.resolve(undefined)
-    await queryCache.prefetchQuery(queryKey, fetchData, { cacheTime: 0 })
-    const query = queryCache.getQuery(queryKey)!
+    await defaultQueryCache.prefetchQuery(queryKey, fetchData, { cacheTime: 0 })
+    const query = defaultQueryCache.getQuery(queryKey)!
     expect(query.state.markedForGarbageCollection).toBe(false)
     const instance = query.subscribe()
     instance.unsubscribe()
     expect(query.state.markedForGarbageCollection).toBe(true)
-    queryCache.clear({ notify: false })
-    queryCache.setQueryData(queryKey, 'data')
+    defaultQueryCache.clear({ notify: false })
+    defaultQueryCache.setQueryData(queryKey, 'data')
     await sleep(10)
-    const newQuery = queryCache.getQuery(queryKey)!
+    const newQuery = defaultQueryCache.getQuery(queryKey)!
     expect(newQuery.state.markedForGarbageCollection).toBe(false)
     expect(newQuery.state.data).toBe('data')
   })
 
-  test('makeQueryCache merges defaultConfig so providing a queryFn does not overwrite the default queryKeySerializerFn', async () => {
-    const queryFn = () => 'data'
-    const queryCache = makeQueryCache({
-      defaultConfig: { queries: { queryFn } },
+  describe('makeQueryCache', () => {
+    test('merges defaultConfig so providing a queryFn does not overwrite the default queryKeySerializerFn', async () => {
+      const queryFn = () => 'data'
+      const queryCache = makeQueryCache({
+        defaultConfig: { queries: { queryFn } },
+      })
+
+      expect(() => queryCache.buildQuery('test')).not.toThrow(
+        'config.queryKeySerializerFn is not a function'
+      )
     })
 
-    expect(() => queryCache.buildQuery('test')).not.toThrow(
-      'config.queryKeySerializerFn is not a function'
-    )
+    test('merges defaultConfig when query is added to cache', async () => {
+      const queryCache = makeQueryCache({
+        defaultConfig: {
+          queries: { refetchOnMount: false, staleTime: Infinity },
+        },
+      })
+
+      const queryKey = 'key'
+      const fetchData = () => Promise.resolve(undefined)
+      await queryCache.prefetchQuery(queryKey, fetchData)
+      const newQuery = queryCache.getQuery(queryKey)
+      expect(newQuery?.config.staleTime).toBe(Infinity)
+      expect(newQuery?.config.refetchOnMount).toBe(false)
+    })
+
+    test('built queries are referencing the correct queryCache', () => {
+      const queryCache = makeQueryCache()
+      const query = queryCache.buildQuery('test')
+
+      expect(query.queryCache).toBe(queryCache)
+    })
+
+    test('notifyGlobalListeners passes the same instance', () => {
+      const queryCache = makeQueryCache()
+      const subscriber = jest.fn()
+      const unsubscribe = queryCache.subscribe(subscriber)
+      const query = queryCache.buildQuery('test')
+      query.setData('foo');
+      expect(subscriber).toHaveBeenCalledWith(queryCache, query)
+
+      unsubscribe()
+    })
   })
 })
diff --git a/src/react/tests/ReactQueryCacheProvider.test.tsx b/src/react/tests/ReactQueryCacheProvider.test.tsx
index 8334fa38e..1dbc774db 100644
--- a/src/react/tests/ReactQueryCacheProvider.test.tsx
+++ b/src/react/tests/ReactQueryCacheProvider.test.tsx
@@ -184,4 +184,39 @@ describe('ReactQueryCacheProvider', () => {
     expect(caches[0].clear).toHaveBeenCalled()
     customCache.clear({ notify: false })
   })
+
+  test('uses defaultConfig for queries when they don\'t provide their own config', async () => {
+    const cache = makeQueryCache({
+      defaultConfig: {
+        queries: {
+          staleTime: Infinity,
+        },
+      },
+    })
+
+    function Page() {
+      const { data } = useQuery('test', async () => {
+        await sleep(10)
+        return 'test'
+      })
+
+      return (
+        <div>
+          <h1>{data}</h1>
+        </div>
+      )
+    }
+
+    const rendered = render(
+      <ReactQueryCacheProvider queryCache={cache}>
+        <Page />
+      </ReactQueryCacheProvider>
+    )
+
+    await waitFor(() => rendered.getByText('test'))
+
+    expect(cache.getQuery('test')).toBeDefined()
+    expect(cache.getQuery('test')?.config.staleTime).toBe(Infinity)
+    cache.clear({ notify: false })
+  })
 })
diff --git a/types/test.ts b/types/test.ts
index db2d5459b..7b790ee63 100644
--- a/types/test.ts
+++ b/types/test.ts
@@ -8,9 +8,12 @@ import {
   useQuery,
   queryCache,
   CachedQuery,
+  makeQueryCache,
 } from 'react-query'
 
-class FooError extends Error {}
+class FooError extends Error {
+  foo = true
+}
 
 function resetErrorBoundaries() {
   queryCache.resetErrorBoundaries // $ExpectType () => void
@@ -39,36 +42,39 @@ function prefetchQuery() {
 }
 
 function getQueryData() {
-  queryCache.getQueryData(['queryKey']);
-  queryCache.getQueryData('queryKey');
-  queryCache.getQueryData(true);
-  queryCache.getQueryData((query) => true);
+  queryCache.getQueryData(['queryKey'])
+  queryCache.getQueryData('queryKey')
+  queryCache.getQueryData(true)
+  queryCache.getQueryData(query => true)
 }
 
 function setQueryData() {
-  queryCache.setQueryData(['queryKey'], ['data']);
-  queryCache.setQueryData('queryKey', ['data']);
-  queryCache.setQueryData(true, ['data']);
-  queryCache.setQueryData((query) => true, ['data']);
+  queryCache.setQueryData(['queryKey'], ['data'])
+  queryCache.setQueryData('queryKey', ['data'])
+  queryCache.setQueryData(true, ['data'])
+  queryCache.setQueryData(query => true, ['data'])
 }
 
 function getQuery() {
-  queryCache.getQuery(['queryKey']);
-  queryCache.getQuery('queryKey');
-  queryCache.getQuery(true);
-  queryCache.getQuery((query) => true);
+  queryCache.getQuery(['queryKey'])
+  queryCache.getQuery('queryKey')
+  queryCache.getQuery(true)
+  queryCache.getQuery(query => true)
 }
 
 function getQueries() {
-  queryCache.getQueries(['queryKey']);
-  queryCache.getQueries('queryKey');
-  queryCache.getQueries(true);
-  queryCache.getQueries((query) => true);
+  queryCache.getQueries(['queryKey'])
+  queryCache.getQueries('queryKey')
+  queryCache.getQueries(true)
+  queryCache.getQueries(query => true)
 }
 
 function cachedQueryErrorState() {
-  const query = queryCache.getQuery(['queryKey']) as CachedQuery<unknown, FooError>
-  const error: FooError | null | undefined = query.state.error;
+  const query = queryCache.getQuery(['queryKey']) as CachedQuery<
+    unknown,
+    FooError
+  >
+  const error: FooError | null | undefined = query.state.error
 }
 
 function simpleQuery() {
@@ -598,3 +604,16 @@ function mutationStatusDiscriminatedUnion() {
     mutationState.error // $ExpectType undefined
   }
 }
+
+function makeQueryCacheTest() {
+  makeQueryCache<FooError>({
+    defaultConfig: {
+      queries: {
+        refetchOnMount: false,
+        onError: err => {
+          err.foo
+        },
+      },
+    },
+  })
+}