diff --git a/README.md b/README.md index 557542ce..18c89baa 100644 --- a/README.md +++ b/README.md @@ -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' + } }, }) ``` diff --git a/src/index.js b/src/index.js index b1e27fa4..fd60f44d 100644 --- a/src/index.js +++ b/src/index.js @@ -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) } }