diff --git a/src/graphql/models/Article.js b/src/graphql/models/Article.js index ac3b01ce..ccd99d76 100644 --- a/src/graphql/models/Article.js +++ b/src/graphql/models/Article.js @@ -368,6 +368,8 @@ const Article = new GraphQLObjectType({ type: GraphQLString, description: 'Attachment of this article', async resolve({ attachmentHash }) { + if (!attachmentHash) return null; + const info = await mediaManager.getInfo(attachmentHash); return info.url; }, diff --git a/src/graphql/mutations/CreateOrUpdateArticleReplyFeedback.js b/src/graphql/mutations/CreateOrUpdateArticleReplyFeedback.js index 1949c1ba..4b41949e 100644 --- a/src/graphql/mutations/CreateOrUpdateArticleReplyFeedback.js +++ b/src/graphql/mutations/CreateOrUpdateArticleReplyFeedback.js @@ -146,17 +146,22 @@ export default { // Fill in reply & article reply author ID // - const { userId: replyUserId } = await loaders.docLoader.load({ - index: 'replies', - id: replyId, - }); + const [ + { userId: replyUserId }, + article, + ] = await loaders.docLoader.loadMany([ + { + index: 'replies', + id: replyId, + }, + { + index: 'articles', + id: articleId, + }, + ]); - const article = await loaders.docLoader.load({ - index: 'articles', - id: articleId, - }); const { userId: articleReplyUserId } = article.articleReplies.find( - ar => (ar.replyId = replyId) + ar => ar.replyId === replyId ); await client.update({ diff --git a/src/graphql/mutations/__fixtures__/CreateOrUpdateArticleReplyFeedback.js b/src/graphql/mutations/__fixtures__/CreateOrUpdateArticleReplyFeedback.js index e8d995d8..c0d5decd 100644 --- a/src/graphql/mutations/__fixtures__/CreateOrUpdateArticleReplyFeedback.js +++ b/src/graphql/mutations/__fixtures__/CreateOrUpdateArticleReplyFeedback.js @@ -9,6 +9,12 @@ function generateEntry(data) { export default { '/articles/doc/article1': { articleReplies: [ + { + replyId: 'reply2', + userId: 'another articleReply user ID', + positiveFeedbackCount: 0, + negativeFeedbackCount: 0, + }, { replyId: 'reply1', userId: 'articleReply user ID', diff --git a/src/graphql/mutations/__tests__/CreateOrUpdateArticleReplyFeedback.js b/src/graphql/mutations/__tests__/CreateOrUpdateArticleReplyFeedback.js index f8117090..87a9e0ce 100644 --- a/src/graphql/mutations/__tests__/CreateOrUpdateArticleReplyFeedback.js +++ b/src/graphql/mutations/__tests__/CreateOrUpdateArticleReplyFeedback.js @@ -86,6 +86,12 @@ describe('CreateOrUpdateArticleReplyFeedback', () => { }); expect(article._source.articleReplies).toMatchInlineSnapshot(` Array [ + Object { + "negativeFeedbackCount": 0, + "positiveFeedbackCount": 0, + "replyId": "reply2", + "userId": "another articleReply user ID", + }, Object { "negativeFeedbackCount": 0, "positiveFeedbackCount": 12, @@ -247,6 +253,12 @@ describe('CreateOrUpdateArticleReplyFeedback', () => { }); expect(article._source.articleReplies).toMatchInlineSnapshot(` Array [ + Object { + "negativeFeedbackCount": 0, + "positiveFeedbackCount": 0, + "replyId": "reply2", + "userId": "another articleReply user ID", + }, Object { "negativeFeedbackCount": 0, "positiveFeedbackCount": 11, diff --git a/src/graphql/queries/__tests__/GetReplyAndGetArticle.js b/src/graphql/queries/__tests__/GetReplyAndGetArticle.js index 1aa19a46..619c5d86 100644 --- a/src/graphql/queries/__tests__/GetReplyAndGetArticle.js +++ b/src/graphql/queries/__tests__/GetReplyAndGetArticle.js @@ -44,6 +44,8 @@ describe('GetReplyAndGetArticle', () => { } } requestedForReply + attachmentHash + attachmentUrl } } `({}, { user: { id: 'fakeUser', appId: 'LINE' } }) diff --git a/src/graphql/queries/__tests__/__snapshots__/GetReplyAndGetArticle.js.snap b/src/graphql/queries/__tests__/__snapshots__/GetReplyAndGetArticle.js.snap index 5ff7b0ef..480e4b24 100644 --- a/src/graphql/queries/__tests__/__snapshots__/GetReplyAndGetArticle.js.snap +++ b/src/graphql/queries/__tests__/__snapshots__/GetReplyAndGetArticle.js.snap @@ -280,6 +280,8 @@ Object { "updatedAt": "2015-01-02T12:10:30Z", }, ], + "attachmentHash": null, + "attachmentUrl": null, "references": Array [ Object { "type": "LINE",