0
Fork 0
mirror of https://github.com/TanStack/query.git synced 2026-11-16 22:50:20 +00:00
query/examples/react/basic-graphql-request/README.md
Wonsuk Choi 70441f460d
docs(examples): rewrite the READMEs, add the framework or router to example titles, and rename examples to '<feature>-<framework>' (#12583)
* docs(examples): describe each example in its README with a summary, the framework it is built with, how it works and the npm commands

* docs(examples): add the framework or router to the README heading and page title of examples that have variants

* docs(examples/react): rename the Next.js examples to '<feature>-nextjs-<pages|app>-router'

* docs(examples/react): update package names, docs links and labels, and the lockfile for the renamed Next.js examples

* docs(examples): rename 'svelte/sveltekit', 'solid/solid-start-streaming' and 'angular/router' to '<feature>-<framework>'

* docs(examples): correct README details on staleness, hydration, 'hasMore', streaming and dependent queries, and prefetch on 'focusin' in 'vue/prefetching-nuxt4'
2026-11-12 16:58:15 +09:00

850 B

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.ts defines postsQueries.list() and postsQueries.detail(postId) with queryOptions, keyed under ['posts'].
  • src/services/posts/api.ts sends GraphQL queries to GraphQLZero with request and gql from graphql-request, selecting only id and title for the list.
  • src/index.tsx renders Posts with useQuery(postsQueries.list()) and Post with useQuery(postsQueries.detail(postId)). Both show "Background Updating..." while isFetching is true.
  • In src/index.tsx, the list marks a post as visited when queryClient.getQueryData(postsQueries.detail(post.id).queryKey) returns cached data.

To run this example:

  • npm install
  • npm run dev