Skip to content

Commit

Permalink
fix: single query methods should be exact by default (#1756)
Browse files Browse the repository at this point in the history
  • Loading branch information
boschni committed Feb 6, 2021
1 parent 2da342c commit 0b8c55c
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 0 deletions.
5 changes: 5 additions & 0 deletions src/core/queryCache.ts
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,11 @@ export class QueryCache extends Subscribable<QueryCacheListener> {
arg2?: QueryFilters
): Query<TQueryFnData, TError, TData> | undefined {
const [filters] = parseFilterArgs(arg1, arg2)

if (typeof filters.exact === 'undefined') {
filters.exact = true
}

return this.queries.find(query => matchQuery(filters, query))
}

Expand Down
19 changes: 19 additions & 0 deletions src/core/tests/queryClient.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -153,6 +153,25 @@ describe('queryClient', () => {
})
})

describe('getQueryData', () => {
test('should return the query data if the query is found', () => {
const key = queryKey()
queryClient.setQueryData([key, 'id'], 'bar')
expect(queryClient.getQueryData([key, 'id'])).toBe('bar')
})

test('should return undefined if the query is not found', () => {
const key = queryKey()
expect(queryClient.getQueryData(key)).toBeUndefined()
})

test('should match exact by default', () => {
const key = queryKey()
queryClient.setQueryData([key, 'id'], 'bar')
expect(queryClient.getQueryData([key])).toBeUndefined()
})
})

describe('fetchQuery', () => {
// https://github.com/tannerlinsley/react-query/issues/652
test('should not retry by default', async () => {
Expand Down

1 comment on commit 0b8c55c

@vercel
Copy link

@vercel vercel bot commented on 0b8c55c Feb 6, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please sign in to comment.