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

README.md

15 lines822 Bytes

1# TanStack Svelte 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/lib/services/posts/queries.ts` defines `postsQueries.list()` and `postsQueries.detail(postId)` with `queryOptions`, keyed by `['posts', 'list']` and `['posts', 'detail', postId]`.
8- `src/lib/services/posts/api.ts` sends GraphQL queries with `request` and `gql` from `graphql-request` to the GraphQLZero API.
9- `src/lib/Posts.svelte` and `src/lib/Post.svelte` pass these options to `createQuery`. `src/App.svelte` switches between them based on the selected post id.
10- `src/lib/Posts.svelte` calls `queryClient.getQueryData(postsQueries.detail(post.id).queryKey)` to style links whose detail is already cached.
11​
12To run this example:
13​
14- `npm install`
15- `npm run dev`