Explicitly define all comment mutations in schema

Remove `postId` as part of the to-be-saved comment type.
This commit is contained in:
Robert Schäfer 2019-07-02 15:05:42 +02:00
parent cbc8fc8d83
commit 0bc1444336
5 changed files with 25 additions and 32 deletions

View File

@ -18,9 +18,6 @@ export default {
if (!params.content || content.length < COMMENT_MIN_LENGTH) { if (!params.content || content.length < COMMENT_MIN_LENGTH) {
throw new UserInputError(`Comment must be at least ${COMMENT_MIN_LENGTH} character long!`) 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 session = context.driver.session()
const postQueryRes = await session.run( const postQueryRes = await session.run(

View File

@ -23,7 +23,7 @@ afterEach(async () => {
describe('CreateComment', () => { describe('CreateComment', () => {
const createCommentMutation = gql` const createCommentMutation = gql`
mutation($postId: ID, $content: String!) { mutation($postId: ID!, $content: String!) {
CreateComment(postId: $postId, content: $content) { CreateComment(postId: $postId, content: $content) {
id id
content content
@ -37,13 +37,6 @@ describe('CreateComment', () => {
} }
} }
` `
const commentQueryForPostId = gql`
query($content: String) {
Comment(content: $content) {
postId
}
}
`
describe('unauthenticated', () => { describe('unauthenticated', () => {
it('throws authorization error', async () => { it('throws authorization error', async () => {
createCommentVariables = { createCommentVariables = {
@ -191,23 +184,6 @@ describe('CreateComment', () => {
client.request(createCommentMutation, createCommentVariablesWithNonExistentPost), client.request(createCommentMutation, createCommentVariablesWithNonExistentPost),
).rejects.toThrow('Comment cannot be created without a post!') ).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,
},
])
})
}) })
}) })

View File

@ -1,7 +1,6 @@
type Comment { type Comment {
id: ID! id: ID!
activityId: String activityId: String
postId: ID
author: User @relation(name: "WROTE", direction: "IN") author: User @relation(name: "WROTE", direction: "IN")
content: String! content: String!
contentExcerpt: String contentExcerpt: String
@ -12,3 +11,24 @@ type Comment {
disabled: Boolean disabled: Boolean
disabledBy: User @relation(name: "DISABLED", direction: "IN") disabledBy: User @relation(name: "DISABLED", direction: "IN")
} }
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
}

View File

@ -10,7 +10,7 @@ export default function(params) {
return { return {
mutation: ` mutation: `
mutation($id: ID!, $postId: ID, $content: String!) { mutation($id: ID!, $postId: ID!, $content: String!) {
CreateComment(id: $id, postId: $postId, content: $content) { CreateComment(id: $id, postId: $postId, content: $content) {
id id
} }

View File

@ -3,7 +3,7 @@ import gql from 'graphql-tag'
export default () => { export default () => {
return { return {
CreateComment: gql` CreateComment: gql`
mutation($postId: ID, $content: String!) { mutation($postId: ID!, $content: String!) {
CreateComment(postId: $postId, content: $content) { CreateComment(postId: $postId, content: $content) {
id id
contentExcerpt contentExcerpt