-
Notifications
You must be signed in to change notification settings - Fork 41
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
better comments, doc update, fix for false/0/empty string return valu…
…es on resolvers
- Loading branch information
1 parent
7c50da6
commit 9c6cc6f
Showing
8 changed files
with
236 additions
and
29 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,24 +1,30 @@ | ||
import assert from 'assert'; | ||
|
||
export const createExpressContext = (data, res) => { | ||
data = data || {}; | ||
data.user = data.user || null; | ||
data.models = data.models || {}; | ||
const context = new Context(data); | ||
if (res) { | ||
assert(typeof res.once === 'function', 'createExpressContext takes response as second parameter that implements "res.once"'); | ||
// Bind the response finish event to the context disposal method | ||
res.once('finish', () => context && context.dispose ? context.dispose() : null); | ||
} | ||
return context; | ||
}; | ||
|
||
export class Context { | ||
constructor ({ models, user }) { | ||
this.models = models; | ||
this.user = user; | ||
constructor (data) { | ||
Object.keys(data).forEach(key => { | ||
this[key] = data[key] | ||
}); | ||
} | ||
dispose () { | ||
const models = this.models; | ||
const user = this.user; | ||
this.models = null; | ||
this.user = null; | ||
// Call dispose on every attached model that contains a dispose method | ||
Object.keys(models).forEach((key) => models[key].dispose ? models[key].dispose() : null); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.