Skip to content

Commit

Permalink
fix: queryKeySerializer now in the right spot of the config
Browse files Browse the repository at this point in the history
  • Loading branch information
tannerlinsley committed Jun 24, 2020
1 parent ef5becb commit a68dc28
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 18 deletions.
7 changes: 3 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -207,7 +207,6 @@ This library is being built and maintained by me, @tannerlinsley and I am always
<!-- START doctoc generated TOC please keep comment here to allow auto update -->
<!-- DON'T EDIT THIS SECTION, INSTEAD RE-RUN doctoc TO UPDATE -->


- [Installation](#installation)
- [Defaults to keep in mind](#defaults-to-keep-in-mind)
- [Quick Start](#quick-start)
Expand Down Expand Up @@ -2323,10 +2322,10 @@ import { ReactQueryConfigProvider } from 'react-query'
const queryConfig = {
shared: {
suspense: false,
queryKeySerializerFn: defaultQueryKeySerializerFn,
},
queries: {
...shared,
suspense, // defaults to `shared.suspense`
queryKeySerializerFn: defaultQueryKeySerializerFn,
queryFn,
enabled: true,
retry: 3,
Expand All @@ -2344,7 +2343,7 @@ const queryConfig = {
useErrorBoundary: false, // falls back to suspense
},
mutations: {
...shared,
suspense, // defaults to `shared.suspense`
throwOnError: false,
onMutate: noop,
onError: noop,
Expand Down
2 changes: 1 addition & 1 deletion src/config.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,9 @@ export const configContext = React.createContext()
const DEFAULT_CONFIG = {
shared: {
suspense: false,
queryKeySerializerFn: defaultQueryKeySerializerFn,
},
queries: {
queryKeySerializerFn: defaultQueryKeySerializerFn,
queryFn: undefined,
enabled: true,
retry: 3,
Expand Down
2 changes: 1 addition & 1 deletion src/queryCache.js
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,7 @@ export function makeQueryCache({ frozen = isServer, defaultConfig } = {}) {
const [
queryHash,
queryKey,
] = configRef.current.shared.queryKeySerializerFn(predicate)
] = configRef.current.queries.queryKeySerializerFn(predicate)

predicate = d =>
exact ? d.queryHash === queryHash : deepIncludes(d.queryKey, queryKey)
Expand Down
31 changes: 19 additions & 12 deletions types/index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -305,14 +305,6 @@ export type InfiniteQueryFunction<

export interface BaseSharedOptions {
suspense: boolean
queryKeySerializerFn?: (
queryKey:
| QueryKeyPart[]
| string
| false
| undefined
| (() => QueryKeyPart[] | string | false | undefined)
) => [string, QueryKeyPart[]] | []
}

export interface BaseQueryOptions<TError = Error> {
Expand Down Expand Up @@ -357,7 +349,8 @@ export interface PrefetchQueryOptions<TResult, TError = Error>
throwOnError?: boolean
}

export interface SetQueryDataQueryOptions<TResult, TError = Error> extends QueryOptions<TResult, TError> {
export interface SetQueryDataQueryOptions<TResult, TError = Error>
extends QueryOptions<TResult, TError> {
exact?: boolean
}

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

export type MutationFunction<TResults, TVariables, TError = Error> = (
variables: TVariables,
mutateOptions?: MutateOptions<TResults, TVariables, TError>,
mutateOptions?: MutateOptions<TResults, TVariables, TError>
) => Promise<TResults>

export interface MutateOptions<TResult, TVariables, TError = Error> {
Expand Down Expand Up @@ -504,7 +497,10 @@ export type MutateFunction<
TError = Error
> = undefined extends TVariables
? (options?: MutateOptions<TResult, TVariables, TError>) => Promise<TResult>
: (variables: TVariables, options?: MutateOptions<TResult, TVariables, TError>) => Promise<TResult>
: (
variables: TVariables,
options?: MutateOptions<TResult, TVariables, TError>
) => Promise<TResult>

export interface MutationResultBase<TResult, TError = Error> {
status: 'idle' | 'loading' | 'error' | 'success'
Expand Down Expand Up @@ -637,7 +633,10 @@ export interface QueryCache {
getQueryData<T = unknown>(key: AnyQueryKey | string): T | undefined
setQueryData<TResult, TError>(
key: AnyQueryKey | string,
dataOrUpdater: TResult | undefined | ((oldData: TResult | undefined) => TResult | undefined),
dataOrUpdater:
| TResult
| undefined
| ((oldData: TResult | undefined) => TResult | undefined),
config?: SetQueryDataQueryOptions<TResult, TError>
): void
invalidateQueries<TResult>(
Expand Down Expand Up @@ -712,6 +711,14 @@ export interface ReactQueryProviderConfig<TError = Error> {
/** Defaults to the value of `suspense` if not defined otherwise */
useErrorBoundary?: boolean
refetchOnWindowFocus?: boolean
queryKeySerializerFn?: (
queryKey:
| QueryKeyPart[]
| string
| false
| undefined
| (() => QueryKeyPart[] | string | false | undefined)
) => [string, QueryKeyPart[]] | []
}
shared?: BaseSharedOptions
mutations?: {
Expand Down

0 comments on commit a68dc28

Please sign in to comment.