Skip to content

Commit 1f15d60

Browse files
mitarAkryum
authored andcommitted
docs: Explain that simple subscriptions can be used for live queries. (#861)
When server supports that.
1 parent 708ce8d commit 1f15d60

File tree

1 file changed

+28
-1
lines changed

1 file changed

+28
-1
lines changed

packages/docs/src/guide/apollo/subscriptions.md

Lines changed: 28 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -174,7 +174,7 @@ this.$watch(() => this.type, (type, oldType) => {
174174

175175
::: danger
176176
If you want to update a query with the result of the subscription, use `subscribeToMore`.
177-
The methods below are suitable for a 'notify' use case
177+
The methods below are suitable for a 'notify' use case.
178178
:::
179179

180180
You can declare [Smart Subscriptions](../../api/smart-subscription.md) in the `apollo` option with the `$subscribe` keyword:
@@ -217,6 +217,33 @@ You can then access the subscription with `this.$apollo.subscriptions.<name>`.
217217
Just like for queries, you can declare the subscription [with a function](./queries.md#option-function), and you can declare the `query` option [with a reactive function](./queries.md#reactive-query-definition).
218218
:::
219219

220+
When server supports live queries and uses subscriptions to update them, like [Hasura](https://hasura.io/), you can
221+
use simple subscriptions for reactive queries:
222+
223+
```js
224+
data () {
225+
return {
226+
tags: [],
227+
};
228+
},
229+
apollo: {
230+
$subscribe: {
231+
tags: {
232+
query: gql`subscription {
233+
tags {
234+
id
235+
label
236+
type
237+
}
238+
}`,
239+
result ({ data }) {
240+
this.tags = data.tags;
241+
},
242+
},
243+
},
244+
},
245+
```
246+
220247
## Skipping the subscription
221248

222249
If the subscription is skipped, it will disable it and it will not be updated anymore. You can use the `skip` option:

0 commit comments

Comments
 (0)