diff --git a/backend/src/schema/resolvers/comments.js b/backend/src/schema/resolvers/comments.js index d2e296596..7aef63c59 100644 --- a/backend/src/schema/resolvers/comments.js +++ b/backend/src/schema/resolvers/comments.js @@ -18,9 +18,6 @@ export default { if (!params.content || content.length < COMMENT_MIN_LENGTH) { throw new UserInputError(`Comment must be at least ${COMMENT_MIN_LENGTH} character long!`) } - if (!postId.trim()) { - throw new UserInputError(NO_POST_ERR_MESSAGE) - } const session = context.driver.session() const postQueryRes = await session.run( diff --git a/backend/src/schema/resolvers/comments.spec.js b/backend/src/schema/resolvers/comments.spec.js index 55b946bb9..07462ed49 100644 --- a/backend/src/schema/resolvers/comments.spec.js +++ b/backend/src/schema/resolvers/comments.spec.js @@ -23,7 +23,7 @@ afterEach(async () => { describe('CreateComment', () => { const createCommentMutation = gql` - mutation($postId: ID, $content: String!) { + mutation($postId: ID!, $content: String!) { CreateComment(postId: $postId, content: $content) { id content @@ -37,13 +37,6 @@ describe('CreateComment', () => { } } ` - const commentQueryForPostId = gql` - query($content: String) { - Comment(content: $content) { - postId - } - } - ` describe('unauthenticated', () => { it('throws authorization error', async () => { createCommentVariables = { @@ -191,23 +184,6 @@ describe('CreateComment', () => { client.request(createCommentMutation, createCommentVariablesWithNonExistentPost), ).rejects.toThrow('Comment cannot be created without a post!') }) - - it('does not create the comment with the postId as an attribute', async () => { - const commentQueryVariablesByContent = { - content: "I'm authorised to comment", - } - - await client.request(createCommentMutation, createCommentVariables) - const { Comment } = await client.request( - commentQueryForPostId, - commentQueryVariablesByContent, - ) - expect(Comment).toEqual([ - { - postId: null, - }, - ]) - }) }) }) diff --git a/backend/src/schema/types/type/Comment.gql b/backend/src/schema/types/type/Comment.gql index 077366e8a..e11623453 100644 --- a/backend/src/schema/types/type/Comment.gql +++ b/backend/src/schema/types/type/Comment.gql @@ -1,7 +1,6 @@ type Comment { id: ID! activityId: String - postId: ID author: User @relation(name: "WROTE", direction: "IN") content: String! contentExcerpt: String @@ -11,4 +10,25 @@ type Comment { deleted: Boolean disabled: Boolean disabledBy: User @relation(name: "DISABLED", direction: "IN") -} \ No newline at end of file +} + +type Mutation { + CreateComment( + id: ID + postId: ID! + content: String! + contentExcerpt: String + deleted: Boolean + disabled: Boolean + ): Comment + UpdateComment( + id: ID! + content: String + contentExcerpt: String + deleted: Boolean + disabled: Boolean + ): Comment + DeleteComment( + id: ID! + ): Comment +} diff --git a/backend/src/seed/factories/comments.js b/backend/src/seed/factories/comments.js index b1079e392..20933e947 100644 --- a/backend/src/seed/factories/comments.js +++ b/backend/src/seed/factories/comments.js @@ -10,7 +10,7 @@ export default function(params) { return { mutation: ` - mutation($id: ID!, $postId: ID, $content: String!) { + mutation($id: ID!, $postId: ID!, $content: String!) { CreateComment(id: $id, postId: $postId, content: $content) { id } diff --git a/webapp/graphql/CommentMutations.js b/webapp/graphql/CommentMutations.js index efaf6cd49..f94ea7ac9 100644 --- a/webapp/graphql/CommentMutations.js +++ b/webapp/graphql/CommentMutations.js @@ -3,7 +3,7 @@ import gql from 'graphql-tag' export default () => { return { CreateComment: gql` - mutation($postId: ID, $content: String!) { + mutation($postId: ID!, $content: String!) { CreateComment(postId: $postId, content: $content) { id contentExcerpt