Open History to see the last commit
1# TanStack Vue Query Dependent Queries Example
2β
3A query that waits for another query's result, with `skipToken` as its `queryFn` until the author ID is known.
4β
5## How it works
6β
7- `src/services/posts/queries.ts` defines `postsQueries.list()` and `postsQueries.detail(id)`, `queryOptions` factories keyed by `['posts', 'list']` and `['posts', 'detail', id]`.
8- `src/services/authors/queries.ts` defines `authorsQueries.detail(id)`, which uses `skipToken` as the `queryFn` while `id` is `undefined`.
9- `src/PostDetail.vue` loads the post with `useQuery(() => postsQueries.detail(props.postId))`, derives `authorId` from `post.value?.userId` with `computed`, and passes it to a second `useQuery`. The author query runs only after the post has arrived, and the author name appears next to the title.
10- `src/PostList.vue` reads the list with `useQuery(postsQueries.list())` and marks a post as visited when `queryClient.getQueryData(postsQueries.detail(item.id).queryKey)` returns data.
11β
12To run this example:
13β
14- `npm install`
15- `npm run dev`