examples/vue/basic-graphql-request
| Name | Last commit message | Last commit date |
|---|---|---|
| .. | ||
README.md
TanStack Vue Query Basic GraphQL Request Example#
The basic posts example, fetching from a GraphQL API with graphql-request.
How it works#
src/services/posts/api.tssends GraphQL queries withrequestandgqlfromgraphql-request: the list asks only foridandtitle, and the detail asks forbodyas well.src/services/posts/queries.tswraps those calls inpostsQueries.list()andpostsQueries.detail(postId),queryOptionsfactories keyed by['posts', 'list']and['posts', 'detail', postId].src/PostList.vuereads the list withuseQuery(postsQueries.list())and shows a post in bold green whenqueryClient.getQueryData(postsQueries.detail(post.id).queryKey)returns data.src/PostDetail.vuepasses a getter,useQuery(() => postsQueries.detail(props.postId)), so the query follows thepostIdprop and shows "Background Updating..." whileisFetchingistrue.
To run this example:
npm installnpm run dev