Created
April 11, 2021 15:52
-
-
Save omar-dulaimi/fe5dd8ac1f634f5daaedba7b4752cc26 to your computer and use it in GitHub Desktop.
TypeGraphQL with PrismaSelect from Pal.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import { PrismaSelect } from '@paljs/plugins'; | |
export function Fields(): ParameterDecorator { | |
return createParamDecorator(({ info }) => { | |
const fieldsMap = new PrismaSelect(info).value; | |
return fieldsMap; | |
}); | |
} | |
Example usage: | |
/* | |
@TypeGraphQL.Mutation(_returns => User, { | |
nullable: true, | |
}) | |
async updateUser( | |
@TypeGraphQL.Ctx() ctx: Context, | |
@TypeGraphQL.Args() args: UpdateUserArgs, | |
@Fields() fields: any, | |
): Promise<User | null> { | |
const user = await ctx.prisma.user.findUnique({ | |
where: { | |
...args.where, | |
}, | |
select: { | |
status: true, | |
}, | |
}); | |
return ctx.prisma.user.update({ | |
where: args.where, | |
data: args.data, | |
select: { | |
...fields.select, | |
}, | |
}); | |
} | |
*/ | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment