Open History to see the last commit
TanStack Svelte Query Basic GraphQL Request Example#
The basic posts example, fetching from a GraphQL API with graphql-request.
How it works#
src/lib/services/posts/queries.tsdefinespostsQueries.list()andpostsQueries.detail(postId)withqueryOptions, keyed by['posts', 'list']and['posts', 'detail', postId].src/lib/services/posts/api.tssends GraphQL queries withrequestandgqlfromgraphql-requestto the GraphQLZero API.src/lib/Posts.svelteandsrc/lib/Post.sveltepass these options tocreateQuery.src/App.svelteswitches between them based on the selected post id.src/lib/Posts.sveltecallsqueryClient.getQueryData(postsQueries.detail(post.id).queryKey)to style links whose detail is already cached.
To run this example:
npm installnpm run dev