Skip to content

Commit 64c1a3a

Browse files
author
Guillaume Chau
committed
Expose addSmartQuery/Subscription in API
1 parent 2f7e739 commit 64c1a3a

File tree

3 files changed

+37
-5
lines changed

3 files changed

+37
-5
lines changed

README.md

Lines changed: 31 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,11 +29,13 @@ Integrates [apollo](http://www.apollostack.com/) in your [Vue](http://vuejs.org)
2929
- [Skipping the query](#skipping-the-query)
3030
- [Advanced options](#advanced-options)
3131
- [Reactive Query Example](#reactive-query-example)
32+
- [Manually adding a smart Query](#manually-adding-a-smart-query)
3233
- [Mutations](#mutations)
3334
- [Subscriptions](#subscriptions)
3435
- [subscribeToMore](#subscribetomore)
3536
- [subscribe](#subscribe)
3637
- [Skipping the subscription](#skipping-the-subscription)
38+
- [Manually adding a smart Subscription](#manually-adding-a-smart-subscription)
3739
- [Pagination with `fetchMore`](#pagination-with-fetchmore)
3840
- [Skip all](#skip-all)
3941
- [Multiple clients](#multiple-clients)
@@ -527,6 +529,20 @@ export const resolvers = {
527529
}
528530
```
529531

532+
### Manually adding a smart Query
533+
534+
You can manually add a smart query with the `$apollo.addSmartQuery(key, options)` method:
535+
536+
```javascript
537+
created () {
538+
this.$apollo.addSmartQuery('comments', {
539+
// Same options like above
540+
})
541+
}
542+
```
543+
544+
*Internally, this method is called for each query entry in the component `apollo` option.*
545+
530546
## Mutations
531547

532548
Mutations are queries that changes your data state on your apollo server. For more info, visit the [apollo doc](http://dev.apollodata.com/core/apollo-client-api.html#ApolloClient\.mutate).
@@ -814,7 +830,7 @@ apollo: {
814830
// Subscriptions
815831
$subscribe: {
816832
// When a tag is added
817-
tags: {
833+
tagAdded: {
818834
query: gql`subscription tags($type: String!) {
819835
tagAdded(type: $type) {
820836
id
@@ -890,6 +906,20 @@ You can also access the subscription directly and set the `skip` property:
890906
this.$apollo.subscriptions.tags.skip = true
891907
```
892908

909+
### Manually adding a smart Subscription
910+
911+
You can manually add a smart subscription with the `$apollo.addSmartSubscription(key, options)` method:
912+
913+
```javascript
914+
created () {
915+
this.$apollo.addSmartSubscription('tagAdded', {
916+
// Same options like '$subscribe' above
917+
})
918+
}
919+
```
920+
921+
*Internally, this method is called for each entry of the `$subscribe` object in the component `apollo` option.*
922+
893923
## Pagination with `fetchMore`
894924

895925
*[Here](https://github.com/Akryum/apollo-server-example/blob/master/schema.js#L21) is a simple example for the server.*

src/dollar-apollo.js

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -95,14 +95,16 @@ export class DollarApollo {
9595
return observable
9696
}
9797

98-
option (key, options) {
98+
addSmartQuery (key, options) {
9999
const smart = this.queries[key] = new SmartQuery(this.vm, key, options, false)
100100
smart.autostart()
101+
return smart
101102
}
102103

103-
subscribeOption (key, options) {
104+
addSmartSubscription (key, options) {
104105
const smart = this.subscriptions[key] = new SmartSubscription(this.vm, key, options, false)
105106
smart.autostart()
107+
return smart
106108
}
107109

108110
defineReactiveSetter (key, func) {

src/index.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ const launch = function launch () {
3939
if (this._apolloQueries) {
4040
// watchQuery
4141
for (let key in this._apolloQueries) {
42-
this.$apollo.option(key, this._apolloQueries[key])
42+
this.$apollo.addSmartQuery(key, this._apolloQueries[key])
4343
}
4444
}
4545

@@ -51,7 +51,7 @@ const launch = function launch () {
5151

5252
if (apollo.$subscribe) {
5353
for (let key in apollo.$subscribe) {
54-
this.$apollo.subscribeOption(key, apollo.$subscribe[key])
54+
this.$apollo.addSmartSubscription(key, apollo.$subscribe[key])
5555
}
5656
}
5757

0 commit comments

Comments
 (0)