Open History to see the last commit
1# TanStack React 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/queries.ts` defines `postsQueries.list()` and `postsQueries.detail(postId)` with `queryOptions`, keyed under `['posts']`.
8- `src/services/posts/api.ts` sends GraphQL queries to GraphQLZero with `request` and `gql` from `graphql-request`, selecting only `id` and `title` for the list.
9- `src/index.tsx` renders `Posts` with `useQuery(postsQueries.list())` and `Post` with `useQuery(postsQueries.detail(postId))`. Both show "Background Updating..." while `isFetching` is `true`.
10- In `src/index.tsx`, the list marks a post as visited when `queryClient.getQueryData(postsQueries.detail(post.id).queryKey)` returns cached data.
11β
12To run this example:
13β
14- `npm install`
15- `npm run dev`