From 5d4c4f3c98755f87b3724cc915d82d28b63d80c6 Mon Sep 17 00:00:00 2001 From: Moriz Wahl Date: Fri, 16 Jun 2023 09:08:31 +0200 Subject: [PATCH] roomId property --- backend/src/graphql/rooms.ts | 2 ++ backend/src/schema/resolvers/rooms.spec.ts | 14 ++++++++++---- backend/src/schema/resolvers/rooms.ts | 3 +++ backend/src/schema/types/type/Room.gql | 4 +++- 4 files changed, 18 insertions(+), 5 deletions(-) diff --git a/backend/src/graphql/rooms.ts b/backend/src/graphql/rooms.ts index 38d10a1d8..f06313228 100644 --- a/backend/src/graphql/rooms.ts +++ b/backend/src/graphql/rooms.ts @@ -9,6 +9,7 @@ export const createRoomMutation = () => { userId: $userId ) { id + roomId } } ` @@ -19,6 +20,7 @@ export const roomQuery = () => { query { Room { id + roomId users { id } diff --git a/backend/src/schema/resolvers/rooms.spec.ts b/backend/src/schema/resolvers/rooms.spec.ts index 26c95920b..be999db83 100644 --- a/backend/src/schema/resolvers/rooms.spec.ts +++ b/backend/src/schema/resolvers/rooms.spec.ts @@ -93,16 +93,18 @@ describe('Room', () => { describe('user id exists', () => { it('returns the id of the room', async () => { - await expect(mutate({ + const result = await mutate({ mutation: createRoomMutation(), variables: { userId: 'other-chatting-user', }, - })).resolves.toMatchObject({ + }) + expect(result).toMatchObject({ errors: undefined, data: { CreateRoom: { id: expect.any(String), + roomId: result.data.CreateRoom.id, }, }, }) @@ -131,12 +133,14 @@ describe('Room', () => { }) it('returns the room', async () => { - await expect(query({ query: roomQuery() })).resolves.toMatchObject({ + const result = await query({ query: roomQuery() }) + expect(result).toMatchObject({ errors: undefined, data: { Room: [ { id: expect.any(String), + roomId: result.data.Room[0].id, users: expect.arrayContaining([ { id: 'chatting-user', @@ -158,12 +162,14 @@ describe('Room', () => { }) it('returns the room', async () => { - await expect(query({ query: roomQuery() })).resolves.toMatchObject({ + const result = await query({ query: roomQuery() }) + expect(result).toMatchObject({ errors: undefined, data: { Room: [ { id: expect.any(String), + roomId: result.data.Room[0].id, users: expect.arrayContaining([ { id: 'chatting-user', diff --git a/backend/src/schema/resolvers/rooms.ts b/backend/src/schema/resolvers/rooms.ts index fe3779293..9080a87ed 100644 --- a/backend/src/schema/resolvers/rooms.ts +++ b/backend/src/schema/resolvers/rooms.ts @@ -38,6 +38,9 @@ export default { }) try { const room = await writeTxResultPromise + if (room) { + room.roomId = room.id + } return room } catch (error) { throw new Error(error) diff --git a/backend/src/schema/types/type/Room.gql b/backend/src/schema/types/type/Room.gql index c228c3a74..854d85078 100644 --- a/backend/src/schema/types/type/Room.gql +++ b/backend/src/schema/types/type/Room.gql @@ -10,7 +10,9 @@ type Room { createdAt: String updatedAt: String - users: [User]! @relation(name: "CHATS_IN", direction: "IN") + users: [User]! @relation(name: "CHATS_IN", direction: "IN") + + roomId: String! @cypher(statement: "RETURN this.id") } type Mutation {