Skip to content
Source
Sign inSign up
TanStack/query

Query options in core v6 #12708

Draftbenjavicente(GitHub profile, opens in a new tab)wants to merge 2 commits intoquery-v6 fromrefs/pull/12708/headopened View on GitHub

Showing 39 changed files with 38 additions and 1 deletion (loading 36).

x
0 of 39 viewed, 39 left
6 additions and 0 deletions.changeset/core-query-options.mdAdded
View file
@@ -0,0 +1,6 @@
+---
+'@tanstack/query-core': minor
+'@tanstack/vue-query': minor
+---
+​
+Add framework-agnostic `queryOptions`, `infiniteQueryOptions`, and `mutationOptions` helpers. They only accept options that every adapter supports, so framework-specific options such as `throwOnError`, `suspense`, and `notifyOnChangeProps` stay in each adapter's helpers. `useQuery` and `useInfiniteQuery` from `@tanstack/vue-query` accept a getter of these options.
2 additions and 0 deletionsdocs/framework/react/guides/query-options.mdModified
View file
@@ -5,6 +5,8 @@
​
One of the best ways to share `queryKey` and `queryFn` between multiple places, yet keep them co-located to one another, is to use the `queryOptions` helper. At runtime, this helper just returns whatever you pass into it, but it has a lot of advantages when using it [with TypeScript](../typescript.md#typing-query-options). You can define all possible options for a query in one place, and you'll also get type inference and type safety for all of them.
​
+For framework-agnostic code, `@tanstack/query-core` also exports `queryOptions`, `infiniteQueryOptions`, and `mutationOptions`. They infer query data, page parameters, and mutation variables without depending on a framework, but they only accept the options that every adapter supports. Use the adapter's helpers when you need framework-specific options such as `throwOnError`.
+​
[//]: # 'Example1'
​
```ts
30 additions and 1 deletionpackages/angular-query/src/__tests__/infinite-query-options.test-d.tsModified
View file
@@ -1,4 +1,9 @@
-import { QueryClient, dataTagSymbol, skipToken } from '@tanstack/query-core'
+import {
+ QueryClient,
+ infiniteQueryOptions as coreInfiniteQueryOptions,
+ dataTagSymbol,
+ skipToken,
+} from '@tanstack/query-core'
import { createKey } from '@tanstack/query-test-utils'