Open History to see the last commit
TanStack React 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)withqueryOptions, keyed under['posts'].src/services/posts/api.tssends GraphQL queries to GraphQLZero withrequestandgqlfromgraphql-request, selecting onlyidandtitlefor the list.src/index.tsxrendersPostswithuseQuery(postsQueries.list())andPostwithuseQuery(postsQueries.detail(postId)). Both show "Background Updating..." whileisFetchingistrue.- In
src/index.tsx, the list marks a post as visited whenqueryClient.getQueryData(postsQueries.detail(post.id).queryKey)returns cached data.
To run this example:
npm installnpm run dev