Skip to content

Instantly share code, notes, and snippets.

@MichaelrMentele
Created September 1, 2022 00:26
Show Gist options
  • Save MichaelrMentele/94e1d9130f22f589781648359d23128a to your computer and use it in GitHub Desktop.
Save MichaelrMentele/94e1d9130f22f589781648359d23128a to your computer and use it in GitHub Desktop.
export const comments: QueryResolvers['comments'] = async ({
parentType,
parentId,
}) => {
const commentable = parentType[0].toLowerCase() + parentType.substring(1)
validateWith(() => {
if (!Object.values(Commentable).includes(commentable)) {
throw new Error(
'Invalid commentable passed in, check your value for parentType'
)
}
})
return db.comment.findMany({
where: {
[commentable + 'Id']: parentId,
},
orderBy: {
createdAt: 'desc',
},
})
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment