Add default query options (#257)
This commit is contained in:
committed by
Guillaume Chau
parent
a9dffa3906
commit
385dec2237
@@ -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
@@ -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)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user