diff --git a/plugins/talk-plugin-rich-text/server/config.js b/plugins/talk-plugin-rich-text/server/config.js index bb28dca32..42c6bd756 100644 --- a/plugins/talk-plugin-rich-text/server/config.js +++ b/plugins/talk-plugin-rich-text/server/config.js @@ -11,6 +11,7 @@ const config = { }, }, + // TODO: move to admin eventually // Super strict rules to make sure users only submit the tags they are allowed dompurify: { ALLOWED_TAGS: ['b', 'i', 'blockquote'] }, diff --git a/plugins/talk-plugin-rich-text/server/hooks.js b/plugins/talk-plugin-rich-text/server/hooks.js index f0bbe33ab..2fb9e9a6e 100644 --- a/plugins/talk-plugin-rich-text/server/hooks.js +++ b/plugins/talk-plugin-rich-text/server/hooks.js @@ -4,11 +4,6 @@ const linkify = require('linkifyjs/html'); const config = require('./config'); const inputCleanup = ({ richTextBody }) => { - // richTextBody needs to be present in the request - if (!richTextBody) { - throw new Error('`richTextBody` field not present in the request'); - } - // Let's sanitize the body let cleanInput = DOMPurify.sanitize(richTextBody); @@ -23,17 +18,17 @@ const inputCleanup = ({ richTextBody }) => { module.exports = { RootMutation: { createComment: { - async pre(_, { input }, _context, _info) { + async pre(_, { input }) { // Adding the clean body to the comment.metadata field - input.metadata = merge(get(input, 'metadata'), { + input.metadata = merge(get(input, 'metadata', {}), { richTextBody: inputCleanup(input), }); }, }, editComment: { - async pre(_, { edit }, _context, _info) { - // Adding the clean body to the coment.metadata field - edit.metadata = merge(get(edit, 'metadata'), { + async pre(_, { edit }) { + // Adding the clean body to the comment.metadata field + edit.metadata = merge(get(edit, 'metadata', {}), { richTextBody: inputCleanup(edit), }); }, diff --git a/plugins/talk-plugin-rich-text/server/resolvers.js b/plugins/talk-plugin-rich-text/server/resolvers.js index 4b7ec276e..899ece49a 100644 --- a/plugins/talk-plugin-rich-text/server/resolvers.js +++ b/plugins/talk-plugin-rich-text/server/resolvers.js @@ -1,5 +1,8 @@ +const { get } = require('lodash'); + module.exports = { Comment: { - richTextBody: comment => comment.metadata.richTextBody, + // Get the richTextBody, or send null. + richTextBody: comment => get(comment, 'metadata.richTextBody', null), }, }; diff --git a/plugins/talk-plugin-rich-text/server/typeDefs.graphql b/plugins/talk-plugin-rich-text/server/typeDefs.graphql index 7a60a24c3..afcb016ca 100644 --- a/plugins/talk-plugin-rich-text/server/typeDefs.graphql +++ b/plugins/talk-plugin-rich-text/server/typeDefs.graphql @@ -1,9 +1,9 @@ input CreateCommentInput { - richTextBody: String + richTextBody: String! } input EditCommentInput { - richTextBody: String + richTextBody: String! } type Comment {