examples/lit/basic-graphql-request
| Name | Last commit message | Last commit date |
|---|---|---|
| .. | ||
README.md
TanStack Lit Query Basic GraphQL Request Example#
The basic posts example, fetching from a GraphQL API with graphql-request.
How it works#
src/services/posts/queries.tsdefinespostsQueries.list()andpostsQueries.detail(postId),queryOptionsfactories keyed by['posts', 'list']and['posts', 'detail', postId].src/services/posts/api.tssendsgqlqueries withrequestfromgraphql-requestto the GraphQLZero API.src/post-list.tsandsrc/post-detail.tsread the factories withcreateQueryController.<post-list>callsuseQueryClient().getQueryData(postsQueries.detail(post.id).queryKey)to show posts that are already cached in bold green.src/main.tssubclassesQueryClientProviderto set the sharedQueryClientand switches between the two elements on aset-post-idevent.
To run this example:
npm installnpm run dev