unreal-chat/apps/api/src/schema/index.ts
Jusemon 19bb0b5bdf refactor: migrate API from Apollo Server to Mercurius and enhance GraphQL implementation
- Replaced Apollo Server with Mercurius for GraphQL API
- Updated resolvers to use Mercurius-compatible GraphQL implementation
- Migrated from Express to Fastify for server framework
- Improved error handling with GraphQL error extensions
- Added Zod for environment variable validation
- Updated Prisma schema and migrations
- Configured CORS and WebSocket subscriptions
- Simplified GraphQL schema and resolver structure
- Enhanced type safety and code organization
2025-03-06 03:04:40 -05:00

68 lines
1.3 KiB
TypeScript

import { gql } from 'mercurius-codegen';
export default gql`
scalar DateTime
type User {
id: ID!
email: String!
username: String!
createdAt: DateTime!
updatedAt: DateTime
messages: [Message!]
rooms: [Room!]
ownedRooms: [Room!]
}
type Room {
id: ID!
name: String!
description: String
isPrivate: Boolean!
createdAt: DateTime!
updatedAt: DateTime
messages: [Message!]
members: [User!]
owner: User
}
type Message {
id: ID!
content: String!
createdAt: DateTime!
updatedAt: DateTime
userId: ID!
user: User
roomId: ID!
room: Room
}
type AuthPayload {
token: String!
user: User!
}
type Query {
me: User
users: [User!]!
user(id: ID!): User
rooms: [Room!]!
room(id: ID!): Room
messages(roomId: ID!): [Message!]!
}
type Mutation {
register(email: String!, username: String!, password: String!): AuthPayload!
login(email: String!, password: String!): AuthPayload!
createRoom(name: String!, description: String, isPrivate: Boolean): Room!
joinRoom(roomId: ID!): Room!
leaveRoom(roomId: ID!): Boolean!
sendMessage(content: String!, roomId: ID!): Message!
}
type Subscription {
messageAdded(roomId: ID!): Message!
roomAdded: Room!
roomUpdated: Room!
}
`;