@wepublish/api
Version:
API core for we.publish.
142 lines • 6.12 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.GraphQLAction = void 0;
const tslib_1 = require("tslib");
const graphql_1 = require("graphql");
const graphql_scalars_1 = require("graphql-scalars");
const action_1 = require("../db/action");
const page_1 = require("./page");
const poll_1 = require("./poll/poll");
const article_1 = require("./article");
const author_1 = require("./author");
const comment_1 = require("./comment/comment");
const subscription_1 = require("./subscription");
const user_1 = require("./user");
const event_1 = require("./event/event");
const actionFields = {
date: { type: new graphql_1.GraphQLNonNull(graphql_scalars_1.GraphQLDateTime) }
};
const GraphQLArticleCreatedAction = new graphql_1.GraphQLObjectType({
name: 'ArticleCreatedAction',
fields: Object.assign(Object.assign({}, actionFields), { article: {
type: new graphql_1.GraphQLNonNull(article_1.GraphQLArticle),
resolve({ id }, args, { loaders }) {
return tslib_1.__awaiter(this, void 0, void 0, function* () {
return yield loaders.articles.load(id);
});
}
} })
});
const GraphQLPageCreatedAction = new graphql_1.GraphQLObjectType({
name: 'PageCreatedAction',
fields: Object.assign(Object.assign({}, actionFields), { page: {
type: new graphql_1.GraphQLNonNull(page_1.GraphQLPage),
resolve({ id }, args, { loaders }) {
return tslib_1.__awaiter(this, void 0, void 0, function* () {
return yield loaders.pages.load(id);
});
}
} })
});
const GraphQLCommentCreatedAction = new graphql_1.GraphQLObjectType({
name: 'CommentCreatedAction',
fields: Object.assign(Object.assign({}, actionFields), { comment: {
type: new graphql_1.GraphQLNonNull(comment_1.GraphQLComment),
resolve({ id }, args, { loaders }) {
return tslib_1.__awaiter(this, void 0, void 0, function* () {
return yield loaders.commentsById.load(id);
});
}
} })
});
const GraphQLPollStartedAction = new graphql_1.GraphQLObjectType({
name: 'PollStartedAction',
fields: Object.assign(Object.assign({}, actionFields), { poll: {
type: new graphql_1.GraphQLNonNull(poll_1.GraphQLPoll),
resolve({ id }, args, { loaders }) {
return tslib_1.__awaiter(this, void 0, void 0, function* () {
return yield loaders.pollById.load(id);
});
}
} })
});
const GraphQLSubscriptionCreatedAction = new graphql_1.GraphQLObjectType({
name: 'SubscriptionCreatedAction',
fields: Object.assign(Object.assign({}, actionFields), { subscription: {
type: new graphql_1.GraphQLNonNull(subscription_1.GraphQLSubscription),
resolve({ id }, args, { loaders }) {
return tslib_1.__awaiter(this, void 0, void 0, function* () {
return yield loaders.subscriptionsById.load(id);
});
}
} })
});
const GraphQLAuthorCreatedAction = new graphql_1.GraphQLObjectType({
name: 'AuthorCreatedAction',
fields: Object.assign(Object.assign({}, actionFields), { author: {
type: new graphql_1.GraphQLNonNull(author_1.GraphQLAuthor),
resolve({ id }, args, { loaders }) {
return tslib_1.__awaiter(this, void 0, void 0, function* () {
return yield loaders.authorsByID.load(id);
});
}
} })
});
const GraphQLUserCreatedAction = new graphql_1.GraphQLObjectType({
name: 'UserCreatedAction',
fields: Object.assign(Object.assign({}, actionFields), { user: {
type: new graphql_1.GraphQLNonNull(user_1.GraphQLUser),
resolve({ id }, args, { loaders }) {
return tslib_1.__awaiter(this, void 0, void 0, function* () {
return yield loaders.usersById.load(id);
});
}
} })
});
const GraphQLEventCreatedAction = new graphql_1.GraphQLObjectType({
name: 'EventCreatedAction',
fields: Object.assign(Object.assign({}, actionFields), { event: {
type: new graphql_1.GraphQLNonNull(event_1.GraphQLEvent),
resolve({ id }, args, { loaders }) {
return tslib_1.__awaiter(this, void 0, void 0, function* () {
return yield loaders.eventById.load(id);
});
}
} })
});
exports.GraphQLAction = new graphql_1.GraphQLUnionType({
name: 'Action',
types: [
GraphQLArticleCreatedAction,
GraphQLPageCreatedAction,
GraphQLCommentCreatedAction,
GraphQLPollStartedAction,
GraphQLSubscriptionCreatedAction,
GraphQLAuthorCreatedAction,
GraphQLUserCreatedAction,
GraphQLEventCreatedAction
],
resolveType(value) {
return tslib_1.__awaiter(this, void 0, void 0, function* () {
switch (value.actionType) {
case action_1.ActionType.ArticleCreated:
return GraphQLArticleCreatedAction.name;
case action_1.ActionType.PageCreated:
return GraphQLPageCreatedAction.name;
case action_1.ActionType.CommentCreated:
return GraphQLCommentCreatedAction.name;
case action_1.ActionType.PollStarted:
return GraphQLPollStartedAction.name;
case action_1.ActionType.SubscriptionCreated:
return GraphQLSubscriptionCreatedAction.name;
case action_1.ActionType.AuthorCreated:
return GraphQLAuthorCreatedAction.name;
case action_1.ActionType.UserCreated:
return GraphQLUserCreatedAction.name;
case action_1.ActionType.EventCreated:
return GraphQLEventCreatedAction.name;
}
});
}
});
//# sourceMappingURL=action.js.map