manifold/web/lib/api/graphql/resolvers/comment.ts
joy_void_joy 85746f0461 graphql: Add slug, market and markets queries
Translate /api/v0/markets, /api/v0/market/[id] and /api/v0/slug/[id]
into their graphql equivalent
2022-07-20 18:15:56 +02:00

31 lines
693 B
TypeScript

import type { CommentResolvers, Resolvers } from 'web/generated/graphql_api'
const commentResolvers: CommentResolvers = {
market: async (comment) => comment.contract,
answers: async (comment, _, { dataSources }) => {
const result = await dataSources.firebaseAPI.listAllCommentAnswers(
comment.id,
comment.contract.id
)
return result.map((el) => ({
...el,
contract: comment.contract,
}))
},
user: async (comment) => ({
id: comment.userId,
avatarUrl: comment.userAvatarUrl,
name: comment.userName,
username: comment.userUsername,
}),
}
const resolvers: Resolvers = {
Comment: commentResolvers,
}
export default resolvers