Refactor GraphQL schema to enhance Service query with additional filtering and sorting options, and add a new Restful module
This commit is contained in:
@@ -1,7 +1,5 @@
|
||||
import { Module } from '@nestjs/common';
|
||||
import { GraphqlModule } from './graphql/graphql.module';
|
||||
import { PrismaModule } from './prisma/prisma.module';
|
||||
import { UsersModule } from './users/users.module';
|
||||
import { ClerkModule } from './clerk/clerk.module';
|
||||
|
||||
@Module({
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
import { builder, prisma, SortOrder } from './graphql.builder';
|
||||
import { Prisma } from '@prisma/client';
|
||||
|
||||
builder.prismaObject('User', {
|
||||
fields: (t) => ({
|
||||
@@ -229,7 +230,7 @@ builder.queryType({
|
||||
type: builder.inputType('ServiceWhereInput', {
|
||||
fields: (t) => ({
|
||||
// search by name contains
|
||||
name: t.string(),
|
||||
nameContain: t.string(),
|
||||
// search by name starts with
|
||||
nameStartsWith: t.string(),
|
||||
// search by name ends with
|
||||
@@ -262,9 +263,26 @@ builder.queryType({
|
||||
},
|
||||
resolve: (query, root, args, ctx, info) => {
|
||||
return prisma.service.findMany({
|
||||
// process filters
|
||||
where: {
|
||||
name: {
|
||||
contains: args.where?.nameContain as string,
|
||||
startsWith: args.where?.nameStartsWith as string,
|
||||
endsWith: args.where?.nameEndsWith as string,
|
||||
},
|
||||
},
|
||||
// process order by
|
||||
orderBy: {
|
||||
rating: args.orderBy?.rating as Prisma.SortOrder,
|
||||
price: args.orderBy?.price as Prisma.SortOrder,
|
||||
},
|
||||
// process pagination
|
||||
cursor: args.cursor as Prisma.ServiceWhereUniqueInput,
|
||||
take: args.take as number,
|
||||
skip: args.skip as number,
|
||||
...query,
|
||||
});
|
||||
},
|
||||
},
|
||||
}),
|
||||
service: t.prismaField({
|
||||
type: 'Service',
|
||||
@@ -329,12 +347,24 @@ builder.queryType({
|
||||
// type: 'User',
|
||||
// args: {
|
||||
// data: t.arg({
|
||||
// type: 'PrismaTypes.UserCreateInput',
|
||||
// type: builder.inputType('UserCreateInput', {
|
||||
// fields: (t) => ({
|
||||
// email: t.string({ required: true }),
|
||||
// name: t.string(),
|
||||
// // Include other fields as per your schema
|
||||
// }),
|
||||
// }),
|
||||
// required: true, // Make the data argument required
|
||||
// }),
|
||||
// },
|
||||
// resolve: (query, root, args, ctx, info) => {
|
||||
// if (!args.data) {
|
||||
// throw new Error('Data input is required');
|
||||
// }
|
||||
|
||||
// return prisma.user.create({
|
||||
// data: args.data,
|
||||
// ...query,
|
||||
// data: args.data as Prisma.UserCreateInput, // Explicit type casting to match Prisma's expectation
|
||||
// });
|
||||
// },
|
||||
// }),
|
||||
|
||||
5
src/restful/restful.module.ts
Normal file
5
src/restful/restful.module.ts
Normal file
@@ -0,0 +1,5 @@
|
||||
import { Module } from '@nestjs/common';
|
||||
@Module({
|
||||
imports: [],
|
||||
})
|
||||
export class RestfulModule {}
|
||||
0
src/restful/restful.service.ts
Normal file
0
src/restful/restful.service.ts
Normal file
Reference in New Issue
Block a user