Add default query options (#257)

This commit is contained in:
Legenko Roman
2018-05-21 20:43:18 +03:00
committed by Guillaume Chau
parent a9dffa3906
commit 385dec2237
2 changed files with 9 additions and 1 deletions
+4
View File
@@ -1137,6 +1137,10 @@ const apolloProvider = new VueApollo({
defaultOptions: {
// apollo options applied to all components that are using apollo
$loadingKey: 'loading',
// apollo options applied to all queries in components
$query: {
fetchPolicy: 'cache-and-network'
}
},
})
```
+5 -1
View File
@@ -51,6 +51,10 @@ const launch = function launch () {
// watchQuery
for (let key in apollo) {
if (key.charAt(0) !== '$') {
let options = apollo[key]
if(apollo.$query) {
options = Object.assign({}, apollo.$query, options)
}
if (!hasProperty(this, key) && !hasProperty(this.$props, key) && !hasProperty(this.$data, key)) {
Object.defineProperty(this, key, {
get: () => this.$data.$apolloData.data[key],
@@ -58,7 +62,7 @@ const launch = function launch () {
configurable: true,
})
}
this.$apollo.addSmartQuery(key, apollo[key])
this.$apollo.addSmartQuery(key, options)
}
}