diff --git a/graph/hooks.js b/graph/hooks.js index 499eb60b1..c5b7541b3 100644 --- a/graph/hooks.js +++ b/graph/hooks.js @@ -3,6 +3,7 @@ const { GraphQLInterfaceType } = require('graphql'); const debug = require('debug')('talk:graph:schema'); +const Joi = require('joi'); /** * XXX taken from graphql-js: src/execution/execute.js, because that function @@ -82,6 +83,8 @@ const decorateWithHooks = (schema, hooks) => forEachField(schema, (field, typeNa Object.keys(hooks).forEach((hook) => { switch (hook) { case 'pre': + Joi.assert(hooks.pre, Joi.func().maxArity(4)); + debug(`adding pre hook to resolver ${typeName}.${fieldName} from plugin '${plugin.name}'`); if (typeof hooks.pre !== 'function') { @@ -91,6 +94,8 @@ const decorateWithHooks = (schema, hooks) => forEachField(schema, (field, typeNa acc.pre.push(hooks.pre); break; case 'post': + Joi.assert(hooks.pre, Joi.func().maxArity(5)); + debug(`adding post hook to resolver ${typeName}.${fieldName} from plugin '${plugin.name}'`); if (typeof hooks.post !== 'function') { @@ -129,6 +134,9 @@ const decorateWithHooks = (schema, hooks) => forEachField(schema, (field, typeNa return; } + // Ensure it matches the format we expect. + Joi.assert(post, Joi.array().items(Joi.func().maxArity(3)), `invalid post hooks were found for ${typeName}.${fieldName}`); + // Cache the original resolverType function. let resolveType = field.resolveType; diff --git a/services/metadata.js b/services/metadata.js index a0c433f8b..2cabed8b8 100644 --- a/services/metadata.js +++ b/services/metadata.js @@ -72,7 +72,7 @@ class MetadataService { key = MetadataService.parseKey(key); return model.update({id}, { - $unset: key + $unset: {[key]: ''} }); } }