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
- Apollo Client Setup in Vue 3
- useQuery for Data Fetching
- useMutation for Data Changes
- Real-Time Subscriptions with useSubscription