Skip to content

Commit

Permalink
fix: uncaught in promise on client-side, closes #572
Browse files Browse the repository at this point in the history
  • Loading branch information
Guillaume Chau committed May 21, 2019
1 parent 04891de commit 359c02f
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 9 deletions.
8 changes: 5 additions & 3 deletions src/mixin.js
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
}
}
}
Expand Down
14 changes: 8 additions & 6 deletions src/smart-query.js
Original file line number Diff line number Diff line change
Expand Up @@ -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'
Expand Down Expand Up @@ -291,9 +293,9 @@ export default class SmartQuery extends SmartApollo {
}
}

firstRunReject () {
firstRunReject (error) {
if (this._firstRunReject) {
this._firstRunReject()
this._firstRunReject(error)
this._firstRunReject = null
}
}
Expand Down

0 comments on commit 359c02f

Please sign in to comment.