Skip to content

Commit a68dc28

Browse files
committed
fix: queryKeySerializer now in the right spot of the config
1 parent ef5becb commit a68dc28

File tree

4 files changed

+24
-18
lines changed

4 files changed

+24
-18
lines changed

README.md

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -207,7 +207,6 @@ This library is being built and maintained by me, @tannerlinsley and I am always
207207
<!-- START doctoc generated TOC please keep comment here to allow auto update -->
208208
<!-- DON'T EDIT THIS SECTION, INSTEAD RE-RUN doctoc TO UPDATE -->
209209

210-
211210
- [Installation](#installation)
212211
- [Defaults to keep in mind](#defaults-to-keep-in-mind)
213212
- [Quick Start](#quick-start)
@@ -2323,10 +2322,10 @@ import { ReactQueryConfigProvider } from 'react-query'
23232322
const queryConfig = {
23242323
shared: {
23252324
suspense: false,
2326-
queryKeySerializerFn: defaultQueryKeySerializerFn,
23272325
},
23282326
queries: {
2329-
...shared,
2327+
suspense, // defaults to `shared.suspense`
2328+
queryKeySerializerFn: defaultQueryKeySerializerFn,
23302329
queryFn,
23312330
enabled: true,
23322331
retry: 3,
@@ -2344,7 +2343,7 @@ const queryConfig = {
23442343
useErrorBoundary: false, // falls back to suspense
23452344
},
23462345
mutations: {
2347-
...shared,
2346+
suspense, // defaults to `shared.suspense`
23482347
throwOnError: false,
23492348
onMutate: noop,
23502349
onError: noop,

src/config.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,9 @@ export const configContext = React.createContext()
66
const DEFAULT_CONFIG = {
77
shared: {
88
suspense: false,
9-
queryKeySerializerFn: defaultQueryKeySerializerFn,
109
},
1110
queries: {
11+
queryKeySerializerFn: defaultQueryKeySerializerFn,
1212
queryFn: undefined,
1313
enabled: true,
1414
retry: 3,

src/queryCache.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -108,7 +108,7 @@ export function makeQueryCache({ frozen = isServer, defaultConfig } = {}) {
108108
const [
109109
queryHash,
110110
queryKey,
111-
] = configRef.current.shared.queryKeySerializerFn(predicate)
111+
] = configRef.current.queries.queryKeySerializerFn(predicate)
112112

113113
predicate = d =>
114114
exact ? d.queryHash === queryHash : deepIncludes(d.queryKey, queryKey)

types/index.d.ts

Lines changed: 19 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -305,14 +305,6 @@ export type InfiniteQueryFunction<
305305

306306
export interface BaseSharedOptions {
307307
suspense: boolean
308-
queryKeySerializerFn?: (
309-
queryKey:
310-
| QueryKeyPart[]
311-
| string
312-
| false
313-
| undefined
314-
| (() => QueryKeyPart[] | string | false | undefined)
315-
) => [string, QueryKeyPart[]] | []
316308
}
317309

318310
export interface BaseQueryOptions<TError = Error> {
@@ -357,7 +349,8 @@ export interface PrefetchQueryOptions<TResult, TError = Error>
357349
throwOnError?: boolean
358350
}
359351

360-
export interface SetQueryDataQueryOptions<TResult, TError = Error> extends QueryOptions<TResult, TError> {
352+
export interface SetQueryDataQueryOptions<TResult, TError = Error>
353+
extends QueryOptions<TResult, TError> {
361354
exact?: boolean
362355
}
363356

@@ -475,7 +468,7 @@ export function useMutation<TResults, TVariables = undefined, TError = Error>(
475468

476469
export type MutationFunction<TResults, TVariables, TError = Error> = (
477470
variables: TVariables,
478-
mutateOptions?: MutateOptions<TResults, TVariables, TError>,
471+
mutateOptions?: MutateOptions<TResults, TVariables, TError>
479472
) => Promise<TResults>
480473

481474
export interface MutateOptions<TResult, TVariables, TError = Error> {
@@ -504,7 +497,10 @@ export type MutateFunction<
504497
TError = Error
505498
> = undefined extends TVariables
506499
? (options?: MutateOptions<TResult, TVariables, TError>) => Promise<TResult>
507-
: (variables: TVariables, options?: MutateOptions<TResult, TVariables, TError>) => Promise<TResult>
500+
: (
501+
variables: TVariables,
502+
options?: MutateOptions<TResult, TVariables, TError>
503+
) => Promise<TResult>
508504

509505
export interface MutationResultBase<TResult, TError = Error> {
510506
status: 'idle' | 'loading' | 'error' | 'success'
@@ -637,7 +633,10 @@ export interface QueryCache {
637633
getQueryData<T = unknown>(key: AnyQueryKey | string): T | undefined
638634
setQueryData<TResult, TError>(
639635
key: AnyQueryKey | string,
640-
dataOrUpdater: TResult | undefined | ((oldData: TResult | undefined) => TResult | undefined),
636+
dataOrUpdater:
637+
| TResult
638+
| undefined
639+
| ((oldData: TResult | undefined) => TResult | undefined),
641640
config?: SetQueryDataQueryOptions<TResult, TError>
642641
): void
643642
invalidateQueries<TResult>(
@@ -712,6 +711,14 @@ export interface ReactQueryProviderConfig<TError = Error> {
712711
/** Defaults to the value of `suspense` if not defined otherwise */
713712
useErrorBoundary?: boolean
714713
refetchOnWindowFocus?: boolean
714+
queryKeySerializerFn?: (
715+
queryKey:
716+
| QueryKeyPart[]
717+
| string
718+
| false
719+
| undefined
720+
| (() => QueryKeyPart[] | string | false | undefined)
721+
) => [string, QueryKeyPart[]] | []
715722
}
716723
shared?: BaseSharedOptions
717724
mutations?: {

0 commit comments

Comments
 (0)