Skip to content

Commit 8cb4515

Browse files
authored
docs: release 2.10.0 (#399)
1 parent 61e2cc4 commit 8cb4515

File tree

2 files changed

+27
-3
lines changed

2 files changed

+27
-3
lines changed

docs/reference/plugins/tanstack-query.mdx

+26-2
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,10 @@ The generated hooks have the following signature convention.
5252
- `args`: Prisma query args. E.g., `{ where: { published: true } }`.
5353
- `options`: tanstack-query options.
5454

55-
The `data` field returned by the hooks call contains the Prisma query result.
55+
The hook function returns a standard TanStack Query [`useQuery`](https://tanstack.com/query/latest/docs/framework/react/reference/useQuery) result, plus an added `queryKey` field.
56+
57+
- The `data` field contains the Prisma query result.
58+
- The `queryKey` field is the query key used to cache the query result. It can be used to manipulate the cache directly or [cancel the query](#query-cancellation).
5659

5760
- **Mutation Hooks**
5861

@@ -64,7 +67,7 @@ The generated hooks have the following signature convention.
6467
- `[Model]`: the name of the model. E.g., "Post".
6568
- `options`: TanStack-Query options.
6669

67-
The `mutate` and `mutateAsync` functions returned with the hooks call take the corresponding Prisma mutation args as input. E.q., `{ data: { title: 'Post1' } }`.
70+
The hook function returns a standard TanStack Query [`useMutation`](https://tanstack.com/query/latest/docs/framework/react/reference/useMutation) result. The `mutate` and `mutateAsync` functions returned take the corresponding Prisma mutation args as input. E.q., `{ data: { title: 'Post1' } }`.
6871

6972
### Context Provider
7073

@@ -679,6 +682,27 @@ will be:
679682
680683
You can use the generated `getQueryKey` function to compute it.
681684
685+
The query hooks also return the query key as part of the result object.
686+
687+
```ts
688+
const { data, queryKey } = useFindUniqueUser({ where: { id: '1' } });
689+
```
690+
691+
### Query Cancellation
692+
693+
You can use TanStack Query's [`queryClient.cancelQueries`](https://tanstack.com/query/latest/docs/reference/QueryClient#queryclientcancelqueries) API to cancel a query. The easiest way to do this is to use the `queryKey` returned by the query hook.
694+
695+
```ts
696+
const queryClient = useQueryClient();
697+
const { queryKey } = useFindUniqueUser({ where: { id: '1' } });
698+
699+
function onCancel() {
700+
queryClient.cancelQueries({ queryKey, exact: true });
701+
}
702+
```
703+
704+
When a cancellation occurs, the query state is reset and the ongoing `fetch` call to the CRUD API is aborted.
705+
682706
## FAQ
683707
684708
### Next.js error "createContext" is not a function

package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -59,5 +59,5 @@
5959
"engines": {
6060
"node": ">=18.0"
6161
},
62-
"packageManager": "pnpm@8.15.8+sha512.d1a029e1a447ad90bc96cd58b0fad486d2993d531856396f7babf2d83eb1823bb83c5a3d0fc18f675b2d10321d49eb161fece36fe8134aa5823ecd215feed392"
62+
"packageManager": "pnpm@9.4.0+sha256.b6fd0bfda555e7e584ad7e56b30c68b01d5a04f9ee93989f4b93ca8473c49c74"
6363
}

0 commit comments

Comments
 (0)