UNPKG

@wepublish/api

Version:
287 lines 16.4 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.GraphQLPublicArticleConnection = exports.GraphQLPublicArticle = exports.GraphQLPeerArticleConnection = exports.GraphQLPeerArticle = exports.GraphQLArticleConnection = exports.GraphQLArticle = exports.GraphQLArticleRevision = exports.GraphQLArticleInput = exports.GraphQLPublicArticleSort = exports.GraphQLArticleSort = exports.GraphQLPublicArticleFilter = exports.GraphQLArticleFilter = void 0; const tslib_1 = require("tslib"); const graphql_1 = require("graphql"); const graphql_scalars_1 = require("graphql-scalars"); const image_1 = require("./image"); const author_1 = require("./author"); const article_1 = require("../db/article"); const slug_1 = require("./slug"); const common_1 = require("./common"); const blocks_1 = require("./blocks"); const utility_1 = require("../utility"); const peer_1 = require("./peer"); const comment_1 = require("./comment/comment"); const api_1 = require("../../../authentication-api/src"); const comment_public_queries_1 = require("./comment/comment.public-queries"); const api_2 = require("../../../utils-api/src"); exports.GraphQLArticleFilter = new graphql_1.GraphQLInputObjectType({ name: 'ArticleFilter', fields: { title: { type: graphql_1.GraphQLString }, preTitle: { type: graphql_1.GraphQLString }, lead: { type: graphql_1.GraphQLString }, publicationDateFrom: { type: common_1.GraphQLDateFilter }, publicationDateTo: { type: common_1.GraphQLDateFilter }, draft: { type: graphql_1.GraphQLBoolean }, published: { type: graphql_1.GraphQLBoolean }, pending: { type: graphql_1.GraphQLBoolean }, authors: { type: new graphql_1.GraphQLList(new graphql_1.GraphQLNonNull(graphql_1.GraphQLID)) }, tags: { type: new graphql_1.GraphQLList(new graphql_1.GraphQLNonNull(graphql_1.GraphQLString)) }, includeHidden: { type: graphql_1.GraphQLBoolean }, shared: { type: graphql_1.GraphQLBoolean } } }); exports.GraphQLPublicArticleFilter = new graphql_1.GraphQLInputObjectType({ name: 'ArticleFilter', fields: { authors: { type: new graphql_1.GraphQLList(new graphql_1.GraphQLNonNull(graphql_1.GraphQLID)) }, tags: { type: new graphql_1.GraphQLList(new graphql_1.GraphQLNonNull(graphql_1.GraphQLString)) }, includeHidden: { type: graphql_1.GraphQLBoolean }, shared: { type: graphql_1.GraphQLBoolean } } }); exports.GraphQLArticleSort = new graphql_1.GraphQLEnumType({ name: 'ArticleSort', values: { CREATED_AT: { value: article_1.ArticleSort.CreatedAt }, MODIFIED_AT: { value: article_1.ArticleSort.ModifiedAt }, PUBLISH_AT: { value: article_1.ArticleSort.PublishAt }, PUBLISHED_AT: { value: article_1.ArticleSort.PublishedAt }, UPDATED_AT: { value: article_1.ArticleSort.UpdatedAt } } }); exports.GraphQLPublicArticleSort = new graphql_1.GraphQLEnumType({ name: 'ArticleSort', values: { PUBLISHED_AT: { value: article_1.ArticleSort.PublishedAt }, UPDATED_AT: { value: article_1.ArticleSort.UpdatedAt } } }); exports.GraphQLArticleInput = new graphql_1.GraphQLInputObjectType({ name: 'ArticleInput', fields: { slug: { type: slug_1.GraphQLSlug }, preTitle: { type: graphql_1.GraphQLString }, title: { type: new graphql_1.GraphQLNonNull(graphql_1.GraphQLString) }, lead: { type: graphql_1.GraphQLString }, seoTitle: { type: graphql_1.GraphQLString }, tags: { type: new graphql_1.GraphQLNonNull(new graphql_1.GraphQLList(new graphql_1.GraphQLNonNull(graphql_1.GraphQLString))) }, properties: { type: new graphql_1.GraphQLNonNull(new graphql_1.GraphQLList(new graphql_1.GraphQLNonNull(common_1.GraphQLMetadataPropertyInput))) }, canonicalUrl: { type: graphql_1.GraphQLString }, imageID: { type: graphql_1.GraphQLID }, authorIDs: { type: new graphql_1.GraphQLNonNull(new graphql_1.GraphQLList(new graphql_1.GraphQLNonNull(graphql_1.GraphQLID))) }, shared: { type: new graphql_1.GraphQLNonNull(graphql_1.GraphQLBoolean) }, hidden: { type: graphql_1.GraphQLBoolean }, breaking: { type: new graphql_1.GraphQLNonNull(graphql_1.GraphQLBoolean) }, hideAuthor: { type: new graphql_1.GraphQLNonNull(graphql_1.GraphQLBoolean) }, socialMediaTitle: { type: graphql_1.GraphQLString }, socialMediaDescription: { type: graphql_1.GraphQLString }, socialMediaAuthorIDs: { type: new graphql_1.GraphQLNonNull(new graphql_1.GraphQLList(new graphql_1.GraphQLNonNull(graphql_1.GraphQLID))) }, socialMediaImageID: { type: graphql_1.GraphQLID }, blocks: { type: new graphql_1.GraphQLNonNull(new graphql_1.GraphQLList(new graphql_1.GraphQLNonNull(blocks_1.GraphQLBlockInput))) } } }); exports.GraphQLArticleRevision = new graphql_1.GraphQLObjectType({ name: 'ArticleRevision', fields: { revision: { type: new graphql_1.GraphQLNonNull(graphql_1.GraphQLInt) }, createdAt: { type: new graphql_1.GraphQLNonNull(graphql_scalars_1.GraphQLDateTime) }, publishAt: { type: graphql_scalars_1.GraphQLDateTime }, updatedAt: { type: graphql_scalars_1.GraphQLDateTime }, publishedAt: { type: graphql_scalars_1.GraphQLDateTime }, hideAuthor: { type: new graphql_1.GraphQLNonNull(graphql_1.GraphQLBoolean) }, preTitle: { type: graphql_1.GraphQLString }, title: { type: graphql_1.GraphQLString }, lead: { type: graphql_1.GraphQLString }, seoTitle: { type: graphql_1.GraphQLString }, slug: { type: graphql_1.GraphQLString }, tags: { type: new graphql_1.GraphQLNonNull(new graphql_1.GraphQLList(new graphql_1.GraphQLNonNull(graphql_1.GraphQLString))) }, properties: { type: new graphql_1.GraphQLNonNull(new graphql_1.GraphQLList(new graphql_1.GraphQLNonNull(common_1.GraphQLMetadataProperty))) }, canonicalUrl: { type: graphql_1.GraphQLString }, url: { type: new graphql_1.GraphQLNonNull(graphql_1.GraphQLString), resolve: (0, utility_1.createProxyingResolver)((articleRevision, args, { urlAdapter }, info) => { var _a; // The URLAdapter expects a public article to generate the public article URL. // The URL should never be created with values from the updatedAt, publishAt // and publishedAt dates, but they are required by the method. return urlAdapter.getPublicArticleURL(Object.assign(Object.assign({}, articleRevision), { id: ((_a = info === null || info === void 0 ? void 0 : info.variableValues) === null || _a === void 0 ? void 0 : _a.id) || 'ID-DOES-NOT-EXIST', shared: true, updatedAt: new Date(), publishAt: new Date(), publishedAt: new Date() })); }) }, image: { type: image_1.GraphQLImage, resolve: (0, utility_1.createProxyingResolver)(({ imageID }, args, { loaders }) => { return imageID ? loaders.images.load(imageID) : null; }) }, authors: { type: new graphql_1.GraphQLNonNull(new graphql_1.GraphQLList(new graphql_1.GraphQLNonNull(author_1.GraphQLAuthor))), resolve: (0, utility_1.createProxyingResolver)(({ authors }, args, { loaders }) => tslib_1.__awaiter(void 0, void 0, void 0, function* () { return (yield loaders.authorsByID.loadMany(authors.map(({ authorId }) => authorId))).filter(Boolean); })) }, breaking: { type: new graphql_1.GraphQLNonNull(graphql_1.GraphQLBoolean) }, socialMediaTitle: { type: graphql_1.GraphQLString }, socialMediaDescription: { type: graphql_1.GraphQLString }, socialMediaAuthors: { type: new graphql_1.GraphQLNonNull(new graphql_1.GraphQLList(new graphql_1.GraphQLNonNull(author_1.GraphQLAuthor))), resolve: (0, utility_1.createProxyingResolver)(({ socialMediaAuthors }, args, { loaders }) => tslib_1.__awaiter(void 0, void 0, void 0, function* () { return (yield loaders.authorsByID.loadMany(socialMediaAuthors.map(({ authorId }) => authorId))).filter(Boolean); })) }, socialMediaImage: { type: image_1.GraphQLImage, resolve: (0, utility_1.createProxyingResolver)(({ socialMediaImageID }, args, { loaders }) => { return socialMediaImageID ? loaders.images.load(socialMediaImageID) : null; }) }, blocks: { type: new graphql_1.GraphQLNonNull(new graphql_1.GraphQLList(new graphql_1.GraphQLNonNull(blocks_1.GraphQLBlock))) } } }); exports.GraphQLArticle = new graphql_1.GraphQLObjectType({ name: 'Article', fields: { id: { type: new graphql_1.GraphQLNonNull(graphql_1.GraphQLID) }, shared: { type: new graphql_1.GraphQLNonNull(graphql_1.GraphQLBoolean) }, hidden: { type: graphql_1.GraphQLBoolean }, createdAt: { type: new graphql_1.GraphQLNonNull(graphql_scalars_1.GraphQLDateTime) }, modifiedAt: { type: new graphql_1.GraphQLNonNull(graphql_scalars_1.GraphQLDateTime) }, draft: { type: exports.GraphQLArticleRevision }, published: { type: exports.GraphQLArticleRevision }, pending: { type: exports.GraphQLArticleRevision }, latest: { type: new graphql_1.GraphQLNonNull(exports.GraphQLArticleRevision), resolve: (0, utility_1.createProxyingResolver)(({ draft, pending, published }) => { var _a; return (_a = draft !== null && draft !== void 0 ? draft : pending) !== null && _a !== void 0 ? _a : published; }) } } }); exports.GraphQLArticleConnection = new graphql_1.GraphQLObjectType({ name: 'ArticleConnection', fields: { nodes: { type: new graphql_1.GraphQLNonNull(new graphql_1.GraphQLList(new graphql_1.GraphQLNonNull(exports.GraphQLArticle))) }, pageInfo: { type: new graphql_1.GraphQLNonNull(common_1.GraphQLPageInfo) }, totalCount: { type: new graphql_1.GraphQLNonNull(graphql_1.GraphQLInt) } } }); exports.GraphQLPeerArticle = new graphql_1.GraphQLObjectType({ name: 'PeerArticle', fields: { peer: { type: new graphql_1.GraphQLNonNull(peer_1.GraphQLPeer), resolve: (0, utility_1.createProxyingResolver)(({ peerID }, _, { loaders }) => loaders.peer.load(peerID)) }, peeredArticleURL: { type: new graphql_1.GraphQLNonNull(graphql_1.GraphQLString), resolve: (0, utility_1.createProxyingResolver)(({ peerID, article }, _, { loaders, urlAdapter }) => tslib_1.__awaiter(void 0, void 0, void 0, function* () { const peer = yield loaders.peer.load(peerID); if (!peer || !article) return ''; return urlAdapter.getPeeredArticleURL(peer, article); })) }, article: { type: new graphql_1.GraphQLNonNull(exports.GraphQLArticle) } } }); exports.GraphQLPeerArticleConnection = new graphql_1.GraphQLObjectType({ name: 'PeerArticleConnection', fields: { nodes: { type: new graphql_1.GraphQLNonNull(new graphql_1.GraphQLList(new graphql_1.GraphQLNonNull(exports.GraphQLPeerArticle))) }, pageInfo: { type: new graphql_1.GraphQLNonNull(common_1.GraphQLUnidirectionalPageInfo) }, totalCount: { type: new graphql_1.GraphQLNonNull(graphql_1.GraphQLInt) } } }); exports.GraphQLPublicArticle = new graphql_1.GraphQLObjectType({ name: 'Article', fields: { id: { type: new graphql_1.GraphQLNonNull(graphql_1.GraphQLID) }, updatedAt: { type: new graphql_1.GraphQLNonNull(graphql_scalars_1.GraphQLDateTime) }, publishedAt: { type: new graphql_1.GraphQLNonNull(graphql_scalars_1.GraphQLDateTime) }, slug: { type: new graphql_1.GraphQLNonNull(slug_1.GraphQLSlug) }, url: { type: new graphql_1.GraphQLNonNull(graphql_1.GraphQLString), resolve: (0, utility_1.createProxyingResolver)((article, _, { urlAdapter }) => { return urlAdapter.getPublicArticleURL(article); }) }, peeredArticleURL: { type: graphql_1.GraphQLString }, preTitle: { type: graphql_1.GraphQLString }, title: { type: new graphql_1.GraphQLNonNull(graphql_1.GraphQLString) }, lead: { type: graphql_1.GraphQLString }, seoTitle: { type: graphql_1.GraphQLString }, tags: { type: new graphql_1.GraphQLNonNull(new graphql_1.GraphQLList(new graphql_1.GraphQLNonNull(graphql_1.GraphQLString))) }, canonicalUrl: { type: graphql_1.GraphQLString }, properties: { type: new graphql_1.GraphQLNonNull(new graphql_1.GraphQLList(new graphql_1.GraphQLNonNull(common_1.GraphQLMetadataPropertyPublic))), resolve: ({ properties }) => { return properties .filter(property => property.public) .map(({ key, value }) => ({ key, value })); } }, image: { type: image_1.GraphQLImage, resolve: (0, utility_1.createProxyingResolver)(({ imageID }, args, { loaders }) => { return imageID ? loaders.images.load(imageID) : null; }) }, authors: { type: new graphql_1.GraphQLNonNull(new graphql_1.GraphQLList(new graphql_1.GraphQLNonNull(author_1.GraphQLAuthor))), resolve: (0, utility_1.createProxyingResolver)(({ authors, hideAuthor }, args, { loaders }) => tslib_1.__awaiter(void 0, void 0, void 0, function* () { if (hideAuthor) { return []; } return (yield loaders.authorsByID.loadMany(authors.map(({ authorId }) => authorId))).filter(Boolean); })) }, breaking: { type: new graphql_1.GraphQLNonNull(graphql_1.GraphQLBoolean) }, socialMediaTitle: { type: graphql_1.GraphQLString }, socialMediaDescription: { type: graphql_1.GraphQLString }, socialMediaAuthors: { type: new graphql_1.GraphQLNonNull(new graphql_1.GraphQLList(new graphql_1.GraphQLNonNull(author_1.GraphQLAuthor))), resolve: (0, utility_1.createProxyingResolver)(({ socialMediaAuthors, hideAuthor }, args, { loaders }) => tslib_1.__awaiter(void 0, void 0, void 0, function* () { if (hideAuthor) { return []; } return (yield loaders.authorsByID.loadMany(socialMediaAuthors.map(({ authorId }) => authorId))).filter(Boolean); })) }, socialMediaImage: { type: image_1.GraphQLImage, resolve: (0, utility_1.createProxyingResolver)(({ socialMediaImageID }, args, { loaders }) => { return socialMediaImageID ? loaders.images.load(socialMediaImageID) : null; }) }, blocks: { type: new graphql_1.GraphQLNonNull(new graphql_1.GraphQLList(new graphql_1.GraphQLNonNull(blocks_1.GraphQLPublicBlock))) }, comments: { type: new graphql_1.GraphQLNonNull(new graphql_1.GraphQLList(new graphql_1.GraphQLNonNull(comment_1.GraphQLPublicComment))), resolve: (0, utility_1.createProxyingResolver)(({ id }, _, { session, prisma: { comment }, loaders: { commentRatingSystemAnswers } }) => tslib_1.__awaiter(void 0, void 0, void 0, function* () { 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.getPublicCommentsForItemById)(id, userId, null, api_2.SortOrder.Descending, commentRatingSystemAnswers, comment); })) } } }); exports.GraphQLPublicArticleConnection = new graphql_1.GraphQLObjectType({ name: 'ArticleConnection', fields: { nodes: { type: new graphql_1.GraphQLNonNull(new graphql_1.GraphQLList(new graphql_1.GraphQLNonNull(exports.GraphQLPublicArticle))) }, pageInfo: { type: new graphql_1.GraphQLNonNull(common_1.GraphQLPageInfo) }, totalCount: { type: new graphql_1.GraphQLNonNull(graphql_1.GraphQLInt) } } }); //# sourceMappingURL=article.js.map