Skip to content

Instantly share code, notes, and snippets.

@omar-dulaimi
Created April 11, 2021 15:52
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save omar-dulaimi/fe5dd8ac1f634f5daaedba7b4752cc26 to your computer and use it in GitHub Desktop.
Save omar-dulaimi/fe5dd8ac1f634f5daaedba7b4752cc26 to your computer and use it in GitHub Desktop.
TypeGraphQL with PrismaSelect from Pal.js
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