249 lines
5.8 KiB
TypeScript
249 lines
5.8 KiB
TypeScript
import { builder, prisma } from './graphql.builder';
|
|
|
|
builder.prismaObject('User', {
|
|
fields: (t) => ({
|
|
id: t.exposeID('id'),
|
|
name: t.exposeString('name'),
|
|
email: t.exposeString('email'),
|
|
phoneNumber: t.exposeString('phoneNumber'),
|
|
role: t.exposeString('role'),
|
|
createdAt: t.expose('createdAt', {
|
|
type: 'DateTime',
|
|
nullable: true,
|
|
}),
|
|
updatedAt: t.expose('updatedAt', {
|
|
type: 'DateTime',
|
|
nullable: true,
|
|
}),
|
|
order: t.relation('orders'),
|
|
serviceFeedbacks: t.relation('serviceFeedbacks'),
|
|
documents: t.relation('documents'),
|
|
sendingMessage: t.relation('sendingMessage'),
|
|
Service: t.relation('Service'),
|
|
center: t.relation('center'),
|
|
customerChatRoom: t.relation('customerChatRoom'),
|
|
centerStaffChatRoom: t.relation('centerStaffChatRoom'),
|
|
CenterStaff: t.relation('CenterStaff'),
|
|
WorkshopSubscription: t.relation('WorkshopSubscription'),
|
|
}),
|
|
});
|
|
|
|
builder.prismaObject('Order', {
|
|
fields: (t) => ({
|
|
id: t.exposeID('id'),
|
|
userId: t.exposeID('userId'),
|
|
}),
|
|
});
|
|
|
|
builder.prismaObject('ServiceFeedback', {
|
|
fields: (t) => ({
|
|
id: t.exposeID('id'),
|
|
userId: t.exposeID('userId'),
|
|
}),
|
|
});
|
|
|
|
builder.prismaObject('UploadedDocument', {
|
|
name: 'documents',
|
|
fields: (t) => ({
|
|
id: t.exposeID('id'),
|
|
userId: t.exposeID('userId'),
|
|
}),
|
|
});
|
|
|
|
builder.prismaObject('Message', {
|
|
name: 'sendingMessage',
|
|
fields: (t) => ({
|
|
id: t.exposeID('id'),
|
|
userId: t.exposeID('senderId'),
|
|
}),
|
|
});
|
|
|
|
builder.prismaObject('Service', {
|
|
fields: (t) => ({
|
|
id: t.exposeID('id'),
|
|
userId: t.exposeID('userId'),
|
|
}),
|
|
});
|
|
|
|
builder.prismaObject('Center', {
|
|
fields: (t) => ({
|
|
id: t.exposeID('id'),
|
|
userId: t.exposeID('centerOwnerId'),
|
|
}),
|
|
});
|
|
|
|
builder.prismaObject('ChatRoom', {
|
|
fields: (t) => ({
|
|
id: t.exposeID('id'),
|
|
}),
|
|
});
|
|
|
|
builder.prismaObject('CenterStaff', {
|
|
fields: (t) => ({
|
|
staffId: t.exposeID('staffId'),
|
|
centerId: t.exposeID('centerId'),
|
|
serviceId: t.exposeID('serviceId'),
|
|
}),
|
|
});
|
|
|
|
builder.prismaObject('WorkshopSubscription', {
|
|
fields: (t) => ({
|
|
userId: t.exposeID('userId'),
|
|
workshopId: t.exposeID('workshopId'),
|
|
user: t.relation('user'),
|
|
workshop: t.relation('workshop'),
|
|
}),
|
|
});
|
|
|
|
builder.prismaObject('Workshop', {
|
|
fields: (t) => ({
|
|
id: t.exposeID('id'),
|
|
}),
|
|
});
|
|
|
|
// Query section
|
|
builder.queryType({
|
|
fields: (t) => ({
|
|
users: t.prismaField({
|
|
type: ['User'], // Return type is a list of 'User'
|
|
resolve: (query, root, args, ctx, info) => {
|
|
return prisma.user.findMany({
|
|
...query,
|
|
// Include related posts in the query
|
|
});
|
|
},
|
|
}),
|
|
user: t.prismaField({
|
|
type: 'User',
|
|
args: {
|
|
id: t.arg.string(),
|
|
},
|
|
resolve: (query, root, args, ctx, info) => {
|
|
return prisma.user.findUnique({
|
|
where: {
|
|
id: args.id?.toString(),
|
|
},
|
|
});
|
|
},
|
|
}),
|
|
orders: t.prismaField({
|
|
type: ['Order'],
|
|
resolve: (query, root, args, ctx, info) => {
|
|
return prisma.order.findMany({
|
|
...query,
|
|
});
|
|
},
|
|
}),
|
|
serviceFeedbacks: t.prismaField({
|
|
type: ['ServiceFeedback'],
|
|
resolve: (query, root, args, ctx, info) => {
|
|
return prisma.serviceFeedback.findMany({
|
|
...query,
|
|
});
|
|
},
|
|
}),
|
|
documents: t.prismaField({
|
|
type: ['UploadedDocument'],
|
|
resolve: (query, root, args, ctx, info) => {
|
|
return prisma.uploadedDocument.findMany({
|
|
...query,
|
|
});
|
|
},
|
|
}),
|
|
messages: t.prismaField({
|
|
type: ['Message'],
|
|
resolve: (query, root, args, ctx, info) => {
|
|
return prisma.message.findMany({
|
|
...query,
|
|
});
|
|
},
|
|
}),
|
|
services: t.prismaField({
|
|
type: ['Service'],
|
|
resolve: (query, root, args, ctx, info) => {
|
|
return prisma.service.findMany({
|
|
...query,
|
|
});
|
|
},
|
|
}),
|
|
centers: t.prismaField({
|
|
type: ['Center'],
|
|
resolve: (query, root, args, ctx, info) => {
|
|
return prisma.center.findMany({
|
|
...query,
|
|
});
|
|
},
|
|
}),
|
|
chatRooms: t.prismaField({
|
|
type: ['ChatRoom'],
|
|
resolve: (query, root, args, ctx, info) => {
|
|
return prisma.chatRoom.findMany({
|
|
...query,
|
|
});
|
|
},
|
|
}),
|
|
centerStaffs: t.prismaField({
|
|
type: ['CenterStaff'],
|
|
resolve: (query, root, args, ctx, info) => {
|
|
return prisma.centerStaff.findMany({
|
|
...query,
|
|
});
|
|
},
|
|
}),
|
|
workshopSubscriptions: t.prismaField({
|
|
type: ['WorkshopSubscription'],
|
|
resolve: (query, root, args, ctx, info) => {
|
|
return prisma.workshopSubscription.findMany({
|
|
...query,
|
|
});
|
|
},
|
|
}),
|
|
workshops: t.prismaField({
|
|
type: ['Workshop'],
|
|
resolve: (query, root, args, ctx, info) => {
|
|
return prisma.workshop.findMany({
|
|
...query,
|
|
});
|
|
},
|
|
}),
|
|
}),
|
|
});
|
|
|
|
// Mutation section
|
|
// builder.mutationType({
|
|
// fields: (t) => ({
|
|
// createUser: t.prismaField({
|
|
// type: 'User',
|
|
// args: {
|
|
// data: t.arg({
|
|
// type: 'PrismaTypes.UserCreateInput',
|
|
// }),
|
|
// },
|
|
// resolve: (query, root, args, ctx, info) => {
|
|
// return prisma.user.create({
|
|
// data: args.data,
|
|
// });
|
|
// },
|
|
// }),
|
|
// }),
|
|
// });
|
|
|
|
// Subscription section
|
|
// builder.subscriptionType({
|
|
// fields: (t) => ({
|
|
// userCreated: t.prismaField({
|
|
// type: 'User',
|
|
// subscribe: (query, root, args, ctx, info) => {
|
|
// return prisma.$subscribe.user({
|
|
// mutation_in: ['CREATED'],
|
|
// });
|
|
// },
|
|
// resolve: (payload) => {
|
|
// return payload;
|
|
// },
|
|
// }),
|
|
// }),
|
|
// });
|
|
|
|
export const schema = builder.toSchema();
|