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

wp-graphql / wp-graphql / #814

19 Sep 2024 05:27PM UTC coverage: 84.035% (-0.1%) from 84.174%
#814

push

php-coveralls

web-flow
Merge pull request #3215 from wp-graphql/release/v1.29.0

release: v1.29.0

47 of 55 new or added lines in 5 files covered. (85.45%)

27 existing lines in 1 file now uncovered.

12533 of 14914 relevant lines covered (84.04%)

308.34 hits per line

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

97.76
/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() {
21
                register_graphql_object_type(
582✔
22
                        'Comment',
582✔
23
                        [
582✔
24
                                'description' => __( 'A Comment object', 'wp-graphql' ),
582✔
25
                                'model'       => CommentModel::class,
582✔
26
                                'interfaces'  => [ 'Node', 'DatabaseIdentifier', 'UniformResourceIdentifiable' ],
582✔
27
                                'connections' => [
582✔
28
                                        'author' => [
582✔
29
                                                'toType'      => 'Commenter',
582✔
30
                                                'description' => __( 'The author of the comment', 'wp-graphql' ),
582✔
31
                                                'oneToOne'    => true,
582✔
32
                                                'edgeFields'  => [
582✔
33
                                                        'email'     => [
582✔
34
                                                                'type'        => 'String',
582✔
35
                                                                'description' => __( 'The email address representing the author for this particular comment', 'wp-graphql' ),
582✔
36
                                                                'resolve'     => static function ( $edge ) {
582✔
37
                                                                        return $edge['source']->commentAuthorEmail ?: null;
2✔
38
                                                                },
582✔
39
                                                        ],
582✔
40
                                                        'ipAddress' => [
582✔
41
                                                                'type'        => 'String',
582✔
42
                                                                'description' => __( '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' ),
582✔
43
                                                                'resolve'     => static function ( $edge ) {
582✔
NEW
44
                                                                        return $edge['source']->authorIp ?: null;
×
45
                                                                },
582✔
46
                                                        ],
582✔
47
                                                        'name'      => [
582✔
48
                                                                'type'        => 'String',
582✔
49
                                                                'description' => __( 'The display name of the comment author for this particular comment', 'wp-graphql' ),
582✔
50
                                                                'resolve'     => static function ( $edge ) {
582✔
51
                                                                        return $edge['source']->commentAuthor;
2✔
52
                                                                },
582✔
53
                                                        ],
582✔
54
                                                        'url'       => [
582✔
55
                                                                'type'        => 'String',
582✔
56
                                                                'description' => __( 'The url entered for the comment author on this particular comment', 'wp-graphql' ),
582✔
57
                                                                'resolve'     => static function ( $edge ) {
582✔
58
                                                                        return $edge['source']->commentAuthorUrl ?: null;
2✔
59
                                                                },
582✔
60
                                                        ],
582✔
61
                                                ],
582✔
62
                                                'resolve'     => static function ( $comment, $_args, AppContext $context ) {
582✔
63
                                                        $node = null;
8✔
64

65
                                                        // try and load the user node
66
                                                        if ( ! empty( $comment->userId ) ) {
8✔
67
                                                                $node = $context->get_loader( 'user' )->load( absint( $comment->userId ) );
6✔
68
                                                        }
69

70
                                                        // If no node is loaded, fallback to the
71
                                                        // public comment author data
72
                                                        if ( ! $node || ( true === $node->isPrivate ) ) {
8✔
73
                                                                $node = ! empty( $comment->commentId ) ? $context->get_loader( 'comment_author' )->load( $comment->commentId ) : null;
4✔
74
                                                        }
75

76
                                                        return [
8✔
77
                                                                'node'   => $node,
8✔
78
                                                                'source' => $comment,
8✔
79
                                                        ];
8✔
80
                                                },
582✔
81
                                        ],
582✔
82
                                ],
582✔
83
                                'fields'      => [
582✔
84
                                        'agent'            => [
582✔
85
                                                'type'        => 'String',
582✔
86
                                                'description' => __( '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' ),
582✔
87
                                        ],
582✔
88
                                        'approved'         => [
582✔
89
                                                'type'              => 'Boolean',
582✔
90
                                                'description'       => __( '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' ),
582✔
91
                                                'deprecationReason' => __( 'Deprecated in favor of the `status` field', 'wp-graphql' ),
582✔
92
                                                'resolve'           => static function ( $comment ) {
582✔
93
                                                        return 'approve' === $comment->status;
×
94
                                                },
582✔
95
                                        ],
582✔
96
                                        'authorIp'         => [
582✔
97
                                                'type'              => 'String',
582✔
98
                                                'deprecationReason' => __( 'Use the ipAddress field on the edge between the comment and author', 'wp-graphql' ),
582✔
99
                                                'description'       => __( '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' ),
582✔
100
                                        ],
582✔
101
                                        'commentId'        => [
582✔
102
                                                'type'              => 'Int',
582✔
103
                                                'description'       => __( 'ID for the comment, unique among comments.', 'wp-graphql' ),
582✔
104
                                                'deprecationReason' => __( 'Deprecated in favor of databaseId', 'wp-graphql' ),
582✔
105
                                        ],
582✔
106
                                        'content'          => [
582✔
107
                                                'type'        => 'String',
582✔
108
                                                'description' => __( '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' ),
582✔
109
                                                'args'        => [
582✔
110
                                                        'format' => [
582✔
111
                                                                'type'        => 'PostObjectFieldFormatEnum',
582✔
112
                                                                'description' => __( 'Format of the field output', 'wp-graphql' ),
582✔
113
                                                        ],
582✔
114
                                                ],
582✔
115
                                                'resolve'     => static function ( \WPGraphQL\Model\Comment $comment, $args ) {
582✔
116
                                                        if ( isset( $args['format'] ) && 'raw' === $args['format'] ) {
27✔
117
                                                                return isset( $comment->contentRaw ) ? $comment->contentRaw : null;
×
118
                                                        } else {
119
                                                                return isset( $comment->contentRendered ) ? $comment->contentRendered : null;
27✔
120
                                                        }
121
                                                },
582✔
122
                                        ],
582✔
123
                                        'date'             => [
582✔
124
                                                'type'        => 'String',
582✔
125
                                                'description' => __( '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' ),
582✔
126
                                        ],
582✔
127
                                        'dateGmt'          => [
582✔
128
                                                'type'        => 'String',
582✔
129
                                                'description' => __( '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' ),
582✔
130
                                        ],
582✔
131
                                        'id'               => [
582✔
132
                                                'description' => __( 'The globally unique identifier for the comment object', 'wp-graphql' ),
582✔
133
                                        ],
582✔
134
                                        'isRestricted'     => [
582✔
135
                                                'type'        => 'Boolean',
582✔
136
                                                'description' => __( 'Whether the object is restricted from the current viewer', 'wp-graphql' ),
582✔
137
                                        ],
582✔
138
                                        'karma'            => [
582✔
139
                                                'type'        => 'Int',
582✔
140
                                                'description' => __( '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' ),
582✔
141
                                        ],
582✔
142
                                        'link'             => [
582✔
143
                                                'type'        => 'String',
582✔
144
                                                'description' => __( 'The permalink of the comment', 'wp-graphql' ),
582✔
145
                                        ],
582✔
146
                                        'parentId'         => [
582✔
147
                                                'type'        => 'ID',
582✔
148
                                                'description' => __( 'The globally unique identifier of the parent comment node.', 'wp-graphql' ),
582✔
149
                                        ],
582✔
150
                                        'parentDatabaseId' => [
582✔
151
                                                'type'        => 'Int',
582✔
152
                                                'description' => __( 'The database id of the parent comment node or null if it is the root comment', 'wp-graphql' ),
582✔
153
                                        ],
582✔
154
                                        'status'           => [
582✔
155
                                                'type'        => 'CommentStatusEnum',
582✔
156
                                                'description' => __( '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' ),
582✔
157
                                        ],
582✔
158
                                        'type'             => [
582✔
159
                                                'type'        => 'String',
582✔
160
                                                'description' => __( 'Type of comment. This field is equivalent to WP_Comment->comment_type and the value matching the "comment_type" column in SQL.', 'wp-graphql' ),
582✔
161
                                        ],
582✔
162
                                ],
582✔
163
                        ]
582✔
164
                );
582✔
165
        }
166
}
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