docs: useQuery intro improvements

This commit is contained in:
Guillaume Chau
2019-11-29 16:11:54 +01:00
parent 1e4adf26b4
commit 9aa26a96af
+15 -13
View File
@@ -1,18 +1,6 @@
# Queries
The main composition function used to execute queries is `useQuery`. In your component, start by importing it:
```vue
<script>
import { useQuery } from '@vue/apollo-composable'
export default {
setup () {
// Your data & logic here...
},
}
</script>
```
Fetching data involves executing **queries** using standard GraphQL documents. You can learn more about queries and GraphQL documents [here](https://graphql.org/learn/queries/) and [practice running queries in the playground](https://www.apollographql.com/docs/react/development-testing/developer-tooling/#features).
## Executing a query
@@ -33,6 +21,20 @@ query getUsers {
It's recommended to give a name to your GraphQL operations (here `getUsers`), so it's easier to find them in the Apollo Client devtools.
:::
The main composition function used to execute queries is `useQuery`. In your component, start by importing it:
```vue
<script>
import { useQuery } from '@vue/apollo-composable'
export default {
setup () {
// Your data & logic here...
},
}
</script>
```
You can use `useQuery` in your `setup` option by passing it a GraphQL document as the first parameter and retrieve the query `result`:
```vue{3,7-16}