mirror of
https://github.com/wassname/talk.git
synced 2026-07-21 12:51:03 +08:00
27 lines
758 B
JavaScript
27 lines
758 B
JavaScript
const perspective = require('./perspective');
|
|
const {ErrToxic} = require('./errors');
|
|
const {TOXICITY_THRESHOLD} = require('./constants');
|
|
|
|
module.exports = {
|
|
RootMutation: {
|
|
createComment: {
|
|
async pre(_, {input}, _context, _info) {
|
|
|
|
// Don't call out to perspective when running tests.
|
|
if (process.env.NODE_ENV === 'test') {
|
|
return;
|
|
}
|
|
|
|
const apiKey = require('./apiKey');
|
|
const scores = await perspective.getScores(apiKey, input.body);
|
|
if (input.checkToxicity && scores.SEVERE_TOXICITY.summaryScore > TOXICITY_THRESHOLD) {
|
|
throw ErrToxic;
|
|
}
|
|
input.metadata = Object.assign({}, input.metadata, {
|
|
perspective: scores,
|
|
});
|
|
},
|
|
},
|
|
},
|
|
};
|