Skip to content

Commit

Permalink
fix(watch): handle errors during watchSchema (#624)
Browse files Browse the repository at this point in the history
  • Loading branch information
benjie committed May 12, 2020
1 parent 314d69e commit 4ef1b7b
Showing 1 changed file with 23 additions and 11 deletions.
34 changes: 23 additions & 11 deletions packages/graphile-build/src/SchemaBuilder.js
Expand Up @@ -535,20 +535,32 @@ class SchemaBuilder extends EventEmitter {
console.error(e);
}
};
for (const fn of this.watchers) {
await fn(this.triggerChange);
}
try {
this._watching = true;
for (const fn of this.watchers) {
await fn(this.triggerChange);
}
// Now we're about to build the first schema, any further `triggerChange`
// calls should be honoured.
ignoreChangeTriggers = false;
// Now we're about to build the first schema, any further
// `triggerChange` calls should be honoured.
ignoreChangeTriggers = false;
if (listener) {
this.on("schema", listener);
if (listener) {
this.on("schema", listener);
}
this.emit("schema", this.buildSchema());
} catch (e) {
try {
this._busy = false;
// Abort abort!
await this.unwatchSchema();
} catch (e2) {
console.error(
`Error when unwatching schema after error during schema build: ${e}`
);
}
throw e;
}
this.emit("schema", this.buildSchema());

this._watching = true;
} finally {
this._busy = false;
}
Expand Down

0 comments on commit 4ef1b7b

Please sign in to comment.