UNPKG

@wepublish/api

Version:
334 lines 15.8 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.GraphQLPublicCommentConnection = exports.GraphQLCommentConnection = exports.GraphQLPublicComment = exports.GraphQLCalculatedRating = exports.GraphQLComment = exports.GraphQLoverriddenRating = exports.GraphQLPublicCommentInput = exports.GraphQLChallengeInput = exports.GraphQLPublicCommentUpdateInput = exports.GraphQLCommentRatingOverrideUpdateInput = exports.GraphQLCommentRevisionUpdateInput = exports.GraphQLCommentRevision = exports.GraphQLCommentFilter = exports.GraphQLPublicCommentSort = exports.GraphQLCommentSort = exports.GraphQLCommentItemType = exports.GraphQLCommentAuthorType = exports.GraphQLCommentRejectionReason = exports.GraphQLCommentState = void 0; const tslib_1 = require("tslib"); const client_1 = require("@prisma/client"); const api_1 = require("../../../../authentication-api/src"); const api_2 = require("../../../../richtext-api/src"); const api_3 = require("../../../../user-api/src"); const graphql_1 = require("graphql"); const graphql_scalars_1 = require("graphql-scalars"); const comment_1 = require("../../db/comment"); const utility_1 = require("../../utility"); const comment_rating_1 = require("../comment-rating/comment-rating"); const common_1 = require("../common"); const image_1 = require("../image"); const tag_1 = require("../tag/tag"); const user_1 = require("../user"); const comment_public_queries_1 = require("./comment.public-queries"); const comment_rating_public_queries_1 = require("../comment-rating/comment-rating.public-queries"); exports.GraphQLCommentState = new graphql_1.GraphQLEnumType({ name: 'CommentState', values: { Approved: { value: client_1.CommentState.approved }, PendingApproval: { value: client_1.CommentState.pendingApproval }, PendingUserChanges: { value: client_1.CommentState.pendingUserChanges }, Rejected: { value: client_1.CommentState.rejected } } }); exports.GraphQLCommentRejectionReason = new graphql_1.GraphQLEnumType({ name: 'CommentRejectionReason', values: { Misconduct: { value: client_1.CommentRejectionReason.misconduct }, Spam: { value: client_1.CommentRejectionReason.spam } } }); exports.GraphQLCommentAuthorType = new graphql_1.GraphQLEnumType({ name: 'CommentAuthorType', values: { Author: { value: client_1.CommentAuthorType.author }, Team: { value: client_1.CommentAuthorType.team }, VerifiedUser: { value: client_1.CommentAuthorType.verifiedUser }, GuestUser: { value: client_1.CommentAuthorType.guestUser } } }); exports.GraphQLCommentItemType = new graphql_1.GraphQLEnumType({ name: 'CommentItemType', values: { Article: { value: client_1.CommentItemType.article }, PeerArticle: { value: client_1.CommentItemType.peerArticle }, Page: { value: client_1.CommentItemType.page } } }); exports.GraphQLCommentSort = new graphql_1.GraphQLEnumType({ name: 'CommentSort', values: { ModifiedAt: { value: comment_1.CommentSort.ModifiedAt }, CreatedAt: { value: comment_1.CommentSort.CreatedAt } } }); exports.GraphQLPublicCommentSort = new graphql_1.GraphQLEnumType({ name: 'CommentSort', values: { RATING: { value: comment_1.PublicCommentSort.Rating } } }); exports.GraphQLCommentFilter = new graphql_1.GraphQLInputObjectType({ name: 'CommentFilter', fields: { item: { type: graphql_1.GraphQLID }, tags: { type: new graphql_1.GraphQLList(new graphql_1.GraphQLNonNull(graphql_1.GraphQLID)) }, states: { type: new graphql_1.GraphQLList(new graphql_1.GraphQLNonNull(exports.GraphQLCommentState)) }, itemType: { type: exports.GraphQLCommentItemType }, itemID: { type: graphql_1.GraphQLID } } }); exports.GraphQLCommentRevision = new graphql_1.GraphQLObjectType({ name: 'CommentRevision', fields: { text: { type: api_2.GraphQLRichText }, title: { type: graphql_1.GraphQLString }, lead: { type: graphql_1.GraphQLString }, createdAt: { type: new graphql_1.GraphQLNonNull(graphql_scalars_1.GraphQLDateTime) } } }); exports.GraphQLCommentRevisionUpdateInput = new graphql_1.GraphQLInputObjectType({ name: 'CommentRevisionUpdateInput', fields: { text: { type: api_2.GraphQLRichText }, title: { type: graphql_1.GraphQLString }, lead: { type: graphql_1.GraphQLString } } }); exports.GraphQLCommentRatingOverrideUpdateInput = new graphql_1.GraphQLInputObjectType({ name: 'CommentRatingOverrideUpdateInput', fields: { answerId: { type: new graphql_1.GraphQLNonNull(graphql_1.GraphQLID) }, value: { type: graphql_1.GraphQLInt } } }); exports.GraphQLPublicCommentUpdateInput = new graphql_1.GraphQLInputObjectType({ name: 'CommentUpdateInput', fields: { id: { type: new graphql_1.GraphQLNonNull(graphql_1.GraphQLID) }, text: { type: api_2.GraphQLRichText }, title: { type: graphql_1.GraphQLString }, lead: { type: graphql_1.GraphQLString } } }); exports.GraphQLChallengeInput = new graphql_1.GraphQLInputObjectType({ name: 'ChallengeInput', fields: { challengeID: { type: new graphql_1.GraphQLNonNull(graphql_1.GraphQLString) }, challengeSolution: { type: new graphql_1.GraphQLNonNull(graphql_1.GraphQLString) } } }); exports.GraphQLPublicCommentInput = new graphql_1.GraphQLInputObjectType({ name: 'CommentInput', fields: { parentID: { type: graphql_1.GraphQLID }, guestUsername: { type: graphql_1.GraphQLString }, challenge: { type: exports.GraphQLChallengeInput }, itemID: { type: new graphql_1.GraphQLNonNull(graphql_1.GraphQLID) }, itemType: { type: new graphql_1.GraphQLNonNull(exports.GraphQLCommentItemType) }, title: { type: graphql_1.GraphQLString }, peerId: { type: graphql_1.GraphQLID }, text: { type: new graphql_1.GraphQLNonNull(api_2.GraphQLRichText) } } }); exports.GraphQLoverriddenRating = new graphql_1.GraphQLObjectType({ name: 'overriddenRating', fields: { answerId: { type: new graphql_1.GraphQLNonNull(graphql_1.GraphQLID) }, value: { type: graphql_1.GraphQLInt } } }); exports.GraphQLComment = new graphql_1.GraphQLObjectType({ name: 'Comment', fields: () => ({ id: { type: new graphql_1.GraphQLNonNull(graphql_1.GraphQLID) }, guestUsername: { type: graphql_1.GraphQLString }, guestUserImage: { type: image_1.GraphQLImage, resolve: (0, utility_1.createProxyingResolver)(({ guestUserImageID }, _, { prisma: { image } }) => guestUserImageID ? image.findUnique({ where: { id: guestUserImageID } }) : null) }, user: { type: user_1.GraphQLUser, resolve: (0, utility_1.createProxyingResolver)(({ userID }, _, { prisma: { user } }) => userID ? user.findUnique({ where: { id: userID }, select: api_3.unselectPassword }) : null) }, tags: { type: new graphql_1.GraphQLList(new graphql_1.GraphQLNonNull(tag_1.GraphQLTag)), resolve: (0, utility_1.createProxyingResolver)(({ id }, _, { prisma: { tag } }) => tslib_1.__awaiter(void 0, void 0, void 0, function* () { const tags = yield tag.findMany({ where: { comments: { some: { commentId: id } } } }); return tags; })) }, authorType: { type: new graphql_1.GraphQLNonNull(exports.GraphQLCommentAuthorType) }, itemID: { type: new graphql_1.GraphQLNonNull(graphql_1.GraphQLID) }, itemType: { type: new graphql_1.GraphQLNonNull(exports.GraphQLCommentItemType) }, peerId: { type: graphql_1.GraphQLID }, parentComment: { type: exports.GraphQLComment, resolve: (0, utility_1.createProxyingResolver)(({ parentID }, _, { prisma: { comment } }) => parentID ? comment.findUnique({ where: { id: parentID }, include: { revisions: { orderBy: { createdAt: 'asc' } } } }) : null) }, revisions: { type: new graphql_1.GraphQLNonNull(new graphql_1.GraphQLList(new graphql_1.GraphQLNonNull(exports.GraphQLCommentRevision))) }, source: { type: graphql_1.GraphQLString }, state: { type: new graphql_1.GraphQLNonNull(exports.GraphQLCommentState) }, rejectionReason: { type: exports.GraphQLCommentRejectionReason }, createdAt: { type: new graphql_1.GraphQLNonNull(graphql_scalars_1.GraphQLDateTime) }, modifiedAt: { type: new graphql_1.GraphQLNonNull(graphql_scalars_1.GraphQLDateTime) }, overriddenRatings: { type: new graphql_1.GraphQLList(new graphql_1.GraphQLNonNull(exports.GraphQLoverriddenRating)) } }) }); exports.GraphQLCalculatedRating = new graphql_1.GraphQLObjectType({ name: 'CalculatedRating', fields: { count: { type: new graphql_1.GraphQLNonNull(graphql_1.GraphQLInt) }, total: { type: new graphql_1.GraphQLNonNull(graphql_1.GraphQLInt) }, mean: { type: new graphql_1.GraphQLNonNull(graphql_1.GraphQLFloat) }, answer: { type: new graphql_1.GraphQLNonNull(comment_rating_1.GraphQLCommentRatingSystemAnswer) } } }); exports.GraphQLPublicComment = new graphql_1.GraphQLObjectType({ name: 'Comment', fields: () => ({ id: { type: new graphql_1.GraphQLNonNull(graphql_1.GraphQLID) }, parentID: { type: graphql_1.GraphQLID }, guestUsername: { type: graphql_1.GraphQLString }, guestUserImage: { type: image_1.GraphQLImage, resolve: (0, utility_1.createProxyingResolver)(({ guestUserImageID }, _, { prisma: { image } }) => guestUserImageID ? image.findUnique({ where: { id: guestUserImageID } }) : null) }, user: { type: user_1.GraphQLPublicUser, resolve: (0, utility_1.createProxyingResolver)(({ userID }, _, { prisma: { user } }) => userID ? user.findUnique({ where: { id: userID }, select: api_3.unselectPassword }) : null) }, tags: { type: new graphql_1.GraphQLList(new graphql_1.GraphQLNonNull(tag_1.GraphQLTag)), resolve: (0, utility_1.createProxyingResolver)(({ id }, _, { prisma: { taggedComments } }) => tslib_1.__awaiter(void 0, void 0, void 0, function* () { const tags = yield taggedComments.findMany({ where: { commentId: id }, include: { tag: true } }); return tags.map(({ tag }) => tag); })) }, authorType: { type: new graphql_1.GraphQLNonNull(exports.GraphQLCommentAuthorType) }, itemID: { type: new graphql_1.GraphQLNonNull(graphql_1.GraphQLID) }, itemType: { type: new graphql_1.GraphQLNonNull(exports.GraphQLCommentItemType) }, peerId: { type: graphql_1.GraphQLID }, children: { type: new graphql_1.GraphQLNonNull(new graphql_1.GraphQLList(new graphql_1.GraphQLNonNull(exports.GraphQLPublicComment))), resolve: (0, utility_1.createProxyingResolver)(({ id }, _, { session, prisma: { comment } }) => { const userId = (session === null || session === void 0 ? void 0 : session.type) === api_1.AuthSessionType.User ? session.user.id : null; return (0, comment_public_queries_1.getPublicChildrenCommentsByParentId)(id, userId, comment); }) }, title: { type: graphql_1.GraphQLString }, lead: { type: graphql_1.GraphQLString }, text: { type: api_2.GraphQLRichText }, state: { type: new graphql_1.GraphQLNonNull(exports.GraphQLCommentState) }, source: { type: graphql_1.GraphQLString }, rejectionReason: { type: graphql_1.GraphQLString }, createdAt: { type: new graphql_1.GraphQLNonNull(graphql_scalars_1.GraphQLDateTime) }, modifiedAt: { type: graphql_scalars_1.GraphQLDateTime, resolve: (0, utility_1.createProxyingResolver)(({ revisions }) => { return (revisions === null || revisions === void 0 ? void 0 : revisions.length) ? revisions[(revisions === null || revisions === void 0 ? void 0 : revisions.length) - 1].createdAt : undefined; }) }, calculatedRatings: { type: new graphql_1.GraphQLNonNull(new graphql_1.GraphQLList(new graphql_1.GraphQLNonNull(exports.GraphQLCalculatedRating))), resolve: (0, utility_1.createProxyingResolver)(({ calculatedRatings, id }, _, { prisma: { commentRating }, loaders: { commentRatingSystemAnswers } }) => tslib_1.__awaiter(void 0, void 0, void 0, function* () { if (calculatedRatings) { return calculatedRatings; } const [answers, ratings] = yield Promise.all([ commentRatingSystemAnswers.load(1), commentRating.findMany({ where: { commentId: id } }) ]); return (0, comment_public_queries_1.getCalculatedRatingsForComment)(answers, ratings); })) }, overriddenRatings: { type: new graphql_1.GraphQLNonNull(new graphql_1.GraphQLList(new graphql_1.GraphQLNonNull(exports.GraphQLoverriddenRating))), resolve: comment => { var _a; return (_a = comment.overriddenRatings.filter(ratings => ratings.value != null)) !== null && _a !== void 0 ? _a : []; } }, userRatings: { type: new graphql_1.GraphQLNonNull(new graphql_1.GraphQLList(new graphql_1.GraphQLNonNull(comment_rating_1.GraphQLCommentRating))), resolve: ({ id }, _, { optionalAuthenticateUser, prisma: { commentRating } }) => (0, comment_rating_public_queries_1.userCommentRating)(id, optionalAuthenticateUser, commentRating) } }) }); exports.GraphQLCommentConnection = new graphql_1.GraphQLObjectType({ name: 'CommentConnection', fields: { nodes: { type: new graphql_1.GraphQLNonNull(new graphql_1.GraphQLList(new graphql_1.GraphQLNonNull(exports.GraphQLComment))) }, pageInfo: { type: new graphql_1.GraphQLNonNull(common_1.GraphQLPageInfo) }, totalCount: { type: new graphql_1.GraphQLNonNull(graphql_1.GraphQLInt) } } }); exports.GraphQLPublicCommentConnection = new graphql_1.GraphQLObjectType({ name: 'CommentConnection', fields: { nodes: { type: new graphql_1.GraphQLNonNull(new graphql_1.GraphQLList(new graphql_1.GraphQLNonNull(exports.GraphQLPublicComment))) }, pageInfo: { type: new graphql_1.GraphQLNonNull(common_1.GraphQLPageInfo) }, totalCount: { type: new graphql_1.GraphQLNonNull(graphql_1.GraphQLInt) } } }); //# sourceMappingURL=comment.js.map