0Pricing
Vue Academy · Lesson

useQuery for Data Fetching

useQuery(QUERY), result, loading, error, variables, fetchPolicy options.

Querying With useQuery

The useQuery composable runs a GraphQL query and returns reactive state. It automatically refetches when variables change and updates when the cache changes.

Basic Usage

Pass a gql document. useQuery returns result, loading, and error refs.

import { useQuery } from '@vue/apollo-composable'
import { gql } from '@apollo/client/core'

const { result, loading, error } = useQuery(gql(
  'query { posts { id title } }'
))

All lessons in this course

  1. Apollo Client Setup in Vue 3
  2. useQuery for Data Fetching
  3. useMutation for Data Changes
  4. Real-Time Subscriptions with useSubscription
← Back to Vue Academy