const HAS_ROOM = gql`
mutation hasRoom($receiverId: Float!) {
hasRoom(input: { receiverId: $receiverId }) {
error
success
roomId
}
}
`;
const [hasRoom, { data, loading }] = useMutation(HAS_ROOM);
useEffect(() => {
hasRoom({
variables: { receiverId: userInfo.id },
});
}, []);
variables
에 객체를 넣고 그안에 key, value
를 설정하면 위에서 선언한 hasRoom(receiverId`)로 전달된다
const GET_MESSAGES = gql`
query getMessages($roomId: Float!) {
getMessage(input: { roomId: $roomId }) {
error
success
messages {
createdAt
receiver {
id
firstname
lastname
images {
src
}
}
sender {
id
firstname
lastname
images {
src
}
}
text
}
}
}
`;
const {
loading: getMessagesLoading,
data: { getMessage },
} = useQuery(GET_MESSAGES, {
variables: { roomId: room?.roomId },
});