Subscriptions are no longer run on server + SSR Fixes
This commit is contained in:
Vendored
+35
-24
@@ -2334,7 +2334,7 @@ function reapply(options, context) {
|
||||
return options;
|
||||
}
|
||||
|
||||
var VUE_APOLLO_QUERY_KEYWORDS = ['variables', 'watch', 'update', 'result', 'error', 'loadingKey', 'watchLoading', 'skip', 'throttle', 'debounce', 'subscribeToMore'];
|
||||
var VUE_APOLLO_QUERY_KEYWORDS = ['variables', 'watch', 'update', 'result', 'error', 'loadingKey', 'watchLoading', 'skip', 'throttle', 'debounce', 'subscribeToMore', 'prefetch', 'manual'];
|
||||
|
||||
var _typeof = typeof Symbol === "function" && typeof Symbol.iterator === "symbol" ? function (obj) {
|
||||
return typeof obj;
|
||||
@@ -2530,6 +2530,10 @@ var SmartApollo = function () {
|
||||
}));
|
||||
}
|
||||
|
||||
if (this.vm.$isServer) {
|
||||
this.options.fetchPolicy = 'cache-first';
|
||||
}
|
||||
|
||||
if (autostart) {
|
||||
this.autostart();
|
||||
}
|
||||
@@ -3073,14 +3077,16 @@ var DollarApollo = function () {
|
||||
value: function subscribe(options) {
|
||||
var _this2 = this;
|
||||
|
||||
var observable = this.getClient(options).subscribe(options);
|
||||
var _subscribe = observable.subscribe.bind(observable);
|
||||
observable.subscribe = function (options) {
|
||||
var sub = _subscribe(options);
|
||||
_this2._apolloSubscriptions.push(sub);
|
||||
return sub;
|
||||
};
|
||||
return observable;
|
||||
if (!this.vm.$isServer) {
|
||||
var observable = this.getClient(options).subscribe(options);
|
||||
var _subscribe = observable.subscribe.bind(observable);
|
||||
observable.subscribe = function (options) {
|
||||
var sub = _subscribe(options);
|
||||
_this2._apolloSubscriptions.push(sub);
|
||||
return sub;
|
||||
};
|
||||
return observable;
|
||||
}
|
||||
}
|
||||
}, {
|
||||
key: 'addSmartQuery',
|
||||
@@ -3092,18 +3098,20 @@ var DollarApollo = function () {
|
||||
var smart = this.queries[key] = new SmartQuery(this.vm, key, options, false);
|
||||
smart.autostart();
|
||||
|
||||
var subs = options.subscribeToMore;
|
||||
if (subs) {
|
||||
if (Array.isArray(subs)) {
|
||||
subs.forEach(function (sub, index) {
|
||||
_this3.addSmartSubscription('' + key + index, _extends({}, sub, {
|
||||
if (!this.vm.$isServer) {
|
||||
var subs = options.subscribeToMore;
|
||||
if (subs) {
|
||||
if (Array.isArray(subs)) {
|
||||
subs.forEach(function (sub, index) {
|
||||
_this3.addSmartSubscription('' + key + index, _extends({}, sub, {
|
||||
linkedQuery: smart
|
||||
}));
|
||||
});
|
||||
} else {
|
||||
this.addSmartSubscription(key, _extends({}, subs, {
|
||||
linkedQuery: smart
|
||||
}));
|
||||
});
|
||||
} else {
|
||||
this.addSmartSubscription(key, _extends({}, subs, {
|
||||
linkedQuery: smart
|
||||
}));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -3112,12 +3120,14 @@ var DollarApollo = function () {
|
||||
}, {
|
||||
key: 'addSmartSubscription',
|
||||
value: function addSmartSubscription(key, options) {
|
||||
options = reapply(options, this.vm);
|
||||
if (!this.vm.$isServer) {
|
||||
options = reapply(options, this.vm);
|
||||
|
||||
var smart = this.subscriptions[key] = new SmartSubscription(this.vm, key, options, false);
|
||||
smart.autostart();
|
||||
var smart = this.subscriptions[key] = new SmartSubscription(this.vm, key, options, false);
|
||||
smart.autostart();
|
||||
|
||||
return smart;
|
||||
return smart;
|
||||
}
|
||||
}
|
||||
}, {
|
||||
key: 'defineReactiveSetter',
|
||||
@@ -3351,8 +3361,9 @@ var ApolloProvider$1 = function () {
|
||||
|
||||
// Query
|
||||
return new Promise(function (resolve, reject) {
|
||||
var options = lodash_omit(queryOptions, VUE_APOLLO_QUERY_KEYWORDS);
|
||||
var options = lodash_omit(queryOptions, [].concat(toConsumableArray(VUE_APOLLO_QUERY_KEYWORDS), ['fetchPolicy']));
|
||||
options.variables = variables;
|
||||
options.fetchPolicy = 'network-only';
|
||||
client.query(options).then(resolve, reject);
|
||||
});
|
||||
}
|
||||
|
||||
Vendored
+1
-1
File diff suppressed because one or more lines are too long
Vendored
+35
-24
@@ -2340,7 +2340,7 @@ function reapply(options, context) {
|
||||
return options;
|
||||
}
|
||||
|
||||
var VUE_APOLLO_QUERY_KEYWORDS = ['variables', 'watch', 'update', 'result', 'error', 'loadingKey', 'watchLoading', 'skip', 'throttle', 'debounce', 'subscribeToMore'];
|
||||
var VUE_APOLLO_QUERY_KEYWORDS = ['variables', 'watch', 'update', 'result', 'error', 'loadingKey', 'watchLoading', 'skip', 'throttle', 'debounce', 'subscribeToMore', 'prefetch', 'manual'];
|
||||
|
||||
var _typeof = typeof Symbol === "function" && typeof Symbol.iterator === "symbol" ? function (obj) {
|
||||
return typeof obj;
|
||||
@@ -2536,6 +2536,10 @@ var SmartApollo = function () {
|
||||
}));
|
||||
}
|
||||
|
||||
if (this.vm.$isServer) {
|
||||
this.options.fetchPolicy = 'cache-first';
|
||||
}
|
||||
|
||||
if (autostart) {
|
||||
this.autostart();
|
||||
}
|
||||
@@ -3079,14 +3083,16 @@ var DollarApollo = function () {
|
||||
value: function subscribe(options) {
|
||||
var _this2 = this;
|
||||
|
||||
var observable = this.getClient(options).subscribe(options);
|
||||
var _subscribe = observable.subscribe.bind(observable);
|
||||
observable.subscribe = function (options) {
|
||||
var sub = _subscribe(options);
|
||||
_this2._apolloSubscriptions.push(sub);
|
||||
return sub;
|
||||
};
|
||||
return observable;
|
||||
if (!this.vm.$isServer) {
|
||||
var observable = this.getClient(options).subscribe(options);
|
||||
var _subscribe = observable.subscribe.bind(observable);
|
||||
observable.subscribe = function (options) {
|
||||
var sub = _subscribe(options);
|
||||
_this2._apolloSubscriptions.push(sub);
|
||||
return sub;
|
||||
};
|
||||
return observable;
|
||||
}
|
||||
}
|
||||
}, {
|
||||
key: 'addSmartQuery',
|
||||
@@ -3098,18 +3104,20 @@ var DollarApollo = function () {
|
||||
var smart = this.queries[key] = new SmartQuery(this.vm, key, options, false);
|
||||
smart.autostart();
|
||||
|
||||
var subs = options.subscribeToMore;
|
||||
if (subs) {
|
||||
if (Array.isArray(subs)) {
|
||||
subs.forEach(function (sub, index) {
|
||||
_this3.addSmartSubscription('' + key + index, _extends({}, sub, {
|
||||
if (!this.vm.$isServer) {
|
||||
var subs = options.subscribeToMore;
|
||||
if (subs) {
|
||||
if (Array.isArray(subs)) {
|
||||
subs.forEach(function (sub, index) {
|
||||
_this3.addSmartSubscription('' + key + index, _extends({}, sub, {
|
||||
linkedQuery: smart
|
||||
}));
|
||||
});
|
||||
} else {
|
||||
this.addSmartSubscription(key, _extends({}, subs, {
|
||||
linkedQuery: smart
|
||||
}));
|
||||
});
|
||||
} else {
|
||||
this.addSmartSubscription(key, _extends({}, subs, {
|
||||
linkedQuery: smart
|
||||
}));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -3118,12 +3126,14 @@ var DollarApollo = function () {
|
||||
}, {
|
||||
key: 'addSmartSubscription',
|
||||
value: function addSmartSubscription(key, options) {
|
||||
options = reapply(options, this.vm);
|
||||
if (!this.vm.$isServer) {
|
||||
options = reapply(options, this.vm);
|
||||
|
||||
var smart = this.subscriptions[key] = new SmartSubscription(this.vm, key, options, false);
|
||||
smart.autostart();
|
||||
var smart = this.subscriptions[key] = new SmartSubscription(this.vm, key, options, false);
|
||||
smart.autostart();
|
||||
|
||||
return smart;
|
||||
return smart;
|
||||
}
|
||||
}
|
||||
}, {
|
||||
key: 'defineReactiveSetter',
|
||||
@@ -3357,8 +3367,9 @@ var ApolloProvider$1 = function () {
|
||||
|
||||
// Query
|
||||
return new Promise(function (resolve, reject) {
|
||||
var options = lodash_omit(queryOptions, VUE_APOLLO_QUERY_KEYWORDS);
|
||||
var options = lodash_omit(queryOptions, [].concat(toConsumableArray(VUE_APOLLO_QUERY_KEYWORDS), ['fetchPolicy']));
|
||||
options.variables = variables;
|
||||
options.fetchPolicy = 'network-only';
|
||||
client.query(options).then(resolve, reject);
|
||||
});
|
||||
}
|
||||
|
||||
+1
-1
@@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "vue-apollo",
|
||||
"version": "2.1.0-rc.5",
|
||||
"version": "2.1.0-rc.8",
|
||||
"description": "Vue apollo integration",
|
||||
"main": "dist/vue-apollo.umd.js",
|
||||
"module": "dist/vue-apollo.esm.js",
|
||||
|
||||
@@ -130,8 +130,12 @@ export class ApolloProvider {
|
||||
|
||||
// Query
|
||||
return new Promise((resolve, reject) => {
|
||||
const options = omit(queryOptions, VUE_APOLLO_QUERY_KEYWORDS)
|
||||
const options = omit(queryOptions, [
|
||||
...VUE_APOLLO_QUERY_KEYWORDS,
|
||||
'fetchPolicy',
|
||||
])
|
||||
options.variables = variables
|
||||
options.fetchPolicy = 'network-only'
|
||||
client.query(options).then(resolve, reject)
|
||||
})
|
||||
}
|
||||
|
||||
@@ -10,4 +10,6 @@ export const VUE_APOLLO_QUERY_KEYWORDS = [
|
||||
'throttle',
|
||||
'debounce',
|
||||
'subscribeToMore',
|
||||
'prefetch',
|
||||
'manual',
|
||||
]
|
||||
|
||||
+29
-23
@@ -63,14 +63,16 @@ export class DollarApollo {
|
||||
}
|
||||
|
||||
subscribe (options) {
|
||||
const observable = this.getClient(options).subscribe(options)
|
||||
const _subscribe = observable.subscribe.bind(observable)
|
||||
observable.subscribe = (options) => {
|
||||
let sub = _subscribe(options)
|
||||
this._apolloSubscriptions.push(sub)
|
||||
return sub
|
||||
if (!this.vm.$isServer) {
|
||||
const observable = this.getClient(options).subscribe(options)
|
||||
const _subscribe = observable.subscribe.bind(observable)
|
||||
observable.subscribe = (options) => {
|
||||
let sub = _subscribe(options)
|
||||
this._apolloSubscriptions.push(sub)
|
||||
return sub
|
||||
}
|
||||
return observable
|
||||
}
|
||||
return observable
|
||||
}
|
||||
|
||||
addSmartQuery (key, options) {
|
||||
@@ -79,20 +81,22 @@ export class DollarApollo {
|
||||
const smart = this.queries[key] = new SmartQuery(this.vm, key, options, false)
|
||||
smart.autostart()
|
||||
|
||||
const subs = options.subscribeToMore
|
||||
if (subs) {
|
||||
if (Array.isArray(subs)) {
|
||||
subs.forEach((sub, index) => {
|
||||
this.addSmartSubscription(`${key}${index}`, {
|
||||
...sub,
|
||||
if (!this.vm.$isServer) {
|
||||
const subs = options.subscribeToMore
|
||||
if (subs) {
|
||||
if (Array.isArray(subs)) {
|
||||
subs.forEach((sub, index) => {
|
||||
this.addSmartSubscription(`${key}${index}`, {
|
||||
...sub,
|
||||
linkedQuery: smart,
|
||||
})
|
||||
})
|
||||
} else {
|
||||
this.addSmartSubscription(key, {
|
||||
...subs,
|
||||
linkedQuery: smart,
|
||||
})
|
||||
})
|
||||
} else {
|
||||
this.addSmartSubscription(key, {
|
||||
...subs,
|
||||
linkedQuery: smart,
|
||||
})
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -100,12 +104,14 @@ export class DollarApollo {
|
||||
}
|
||||
|
||||
addSmartSubscription (key, options) {
|
||||
options = reapply(options, this.vm)
|
||||
if (!this.vm.$isServer) {
|
||||
options = reapply(options, this.vm)
|
||||
|
||||
const smart = this.subscriptions[key] = new SmartSubscription(this.vm, key, options, false)
|
||||
smart.autostart()
|
||||
const smart = this.subscriptions[key] = new SmartSubscription(this.vm, key, options, false)
|
||||
smart.autostart()
|
||||
|
||||
return smart
|
||||
return smart
|
||||
}
|
||||
}
|
||||
|
||||
defineReactiveSetter (key, func) {
|
||||
|
||||
@@ -32,6 +32,10 @@ class SmartApollo {
|
||||
}))
|
||||
}
|
||||
|
||||
if (this.vm.$isServer) {
|
||||
this.options.fetchPolicy = 'cache-first'
|
||||
}
|
||||
|
||||
if (autostart) {
|
||||
this.autostart()
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user