Skip to content
Source
Sign inSign up
TanStack/query
Open History to see the last commit

README.md

15 lines971 Bytes

1# TanStack Vue Query Basic GraphQL Request Example
2​
3The basic posts example, fetching from a GraphQL API with `graphql-request`.
4​
5## How it works
6​
7- `src/services/posts/api.ts` sends GraphQL queries with `request` and `gql` from `graphql-request`: the list asks only for `id` and `title`, and the detail asks for `body` as well.
8- `src/services/posts/queries.ts` wraps those calls in `postsQueries.list()` and `postsQueries.detail(postId)`, `queryOptions` factories keyed by `['posts', 'list']` and `['posts', 'detail', postId]`.
9- `src/PostList.vue` reads the list with `useQuery(postsQueries.list())` and shows a post in bold green when `queryClient.getQueryData(postsQueries.detail(post.id).queryKey)` returns data.
10- `src/PostDetail.vue` passes a getter, `useQuery(() => postsQueries.detail(props.postId))`, so the query follows the `postId` prop and shows "Background Updating..." while `isFetching` is `true`.
11​
12To run this example:
13​
14- `npm install`
15- `npm run dev`