• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

cofacts / rumors-api / 8974303076

06 May 2024 07:02PM UTC coverage: 88.312%. Remained the same
8974303076

push

github

web-flow
Merge pull request #336 from cofacts/typescript

Add Typescript support

771 of 931 branches covered (82.81%)

Branch coverage included in aggregate %.

1541 of 1687 relevant lines covered (91.35%)

22.93 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

72.73
/src/graphql/models/ArticleReply.js
1
import {
2
  GraphQLObjectType,
3
  GraphQLList,
4
  GraphQLInt,
5
  GraphQLString,
6
  GraphQLBoolean,
7
  GraphQLNonNull,
8
} from 'graphql';
9

10
import Article from './Article';
11
import User, { userFieldResolver } from './User';
12
import Reply from './Reply';
13
import ReplyTypeEnum from './ReplyTypeEnum';
14
import ArticleReplyFeedback from './ArticleReplyFeedback';
15
import ArticleReplyStatusEnum from './ArticleReplyStatusEnum';
16
import FeedbackVote from './FeedbackVote';
17
import ArticleReplyFeedbackStatusEnum from './ArticleReplyFeedbackStatusEnum';
18

19
import {
20
  DEFAULT_ARTICLE_REPLY_FEEDBACK_STATUSES,
21
  filterByStatuses,
22
} from 'graphql/util';
23

24
export default new GraphQLObjectType({
25
  name: 'ArticleReply',
26
  description: 'The linkage between an Article and a Reply',
27
  fields: () => ({
31✔
28
    replyId: { type: new GraphQLNonNull(GraphQLString) },
29

30
    reply: {
31
      type: Reply,
32
      resolve: ({ replyId }, args, { loaders }) =>
33
        loaders.docLoader.load({ index: 'replies', id: replyId }),
5✔
34
    },
35

36
    replyType: {
37
      type: ReplyTypeEnum,
38
      description: 'Cached reply type value stored in ArticleReply',
39
    },
40

41
    articleId: { type: new GraphQLNonNull(GraphQLString) },
42

43
    article: {
44
      type: Article,
45
      resolve: ({ articleId }, args, { loaders }) =>
46
        loaders.docLoader.load({ index: 'articles', id: articleId }),
7✔
47
    },
48

49
    user: {
50
      type: User,
51
      description: 'The user who conencted this reply and this article.',
52
      resolve: userFieldResolver,
53
    },
54

55
    userId: { type: GraphQLNonNull(GraphQLString) },
56
    appId: { type: GraphQLNonNull(GraphQLString) },
57

58
    canUpdateStatus: {
59
      type: new GraphQLNonNull(GraphQLBoolean),
60
      resolve: ({ userId, appId }, args, { user }) => {
61
        return !!user && userId === user.id && appId === user.appId;
2!
62
      },
63
    },
64

65
    feedbackCount: {
66
      type: new GraphQLNonNull(GraphQLInt),
67
      resolve: ({ positiveFeedbackCount = 0, negativeFeedbackCount = 0 }) =>
×
68
        positiveFeedbackCount + negativeFeedbackCount,
4✔
69
    },
70

71
    positiveFeedbackCount: {
72
      type: new GraphQLNonNull(GraphQLInt),
73
      resolve({ positiveFeedbackCount }) {
74
        return positiveFeedbackCount ?? 0;
11!
75
      },
76
    },
77
    negativeFeedbackCount: {
78
      type: new GraphQLNonNull(GraphQLInt),
79
      resolve({ negativeFeedbackCount }) {
80
        return negativeFeedbackCount ?? 0;
11!
81
      },
82
    },
83

84
    feedbacks: {
85
      type: new GraphQLNonNull(
86
        new GraphQLList(new GraphQLNonNull(ArticleReplyFeedback))
87
      ),
88
      args: {
89
        statuses: {
90
          type: new GraphQLList(
91
            new GraphQLNonNull(ArticleReplyFeedbackStatusEnum)
92
          ),
93
          defaultValue: DEFAULT_ARTICLE_REPLY_FEEDBACK_STATUSES,
94
          description:
95
            'Returns only aricle reply feedbacks with the specified statuses',
96
        },
97
      },
98
      resolve: async (
99
        { articleId, replyId },
100
        { statuses = DEFAULT_ARTICLE_REPLY_FEEDBACK_STATUSES },
×
101
        { loaders }
102
      ) =>
103
        filterByStatuses(
4✔
104
          await loaders.articleReplyFeedbacksLoader.load({
105
            articleId,
106
            replyId,
107
          }),
108
          statuses
109
        ),
110
    },
111

112
    ownVote: {
113
      type: FeedbackVote,
114
      description:
115
        'The feedback of current user. null when not logged in or not voted yet.',
116
      resolve: async ({ articleId, replyId }, args, { user, loaders }) => {
117
        if (!user) return null;
3!
118
        const feedbacks = await loaders.articleReplyFeedbacksLoader.load({
3✔
119
          articleId,
120
          replyId,
121
        });
122

123
        const ownFeedback = feedbacks.find(
3✔
124
          feedback =>
125
            feedback.userId === user.id && feedback.appId === user.appId
35✔
126
        );
127
        if (!ownFeedback) return null;
3!
128
        return ownFeedback.score;
3✔
129
      },
130
    },
131

132
    status: {
133
      type: new GraphQLNonNull(ArticleReplyStatusEnum),
134
      resolve: ({ status }) => (status === undefined ? 'NORMAL' : status),
12!
135
    },
136

137
    createdAt: {
138
      type: GraphQLString,
139
      description: 'May be null for legacy article-replies',
140
    },
141
    updatedAt: { type: GraphQLString },
142
  }),
143
});
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc