Skip to content

Commit 455a5e7

Browse files
author
Guillaume Chau
committed
chore: v3.0.0-beta.28
1 parent 43ff770 commit 455a5e7

File tree

4 files changed

+142
-38
lines changed

4 files changed

+142
-38
lines changed

dist/vue-apollo.esm.js

+70-18
Original file line numberDiff line numberDiff line change
@@ -413,10 +413,6 @@ function () {
413413
this._watchers = [];
414414
this._destroyed = false;
415415

416-
if (this.vm.$isServer) {
417-
this.options.fetchPolicy = 'cache-first';
418-
}
419-
420416
if (autostart) {
421417
this.autostart();
422418
}
@@ -724,14 +720,23 @@ function (_SmartApollo) {
724720
});
725721
}
726722

727-
_this = _possibleConstructorReturn(this, _getPrototypeOf(SmartQuery).call(this, vm, key, options, autostart));
723+
_this = _possibleConstructorReturn(this, _getPrototypeOf(SmartQuery).call(this, vm, key, options, false));
728724

729725
_defineProperty(_assertThisInitialized(_assertThisInitialized(_this)), "type", 'query');
730726

731727
_defineProperty(_assertThisInitialized(_assertThisInitialized(_this)), "vueApolloSpecialKeys", VUE_APOLLO_QUERY_KEYWORDS);
732728

733729
_defineProperty(_assertThisInitialized(_assertThisInitialized(_this)), "_loading", false);
734730

731+
_this.firstRun = new Promise(function (resolve, reject) {
732+
_this._firstRunResolve = resolve;
733+
_this._firstRunReject = reject;
734+
});
735+
736+
if (_this.vm.$isServer) {
737+
_this.options.fetchPolicy = 'network-only';
738+
}
739+
735740
if (!options.manual) {
736741
_this.hasDataField = _this.vm.$data.hasOwnProperty(key);
737742

@@ -754,6 +759,10 @@ function (_SmartApollo) {
754759
}
755760
}
756761

762+
if (autostart) {
763+
_this.autostart();
764+
}
765+
757766
return _this;
758767
}
759768

@@ -827,7 +836,12 @@ function (_SmartApollo) {
827836
_get(_getPrototypeOf(SmartQuery.prototype), "nextResult", this).call(this, result);
828837

829838
var data = result.data,
830-
loading = result.loading;
839+
loading = result.loading,
840+
error = result.error;
841+
842+
if (error) {
843+
this.firstRunReject();
844+
}
831845

832846
if (!loading) {
833847
this.loadingDone();
@@ -861,7 +875,8 @@ function (_SmartApollo) {
861875
value: function catchError(error) {
862876
_get(_getPrototypeOf(SmartQuery.prototype), "catchError", this).call(this, error);
863877

864-
this.loadingDone();
878+
this.firstRunReject();
879+
this.loadingDone(error);
865880
this.nextResult(this.observer.currentResult()); // The observable closes the sub if an error occurs
866881

867882
this.resubscribeToQuery();
@@ -901,11 +916,17 @@ function (_SmartApollo) {
901916
}, {
902917
key: "loadingDone",
903918
value: function loadingDone() {
919+
var error = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : null;
920+
904921
if (this.loading) {
905922
this.applyLoadingModifier(-1);
906923
}
907924

908925
this.loading = false;
926+
927+
if (!error) {
928+
this.firstRunResolve();
929+
}
909930
}
910931
}, {
911932
key: "fetchMore",
@@ -995,6 +1016,24 @@ function (_SmartApollo) {
9951016
return (_this$observer4 = this.observer).stopPolling.apply(_this$observer4, arguments);
9961017
}
9971018
}
1019+
}, {
1020+
key: "firstRunResolve",
1021+
value: function firstRunResolve() {
1022+
if (this._firstRunResolve) {
1023+
this._firstRunResolve();
1024+
1025+
this._firstRunResolve = null;
1026+
}
1027+
}
1028+
}, {
1029+
key: "firstRunReject",
1030+
value: function firstRunReject() {
1031+
if (this._firstRunReject) {
1032+
this._firstRunReject();
1033+
1034+
this._firstRunReject = null;
1035+
}
1036+
}
9981037
}, {
9991038
key: "destroy",
10001039
value: function destroy() {
@@ -1733,7 +1772,7 @@ function hasProperty(holder, key) {
17331772
return typeof holder !== 'undefined' && Object.prototype.hasOwnProperty.call(holder, key);
17341773
}
17351774

1736-
function initDollarApollo() {
1775+
function initProvider() {
17371776
var options = this.$options; // ApolloProvider injection
17381777

17391778
var optionValue = options.apolloProvider;
@@ -1797,6 +1836,8 @@ function launch() {
17971836
var apollo = this.$options.apollo;
17981837

17991838
if (apollo) {
1839+
this.$_apolloPromises = [];
1840+
18001841
if (!apollo.$init) {
18011842
apollo.$init = true; // Default options applied to `apollo` options
18021843

@@ -1824,7 +1865,11 @@ function launch() {
18241865
for (var key in apollo) {
18251866
if (key.charAt(0) !== '$') {
18261867
var options = apollo[key];
1827-
this.$apollo.addSmartQuery(key, options);
1868+
var smart = this.$apollo.addSmartQuery(key, options);
1869+
1870+
if (options.prefetch !== false && apollo.$prefetch !== false) {
1871+
this.$_apolloPromises.push(smart.firstRun);
1872+
}
18281873
}
18291874
}
18301875

@@ -1850,9 +1895,16 @@ function defineReactiveSetter($apollo, key, value, deep) {
18501895
}
18511896
}
18521897

1898+
function destroy() {
1899+
if (this.$_apollo) {
1900+
this.$_apollo.destroy();
1901+
this.$_apollo = null;
1902+
}
1903+
}
1904+
18531905
function installMixin(Vue, vueVersion) {
18541906
Vue.mixin(_objectSpread({}, vueVersion === '1' ? {
1855-
init: initDollarApollo
1907+
init: initProvider
18561908
} : {}, vueVersion === '2' ? {
18571909
data: function data() {
18581910
return {
@@ -1864,17 +1916,17 @@ function installMixin(Vue, vueVersion) {
18641916
};
18651917
},
18661918
beforeCreate: function beforeCreate() {
1867-
initDollarApollo.call(this);
1919+
initProvider.call(this);
18681920
proxyData.call(this);
1921+
},
1922+
serverPrefetch: function serverPrefetch() {
1923+
if (this.$_apolloPromises) {
1924+
return Promise.all(this.$_apolloPromises);
1925+
}
18691926
}
18701927
} : {}, {
18711928
created: launch,
1872-
destroyed: function destroyed() {
1873-
if (this.$_apollo) {
1874-
this.$_apollo.destroy();
1875-
this.$_apollo = null;
1876-
}
1877-
}
1929+
destroyed: destroy
18781930
}));
18791931
}
18801932

@@ -1925,7 +1977,7 @@ function install(Vue, options) {
19251977
}
19261978
ApolloProvider.install = install; // eslint-disable-next-line no-undef
19271979

1928-
ApolloProvider.version = "3.0.0-beta.27"; // Apollo provider
1980+
ApolloProvider.version = "3.0.0-beta.28"; // Apollo provider
19291981

19301982
var ApolloProvider$1 = ApolloProvider; // Components
19311983

0 commit comments

Comments
 (0)