Skip to content

Commit

Permalink
fix(types): queryCache.getQueries (#688)
Browse files Browse the repository at this point in the history
* fix(types): queryCache.getQueries

* fix(formatting)

* fix(types): queryCache parameters

* fix(formatting)

* fix(formatting)

Co-authored-by: Jen Gettings <[email protected]>
  • Loading branch information
jgettings and Jen Gettings authored Jul 2, 2020
1 parent 989c4cd commit 04a1346
Show file tree
Hide file tree
Showing 2 changed files with 44 additions and 16 deletions.
32 changes: 16 additions & 16 deletions types/index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -540,6 +540,12 @@ export interface CachedQuery<T, TError = unknown> {

export type QueryKey<TKey> = TKey | false | null | undefined

export type QueryKeyOrPredicateFn =
| AnyQueryKey
| string
| boolean
| ((query: CachedQuery<unknown>) => boolean)

export interface QueryCache {
prefetchQuery<TResult, TKey extends AnyQueryKey, TError = Error>(
queryKey: QueryKey<TKey>,
Expand Down Expand Up @@ -580,20 +586,17 @@ export interface QueryCache {
prefetch?: PrefetchQueryOptions
}): Promise<TResult>

getQueryData<T = unknown>(key: AnyQueryKey | string): T | undefined
getQueryData<T = unknown>(key: QueryKeyOrPredicateFn): T | undefined
setQueryData<TResult, TError = Error>(
key: AnyQueryKey | string,
queryKeyOrPredicateFn: QueryKeyOrPredicateFn,
dataOrUpdater:
| TResult
| undefined
| ((oldData: TResult | undefined) => TResult | undefined),
config?: SetQueryDataQueryOptions<TResult, TError>
): void
invalidateQueries<TResult>(
queryKeyOrPredicateFn:
| AnyQueryKey
| string
| ((query: CachedQuery<unknown>) => boolean),
queryKeyOrPredicateFn: QueryKeyOrPredicateFn,
{
exact,
throwOnError,
Expand All @@ -607,19 +610,16 @@ export interface QueryCache {
}
): Promise<TResult>
removeQueries(
queryKeyOrPredicateFn:
| AnyQueryKey
| string
| ((query: CachedQuery<unknown>) => boolean),
queryKeyOrPredicateFn: QueryKeyOrPredicateFn,
{ exact }?: { exact?: boolean }
): void
getQuery(queryKey: AnyQueryKey): CachedQuery<unknown> | undefined
getQueries(queryKey: AnyQueryKey): Array<CachedQuery<unknown>>
getQuery(queryKeyOrPredicateFn: QueryKeyOrPredicateFn): CachedQuery<unknown> | undefined
getQueries(
queryKeyOrPredicateFn: QueryKeyOrPredicateFn,
{ exact }?: { exact?: boolean }
): Array<CachedQuery<unknown>>
cancelQueries(
queryKeyOrPredicateFn:
| AnyQueryKey
| string
| ((query: CachedQuery<unknown>) => boolean),
queryKeyOrPredicateFn: QueryKeyOrPredicateFn,
{ exact }?: { exact?: boolean }
): void
isFetching: number
Expand Down
28 changes: 28 additions & 0 deletions types/test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,34 @@ function prefetchQuery() {
})
}

function getQueryData() {
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']);
}

function getQuery() {
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);
}

function simpleQuery() {
// Query - simple case
const querySimple = useQuery<string, 'todos'>('todos', () =>
Expand Down

0 comments on commit 04a1346

Please sign in to comment.