mirror of
https://github.com/IT4Change/Ocelot-Social.git
synced 2025-12-13 07:45:56 +00:00
Use custom resolver
- add postId to type Comment - remove it from params to create node without postId - fix tests Co-authored-by: Robert Schäfer <roschaefer@users.noreply.github.com> Co-Authored-By: Tirokk <wolle.huss@pjannto.com> Co-Authored-By: Mike Aono <aonomike@gmail.com>
This commit is contained in:
parent
0bcfefe210
commit
f46e5ee58c
@ -2,11 +2,24 @@ import { neo4jgraphql } from 'neo4j-graphql-js'
|
||||
|
||||
export default {
|
||||
Mutation: {
|
||||
CreateComment: (object, params, context, resolveInfo) => {
|
||||
return neo4jgraphql(object, params, context, resolveInfo, false)
|
||||
},
|
||||
AddPostComments: (object, params, context, resolveInfo) => {
|
||||
return neo4jgraphql(object, params, context, resolveInfo, false)
|
||||
CreateComment: async (object, params, context, resolveInfo) => {
|
||||
const { postId } = params
|
||||
delete params.postId
|
||||
const comment = await neo4jgraphql(object, params, context, resolveInfo, true)
|
||||
|
||||
const session = context.driver.session()
|
||||
|
||||
const transactionRes = await session.run(`
|
||||
MATCH (post:Post {id: $postId}), (comment:Comment {id: $commentId})
|
||||
MERGE (post)<-[:COMMENTS]-(comment)
|
||||
RETURN comment {.id, .content}`, {
|
||||
postId,
|
||||
commentId: comment.id
|
||||
}
|
||||
)
|
||||
session.close()
|
||||
|
||||
return comment
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ -19,8 +19,8 @@ afterEach(async () => {
|
||||
|
||||
describe('CreateComment', () => {
|
||||
const mutation = `
|
||||
mutation($id: ID!, $content: String!) {
|
||||
CreateComment(id: $id, content: $content) {
|
||||
mutation($postId: ID, $content: String!) {
|
||||
CreateComment(postId: $postId, content: $content) {
|
||||
id
|
||||
content
|
||||
}
|
||||
@ -29,7 +29,7 @@ describe('CreateComment', () => {
|
||||
describe('unauthenticated', () => {
|
||||
it('throws authorization error', async () => {
|
||||
variables = {
|
||||
id: 'c1',
|
||||
postId: 'p1',
|
||||
content: 'I\'m not authorised to comment'
|
||||
}
|
||||
client = new GraphQLClient(host)
|
||||
@ -46,12 +46,11 @@ describe('CreateComment', () => {
|
||||
|
||||
it('creates a post', async () => {
|
||||
variables = {
|
||||
id: 'c1',
|
||||
postId: 'p1',
|
||||
content: 'I\'m authorised to comment'
|
||||
}
|
||||
const expected = {
|
||||
CreateComment: {
|
||||
id: 'c1',
|
||||
content: 'I\'m authorised to comment'
|
||||
}
|
||||
}
|
||||
|
||||
@ -210,6 +210,7 @@ type Post {
|
||||
type Comment {
|
||||
id: ID!
|
||||
activityId: String
|
||||
postId: ID
|
||||
author: User @relation(name: "WROTE", direction: "IN")
|
||||
content: String!
|
||||
contentExcerpt: String
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user