import BaseDataSource from '../shared/base.datasource' ; import { ID } from '../shared/shared.types' ; import { AddPostCommentInput , PostCommentsArgs } from '../generated/graphql' ; class CommentAPI extends BaseDataSource { async addPostComment ( input ) { const { db } = this . context ; const commentEdge = await db . comment . create ( input ) ; return commentEdge ; } async removePostComment ( id ) { const { db } = this . context ; const comment = await db . comment . deleteById ( id ) ; return ! ! comment ; } async findCommentConnectionByPostId ( postId , args ) { const { db } = this . context ; const connection = await db . comment . findConnection ( { ... args , postId , } ) ; return connection ; } async countCommentsByPostId ( postId ) { const { db } = this . context ; const count = await db . comment . countByPostId ( postId ) ; return count ; } } export default CommentAPI ;