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

wp-graphql / wp-graphql / 14716683875

28 Apr 2025 07:58PM UTC coverage: 84.287% (+1.6%) from 82.648%
14716683875

push

github

actions-user
release: merge develop into master for v2.3.0

15905 of 18870 relevant lines covered (84.29%)

257.23 hits per line

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

98.36
/src/Type/ObjectType/Comment.php
1
<?php
2

3
namespace WPGraphQL\Type\ObjectType;
4

5
use WPGraphQL\AppContext;
6
use WPGraphQL\Model\Comment as CommentModel;
7

8
/**
9
 * Class Comment
10
 *
11
 * @package WPGraphQL\Type\Object
12
 */
13
class Comment {
14

15
        /**
16
         * Register Comment Type
17
         *
18
         * @return void
19
         */
20
        public static function register_type() {
593✔
21
                register_graphql_object_type(
593✔
22
                        'Comment',
593✔
23
                        [
593✔
24
                                'description' => static function () {
593✔
25
                                        return __( 'A response or reaction to content submitted by users. Comments are typically associated with a specific content entry.', 'wp-graphql' );
18✔
26
                                },
593✔
27
                                'model'       => CommentModel::class,
593✔
28
                                'interfaces'  => [ 'Node', 'DatabaseIdentifier', 'UniformResourceIdentifiable' ],
593✔
29
                                'connections' => [
593✔
30
                                        'author' => [
593✔
31
                                                'toType'      => 'Commenter',
593✔
32
                                                'description' => static function () {
593✔
33
                                                        return __( 'The author of the comment', 'wp-graphql' );
18✔
34
                                                },
593✔
35
                                                'oneToOne'    => true,
593✔
36
                                                'edgeFields'  => [
593✔
37
                                                        'email'     => [
593✔
38
                                                                'type'        => 'String',
593✔
39
                                                                'description' => static function () {
593✔
40
                                                                        return __( 'The email address representing the author for this particular comment', 'wp-graphql' );
16✔
41
                                                                },
593✔
42
                                                                'resolve'     => static function ( $edge ) {
593✔
43
                                                                        return $edge['source']->commentAuthorEmail ?: null;
2✔
44
                                                                },
593✔
45
                                                        ],
593✔
46
                                                        'ipAddress' => [
593✔
47
                                                                'type'        => 'String',
593✔
48
                                                                'description' => static function () {
593✔
49
                                                                        return __( 'IP address of the author at the time of making this comment. This field is equivalent to WP_Comment->comment_author_IP and the value matching the "comment_author_IP" column in SQL.', 'wp-graphql' );
16✔
50
                                                                },
593✔
51
                                                                'resolve'     => static function ( $edge ) {
593✔
52
                                                                        return $edge['source']->authorIp ?: null;
×
53
                                                                },
593✔
54
                                                        ],
593✔
55
                                                        'name'      => [
593✔
56
                                                                'type'        => 'String',
593✔
57
                                                                'description' => static function () {
593✔
58
                                                                        return __( 'The display name of the comment author for this particular comment', 'wp-graphql' );
16✔
59
                                                                },
593✔
60
                                                                'resolve'     => static function ( $edge ) {
593✔
61
                                                                        return $edge['source']->commentAuthor;
2✔
62
                                                                },
593✔
63
                                                        ],
593✔
64
                                                        'url'       => [
593✔
65
                                                                'type'        => 'String',
593✔
66
                                                                'description' => static function () {
593✔
67
                                                                        return __( 'The url entered for the comment author on this particular comment', 'wp-graphql' );
16✔
68
                                                                },
593✔
69
                                                                'resolve'     => static function ( $edge ) {
593✔
70
                                                                        return $edge['source']->commentAuthorUrl ?: null;
2✔
71
                                                                },
593✔
72
                                                        ],
593✔
73
                                                ],
593✔
74
                                                'resolve'     => static function ( $comment, $_args, AppContext $context ) {
593✔
75
                                                        $node = null;
9✔
76

77
                                                        // try and load the user node
78
                                                        if ( ! empty( $comment->userId ) ) {
9✔
79
                                                                $node = $context->get_loader( 'user' )->load( absint( $comment->userId ) );
6✔
80
                                                        }
81

82
                                                        // If no node is loaded, fallback to the
83
                                                        // public comment author data
84
                                                        if ( ! $node || ( true === $node->isPrivate ) ) {
9✔
85
                                                                $node = ! empty( $comment->commentId ) ? $context->get_loader( 'comment_author' )->load( $comment->commentId ) : null;
5✔
86
                                                        }
87

88
                                                        return [
9✔
89
                                                                'node'   => $node,
9✔
90
                                                                'source' => $comment,
9✔
91
                                                        ];
9✔
92
                                                },
593✔
93
                                        ],
593✔
94
                                ],
593✔
95
                                'fields'      => static function () {
593✔
96
                                        return [
138✔
97
                                                'agent'            => [
138✔
98
                                                        'type'        => 'String',
138✔
99
                                                        'description' => static function () {
138✔
100
                                                                return __( 'User agent used to post the comment. This field is equivalent to WP_Comment->comment_agent and the value matching the "comment_agent" column in SQL.', 'wp-graphql' );
18✔
101
                                                        },
138✔
102
                                                ],
138✔
103
                                                'approved'         => [
138✔
104
                                                        'type'              => 'Boolean',
138✔
105
                                                        'description'       => static function () {
138✔
106
                                                                return __( 'The approval status of the comment. This field is equivalent to WP_Comment->comment_approved and the value matching the "comment_approved" column in SQL.', 'wp-graphql' );
18✔
107
                                                        },
138✔
108
                                                        'deprecationReason' => __( 'Deprecated in favor of the `status` field', 'wp-graphql' ),
138✔
109
                                                        'resolve'           => static function ( $comment ) {
138✔
110
                                                                return 'approve' === $comment->status;
×
111
                                                        },
138✔
112
                                                ],
138✔
113
                                                'authorIp'         => [
138✔
114
                                                        'type'              => 'String',
138✔
115
                                                        'deprecationReason' => __( 'Use the ipAddress field on the edge between the comment and author', 'wp-graphql' ),
138✔
116
                                                        'description'       => static function () {
138✔
117
                                                                return __( 'IP address for the author at the time of commenting. This field is equivalent to WP_Comment->comment_author_IP and the value matching the "comment_author_IP" column in SQL.', 'wp-graphql' );
18✔
118
                                                        },
138✔
119
                                                ],
138✔
120
                                                'commentId'        => [
138✔
121
                                                        'type'              => 'Int',
138✔
122
                                                        'description'       => static function () {
138✔
123
                                                                return __( 'ID for the comment, unique among comments.', 'wp-graphql' );
18✔
124
                                                        },
138✔
125
                                                        'deprecationReason' => static function () {
138✔
126
                                                                return __( 'Deprecated in favor of databaseId', 'wp-graphql' );
18✔
127
                                                        },
138✔
128
                                                ],
138✔
129
                                                'content'          => [
138✔
130
                                                        'type'        => 'String',
138✔
131
                                                        'description' => static function () {
138✔
132
                                                                return __( 'Content of the comment. This field is equivalent to WP_Comment->comment_content and the value matching the "comment_content" column in SQL.', 'wp-graphql' );
18✔
133
                                                        },
138✔
134
                                                        'args'        => [
138✔
135
                                                                'format' => [
138✔
136
                                                                        'type'        => 'PostObjectFieldFormatEnum',
138✔
137
                                                                        'description' => static function () {
138✔
138
                                                                                return __( 'Format of the field output', 'wp-graphql' );
18✔
139
                                                                        },
138✔
140
                                                                ],
138✔
141
                                                        ],
138✔
142
                                                        'resolve'     => static function ( \WPGraphQL\Model\Comment $comment, $args ) {
138✔
143
                                                                if ( isset( $args['format'] ) && 'raw' === $args['format'] ) {
30✔
144
                                                                        return isset( $comment->contentRaw ) ? $comment->contentRaw : null;
×
145
                                                                } else {
146
                                                                        return isset( $comment->contentRendered ) ? $comment->contentRendered : null;
30✔
147
                                                                }
148
                                                        },
138✔
149
                                                ],
138✔
150
                                                'date'             => [
138✔
151
                                                        'type'        => 'String',
138✔
152
                                                        'description' => static function () {
138✔
153
                                                                return __( 'Date the comment was posted in local time. This field is equivalent to WP_Comment->date and the value matching the "date" column in SQL.', 'wp-graphql' );
18✔
154
                                                        },
138✔
155
                                                ],
138✔
156
                                                'dateGmt'          => [
138✔
157
                                                        'type'        => 'String',
138✔
158
                                                        'description' => static function () {
138✔
159
                                                                return __( 'Date the comment was posted in GMT. This field is equivalent to WP_Comment->date_gmt and the value matching the "date_gmt" column in SQL.', 'wp-graphql' );
18✔
160
                                                        },
138✔
161
                                                ],
138✔
162
                                                'id'               => [
138✔
163
                                                        'description' => static function () {
138✔
164
                                                                return __( 'The globally unique identifier for the comment object', 'wp-graphql' );
18✔
165
                                                        },
138✔
166
                                                ],
138✔
167
                                                'isRestricted'     => [
138✔
168
                                                        'type'        => 'Boolean',
138✔
169
                                                        'description' => static function () {
138✔
170
                                                                return __( 'Whether the object is restricted from the current viewer', 'wp-graphql' );
18✔
171
                                                        },
138✔
172
                                                ],
138✔
173
                                                'karma'            => [
138✔
174
                                                        'type'        => 'Int',
138✔
175
                                                        'description' => static function () {
138✔
176
                                                                return __( 'Karma value for the comment. This field is equivalent to WP_Comment->comment_karma and the value matching the "comment_karma" column in SQL.', 'wp-graphql' );
18✔
177
                                                        },
138✔
178
                                                ],
138✔
179
                                                'link'             => [
138✔
180
                                                        'type'        => 'String',
138✔
181
                                                        'description' => static function () {
138✔
182
                                                                return __( 'The permalink of the comment', 'wp-graphql' );
18✔
183
                                                        },
138✔
184
                                                ],
138✔
185
                                                'parentId'         => [
138✔
186
                                                        'type'        => 'ID',
138✔
187
                                                        'description' => static function () {
138✔
188
                                                                return __( 'The globally unique identifier of the parent comment node.', 'wp-graphql' );
18✔
189
                                                        },
138✔
190
                                                ],
138✔
191
                                                'parentDatabaseId' => [
138✔
192
                                                        'type'        => 'Int',
138✔
193
                                                        'description' => static function () {
138✔
194
                                                                return __( 'The database id of the parent comment node or null if it is the root comment', 'wp-graphql' );
18✔
195
                                                        },
138✔
196
                                                ],
138✔
197
                                                'status'           => [
138✔
198
                                                        'type'        => 'CommentStatusEnum',
138✔
199
                                                        'description' => static function () {
138✔
200
                                                                return __( 'The approval status of the comment. This field is equivalent to WP_Comment->comment_approved and the value matching the "comment_approved" column in SQL.', 'wp-graphql' );
18✔
201
                                                        },
138✔
202
                                                ],
138✔
203
                                                'type'             => [
138✔
204
                                                        'type'        => 'String',
138✔
205
                                                        'description' => static function () {
138✔
206
                                                                return __( 'Type of comment. This field is equivalent to WP_Comment->comment_type and the value matching the "comment_type" column in SQL.', 'wp-graphql' );
18✔
207
                                                        },
138✔
208
                                                ],
138✔
209
                                        ];
138✔
210
                                },
593✔
211
                        ]
593✔
212
                );
593✔
213
        }
214
}
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

© 2025 Coveralls, Inc