@@ -413,10 +413,6 @@ function () {
413
413
this . _watchers = [ ] ;
414
414
this . _destroyed = false ;
415
415
416
- if ( this . vm . $isServer ) {
417
- this . options . fetchPolicy = 'cache-first' ;
418
- }
419
-
420
416
if ( autostart ) {
421
417
this . autostart ( ) ;
422
418
}
@@ -724,14 +720,23 @@ function (_SmartApollo) {
724
720
} ) ;
725
721
}
726
722
727
- _this = _possibleConstructorReturn ( this , _getPrototypeOf ( SmartQuery ) . call ( this , vm , key , options , autostart ) ) ;
723
+ _this = _possibleConstructorReturn ( this , _getPrototypeOf ( SmartQuery ) . call ( this , vm , key , options , false ) ) ;
728
724
729
725
_defineProperty ( _assertThisInitialized ( _assertThisInitialized ( _this ) ) , "type" , 'query' ) ;
730
726
731
727
_defineProperty ( _assertThisInitialized ( _assertThisInitialized ( _this ) ) , "vueApolloSpecialKeys" , VUE_APOLLO_QUERY_KEYWORDS ) ;
732
728
733
729
_defineProperty ( _assertThisInitialized ( _assertThisInitialized ( _this ) ) , "_loading" , false ) ;
734
730
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
+
735
740
if ( ! options . manual ) {
736
741
_this . hasDataField = _this . vm . $data . hasOwnProperty ( key ) ;
737
742
@@ -754,6 +759,10 @@ function (_SmartApollo) {
754
759
}
755
760
}
756
761
762
+ if ( autostart ) {
763
+ _this . autostart ( ) ;
764
+ }
765
+
757
766
return _this ;
758
767
}
759
768
@@ -827,7 +836,12 @@ function (_SmartApollo) {
827
836
_get ( _getPrototypeOf ( SmartQuery . prototype ) , "nextResult" , this ) . call ( this , result ) ;
828
837
829
838
var data = result . data ,
830
- loading = result . loading ;
839
+ loading = result . loading ,
840
+ error = result . error ;
841
+
842
+ if ( error ) {
843
+ this . firstRunReject ( ) ;
844
+ }
831
845
832
846
if ( ! loading ) {
833
847
this . loadingDone ( ) ;
@@ -861,7 +875,8 @@ function (_SmartApollo) {
861
875
value : function catchError ( error ) {
862
876
_get ( _getPrototypeOf ( SmartQuery . prototype ) , "catchError" , this ) . call ( this , error ) ;
863
877
864
- this . loadingDone ( ) ;
878
+ this . firstRunReject ( ) ;
879
+ this . loadingDone ( error ) ;
865
880
this . nextResult ( this . observer . currentResult ( ) ) ; // The observable closes the sub if an error occurs
866
881
867
882
this . resubscribeToQuery ( ) ;
@@ -901,11 +916,17 @@ function (_SmartApollo) {
901
916
} , {
902
917
key : "loadingDone" ,
903
918
value : function loadingDone ( ) {
919
+ var error = arguments . length > 0 && arguments [ 0 ] !== undefined ? arguments [ 0 ] : null ;
920
+
904
921
if ( this . loading ) {
905
922
this . applyLoadingModifier ( - 1 ) ;
906
923
}
907
924
908
925
this . loading = false ;
926
+
927
+ if ( ! error ) {
928
+ this . firstRunResolve ( ) ;
929
+ }
909
930
}
910
931
} , {
911
932
key : "fetchMore" ,
@@ -995,6 +1016,24 @@ function (_SmartApollo) {
995
1016
return ( _this$observer4 = this . observer ) . stopPolling . apply ( _this$observer4 , arguments ) ;
996
1017
}
997
1018
}
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
+ }
998
1037
} , {
999
1038
key : "destroy" ,
1000
1039
value : function destroy ( ) {
@@ -1733,7 +1772,7 @@ function hasProperty(holder, key) {
1733
1772
return typeof holder !== 'undefined' && Object . prototype . hasOwnProperty . call ( holder , key ) ;
1734
1773
}
1735
1774
1736
- function initDollarApollo ( ) {
1775
+ function initProvider ( ) {
1737
1776
var options = this . $options ; // ApolloProvider injection
1738
1777
1739
1778
var optionValue = options . apolloProvider ;
@@ -1797,6 +1836,8 @@ function launch() {
1797
1836
var apollo = this . $options . apollo ;
1798
1837
1799
1838
if ( apollo ) {
1839
+ this . $_apolloPromises = [ ] ;
1840
+
1800
1841
if ( ! apollo . $init ) {
1801
1842
apollo . $init = true ; // Default options applied to `apollo` options
1802
1843
@@ -1824,7 +1865,11 @@ function launch() {
1824
1865
for ( var key in apollo ) {
1825
1866
if ( key . charAt ( 0 ) !== '$' ) {
1826
1867
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
+ }
1828
1873
}
1829
1874
}
1830
1875
@@ -1850,9 +1895,16 @@ function defineReactiveSetter($apollo, key, value, deep) {
1850
1895
}
1851
1896
}
1852
1897
1898
+ function destroy ( ) {
1899
+ if ( this . $_apollo ) {
1900
+ this . $_apollo . destroy ( ) ;
1901
+ this . $_apollo = null ;
1902
+ }
1903
+ }
1904
+
1853
1905
function installMixin ( Vue , vueVersion ) {
1854
1906
Vue . mixin ( _objectSpread ( { } , vueVersion === '1' ? {
1855
- init : initDollarApollo
1907
+ init : initProvider
1856
1908
} : { } , vueVersion === '2' ? {
1857
1909
data : function data ( ) {
1858
1910
return {
@@ -1864,17 +1916,17 @@ function installMixin(Vue, vueVersion) {
1864
1916
} ;
1865
1917
} ,
1866
1918
beforeCreate : function beforeCreate ( ) {
1867
- initDollarApollo . call ( this ) ;
1919
+ initProvider . call ( this ) ;
1868
1920
proxyData . call ( this ) ;
1921
+ } ,
1922
+ serverPrefetch : function serverPrefetch ( ) {
1923
+ if ( this . $_apolloPromises ) {
1924
+ return Promise . all ( this . $_apolloPromises ) ;
1925
+ }
1869
1926
}
1870
1927
} : { } , {
1871
1928
created : launch ,
1872
- destroyed : function destroyed ( ) {
1873
- if ( this . $_apollo ) {
1874
- this . $_apollo . destroy ( ) ;
1875
- this . $_apollo = null ;
1876
- }
1877
- }
1929
+ destroyed : destroy
1878
1930
} ) ) ;
1879
1931
}
1880
1932
@@ -1925,7 +1977,7 @@ function install(Vue, options) {
1925
1977
}
1926
1978
ApolloProvider . install = install ; // eslint-disable-next-line no-undef
1927
1979
1928
- ApolloProvider . version = "3.0.0-beta.27 " ; // Apollo provider
1980
+ ApolloProvider . version = "3.0.0-beta.28 " ; // Apollo provider
1929
1981
1930
1982
var ApolloProvider$1 = ApolloProvider ; // Components
1931
1983
0 commit comments