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

cofacts / rumors-api / 5892775065

17 Aug 2023 03:17PM UTC coverage: 88.141% (-0.08%) from 88.218%
5892775065

push

github

web-flow
Merge pull request #312 from cofacts/compress-logs

feat: record less bytes in GraphQL request

707 of 855 branches covered (82.69%)

Branch coverage included in aggregate %.

2 of 2 new or added lines in 1 file covered. (100.0%)

1441 of 1582 relevant lines covered (91.09%)

22.94 hits per line

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

74.07
/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: () => ({
30✔
28
    replyId: { type: 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: 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: GraphQLBoolean,
60
      resolve: ({ userId, appId }, args, { user }) => {
61
        return !!user && userId === user.id && appId === user.appId;
2!
62
      },
63
    },
64

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

71
    positiveFeedbackCount: { type: GraphQLInt },
72
    negativeFeedbackCount: { type: GraphQLInt },
73

74
    feedbacks: {
75
      type: new GraphQLList(ArticleReplyFeedback),
76
      args: {
77
        statuses: {
78
          type: new GraphQLList(
79
            new GraphQLNonNull(ArticleReplyFeedbackStatusEnum)
80
          ),
81
          defaultValue: DEFAULT_ARTICLE_REPLY_FEEDBACK_STATUSES,
82
          description:
83
            'Returns only aricle reply feedbacks with the specified statuses',
84
        },
85
      },
86
      resolve: async (
87
        { articleId, replyId },
88
        { statuses = DEFAULT_ARTICLE_REPLY_FEEDBACK_STATUSES },
×
89
        { loaders }
90
      ) =>
91
        filterByStatuses(
4✔
92
          await loaders.articleReplyFeedbacksLoader.load({
93
            articleId,
94
            replyId,
95
          }),
96
          statuses
97
        ),
98
    },
99

100
    ownVote: {
101
      type: FeedbackVote,
102
      description:
103
        'The feedback of current user. null when not logged in or not voted yet.',
104
      resolve: async ({ articleId, replyId }, args, { user, loaders }) => {
105
        if (!user) return null;
3!
106
        const feedbacks = await loaders.articleReplyFeedbacksLoader.load({
3✔
107
          articleId,
108
          replyId,
109
        });
110

111
        const ownFeedback = feedbacks.find(
3✔
112
          feedback =>
113
            feedback.userId === user.id && feedback.appId === user.appId
35✔
114
        );
115
        if (!ownFeedback) return null;
3!
116
        return ownFeedback.score;
3✔
117
      },
118
    },
119

120
    status: {
121
      type: ArticleReplyStatusEnum,
122
      resolve: ({ status }) => (status === undefined ? 'NORMAL' : status),
12!
123
    },
124

125
    createdAt: { type: GraphQLString },
126
    updatedAt: { type: GraphQLString },
127
  }),
128
});
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