Skip to content

Commit 385dec2

Browse files
uNScopeAkryum
authored andcommitted
Add default query options (#257)
1 parent a9dffa3 commit 385dec2

File tree

2 files changed

+9
-1
lines changed

2 files changed

+9
-1
lines changed

README.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1137,6 +1137,10 @@ const apolloProvider = new VueApollo({
11371137
defaultOptions: {
11381138
// apollo options applied to all components that are using apollo
11391139
$loadingKey: 'loading',
1140+
// apollo options applied to all queries in components
1141+
$query: {
1142+
fetchPolicy: 'cache-and-network'
1143+
}
11401144
},
11411145
})
11421146
```

src/index.js

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,14 +51,18 @@ const launch = function launch () {
5151
// watchQuery
5252
for (let key in apollo) {
5353
if (key.charAt(0) !== '$') {
54+
let options = apollo[key]
55+
if(apollo.$query) {
56+
options = Object.assign({}, apollo.$query, options)
57+
}
5458
if (!hasProperty(this, key) && !hasProperty(this.$props, key) && !hasProperty(this.$data, key)) {
5559
Object.defineProperty(this, key, {
5660
get: () => this.$data.$apolloData.data[key],
5761
enumerable: true,
5862
configurable: true,
5963
})
6064
}
61-
this.$apollo.addSmartQuery(key, apollo[key])
65+
this.$apollo.addSmartQuery(key, options)
6266
}
6367
}
6468

0 commit comments

Comments
 (0)