Skip to content

Commit

Permalink
Merge pull request #6471 from Ocelot-Social-Community/message-properties
Browse files Browse the repository at this point in the history
feat(backend): message properties
  • Loading branch information
Mogge committed Jun 21, 2023
2 parents 6904668 + 02ffdda commit 9e4b2d1
Show file tree
Hide file tree
Showing 4 changed files with 39 additions and 20 deletions.
8 changes: 5 additions & 3 deletions backend/src/graphql/messages.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,11 +21,13 @@ export const messageQuery = () => {
return gql`
query($roomId: ID!) {
Message(roomId: $roomId) {
_id
id
content
author {
id
}
senderId
username
avatar
date
}
}
`
Expand Down
38 changes: 22 additions & 16 deletions backend/src/schema/resolvers/messages.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -184,20 +184,23 @@ describe('Message', () => {

describe('room exists with authenticated user chatting', () => {
it('returns the messages', async () => {
await expect(query({
const result = await query({
query: messageQuery(),
variables: {
roomId,
},
})).resolves.toMatchObject({
})
expect(result).toMatchObject({
errors: undefined,
data: {
Message: [{
id: expect.any(String),
_id: result.data.Message[0].id,
content: 'Some nice message to other chatting user',
author: {
id: 'chatting-user',
},
senderId: 'chatting-user',
username: 'Chatting User',
avatar: expect.any(String),
date: expect.any(String),
}],
},
})
Expand Down Expand Up @@ -235,29 +238,32 @@ describe('Message', () => {
{
id: expect.any(String),
content: 'Some nice message to other chatting user',
author: {
id: 'chatting-user',
},
senderId: 'chatting-user',
username: 'Chatting User',
avatar: expect.any(String),
date: expect.any(String),
},
{
id: expect.any(String),
content: 'A nice response message to chatting user',
author: {
id: 'other-chatting-user',
},
senderId: 'other-chatting-user',
username: 'Other Chatting User',
avatar: expect.any(String),
date: expect.any(String),
},
{
id: expect.any(String),
content: 'And another nice message to other chatting user',
author: {
id: 'chatting-user',
},
}
senderId: 'chatting-user',
username: 'Chatting User',
avatar: expect.any(String),
date: expect.any(String),
},
],
},
})
})
})
})
})

describe('room exists, authenticated user not in room', () => {
Expand Down
8 changes: 7 additions & 1 deletion backend/src/schema/resolvers/messages.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,13 @@ export default {
id: context.user.id,
},
}
return neo4jgraphql(object, params, context, resolveInfo)
const resolved = await neo4jgraphql(object, params, context, resolveInfo)
if (resolved) {
resolved.forEach((message) => {
message._id = message.id
})
}
return resolved
},
},
Mutation: {
Expand Down
5 changes: 5 additions & 0 deletions backend/src/schema/types/type/Message.gql
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,11 @@ type Message {

author: User! @relation(name: "CREATED", direction: "IN")
room: Room! @relation(name: "INSIDE", direction: "OUT")

senderId: String! @cypher(statement: "MATCH (this)<-[:CREATED]-(user:User) RETURN user.id")
username: String! @cypher(statement: "MATCH (this)<-[:CREATED]-(user:User) RETURN user.name")
avatar: String @cypher(statement: "MATCH (this)<-[:CREATED]-(:User)-[:AVATAR_IMAGE]->(image:Image) RETURN image.url")
date: String! @cypher(statement: "RETURN this.createdAt")
}

type Mutation {
Expand Down

0 comments on commit 9e4b2d1

Please sign in to comment.