Resolves edge case with old digest frequency

This commit is contained in:
Wyatt Johnson
2018-03-07 14:22:24 -07:00
parent e72622e913
commit 48b5afafab
2 changed files with 49 additions and 9 deletions
@@ -0,0 +1,37 @@
const { isValidJSValue } = require('graphql');
module.exports = {
NotificationSettings: {
digestFrequency: {
// This hook will swap out the digest frequency with `NONE` in the event
// that an org had a digest plugin enabled and later switched it off. This
// will force users that have previously had a digested option enabled to
// get notifications immediately until they update their frequency
// options.
post: async (settings, args, ctx, { schema }, frequency) => {
try {
// Validate that the type is correct.
const errors = isValidJSValue(
frequency,
schema.getType('DIGEST_FREQUENCY')
);
if (errors && errors.length > 0) {
ctx.log.info(
{ frequency },
'invalid frequency, swapping with `NONE`, plugin likely disabled'
);
// Fallback to 'NONE' if the digest value has an error.
frequency = 'NONE';
}
} catch (err) {
ctx.log.error({ err }, 'could not check if the type was valid');
// Fallback to 'NONE' if we couldn't validate the value.
frequency = 'NONE';
}
return frequency;
},
},
},
};
@@ -1,16 +1,19 @@
const path = require('path');
const connect = require('./connect');
const typeDefs = require('./typeDefs');
const resolvers = require('./resolvers');
const router = require('./router');
const mutators = require('./mutators');
const translations = path.join(__dirname, 'translations.yml');
const connect = require('./connect');
const hooks = require('./hooks');
const mutators = require('./mutators');
const resolvers = require('./resolvers');
const router = require('./router');
const typeDefs = require('./typeDefs');
module.exports = {
connect,
hooks,
mutators,
resolvers,
router,
translations,
typeDefs,
resolvers,
mutators,
connect,
router,
};