fix: uncaught in promise on client-side, closes #572

This commit is contained in:
Guillaume Chau
2019-05-21 17:00:31 +02:00
parent 04891de3a5
commit 359c02f4d2
2 changed files with 13 additions and 9 deletions
+5 -3
View File
@@ -91,9 +91,11 @@ function launch () {
if (key.charAt(0) !== '$') {
let options = apollo[key]
const smart = this.$apollo.addSmartQuery(key, options)
options = reapply(options, this)
if (options.prefetch !== false && apollo.$prefetch !== false && !smart.skip) {
this.$_apolloPromises.push(smart.firstRun)
if (this.$isServer) {
options = reapply(options, this)
if (options.prefetch !== false && apollo.$prefetch !== false && !smart.skip) {
this.$_apolloPromises.push(smart.firstRun)
}
}
}
}
+8 -6
View File
@@ -24,10 +24,12 @@ export default class SmartQuery extends SmartApollo {
super(vm, key, options, false)
this.firstRun = new Promise((resolve, reject) => {
this._firstRunResolve = resolve
this._firstRunReject = reject
})
if (vm.$isServer) {
this.firstRun = new Promise((resolve, reject) => {
this._firstRunResolve = resolve
this._firstRunReject = reject
})
}
if (this.vm.$isServer) {
this.options.fetchPolicy = 'network-only'
@@ -291,9 +293,9 @@ export default class SmartQuery extends SmartApollo {
}
}
firstRunReject () {
firstRunReject (error) {
if (this._firstRunReject) {
this._firstRunReject()
this._firstRunReject(error)
this._firstRunReject = null
}
}