Open History to see the last commit
1# TanStack Preact 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)`, `queryOptions` factories keyed by `['posts', 'list']` and `['posts', 'detail', postId]`.
8- `src/services/posts/api.ts` sends `gql` queries with `request` from `graphql-request` to the GraphQLZero API.
9- In `src/index.tsx`, `Posts` and `Post` pass the factories to `useQuery`. `Posts` calls `queryClient.getQueryData(postsQueries.detail(post.id).queryKey)` to show posts that are already cached in bold green.
10β
11To run this example:
12β
13- `npm install`
14- `npm run dev`