Merge branch 'notification-digests' of ssh://github.com/coralproject/talk into notification-digests

This commit is contained in:
Chi Vinh Le
2018-03-08 14:37:24 +01:00
3 changed files with 50 additions and 9 deletions
+1
View File
@@ -18,5 +18,6 @@ ONBUILD COPY . /usr/src/app
# clear out the development dependencies again. After this we of course need to
# clear out the yarn cache, this saves quite a lot of size.
ONBUILD RUN cli plugins reconcile && \
yarn && \
yarn build && \
yarn cache clean
@@ -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,
};