Created
September 1, 2022 00:26
-
-
Save MichaelrMentele/94e1d9130f22f589781648359d23128a to your computer and use it in GitHub Desktop.
This file contains hidden or 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
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