Skip to content

Conversation

@jasonbahl
Copy link
Collaborator

@jasonbahl jasonbahl commented Sep 10, 2024

What does this implement/fix? Explain your changes.

This introduces new fields on the "Edge" on the CommentToCommenter connection:

  • name: The display name of the comment author for this particular comment
  • url: The url entered for the comment author on this particular comment
  • email: The email address representing the author for this particular comment
  • ipAddress: IP address of the author at the time of making this comment.

This allows for the relational data between a Commenter and the Comment to be queried for, in addition to the Commenter node itself.

Why?

Comment Authors can be represented by both their User object data and conditional data related to a specific comment.

By exposing this edge data, the client application can combine data from the User node and the Comment.author edge fields to provide a UI matching similar UIs as the WordPress Dashboard.

For example:

In the WordPress Dashboard, when moderating comments, the Author is represented as a mix of a User and comment-specific data.

With these edge fields, we can now query the User that authored the comment as well as the conditional fields specific to the comment:

CleanShot 2024-09-10 at 13 20 53

With this data queried at the edge between the Comment and the Author, we could create a UI similar to what is displayed in the WP Admin, where we see some information (avatar, etc) from the User node, and some information (commenter's name) in place of the User's information:

CleanShot 2024-09-10 at 13 19 25

Does this close any currently open issues?

closes #3197

- refactor WPGraphQL\AdminNotices to be a singleton
- instantiate AdminNotices the singleton
- expose commentAuthorUrl, commentAuthorEmail and commentAuthor on the Comment model as allowed restricted fields
- add name, email, url as edge fields on the CommentToCommenter Connection
- test the new edge fields
@jasonbahl jasonbahl self-assigned this Sep 10, 2024
},
'comment_author' => function () {
return ! empty( $this->data->comment_author ) ? absint( $this->data->comment_author ) : null;
return ! empty( $this->data->comment_author ) ? $this->data->comment_author : null;

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Avoid too many return statements within this method.

},
'comment_author_url' => function () {
return ! empty( $this->data->comment_author_url ) ? absint( $this->data->comment_author_url ) : null;
return ! empty( $this->data->comment_author_url ) ? $this->data->comment_author_url : null;

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Avoid too many return statements within this method.

return ! empty( $this->data->comment_author_url ) ? $this->data->comment_author_url : null;
},
'commentAuthor' => function () {
return ! empty( $this->data->comment_author ) ? $this->data->comment_author : null;

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Avoid too many return statements within this method.

return ! empty( $this->data->comment_author ) ? $this->data->comment_author : null;
},
'commentAuthorUrl' => function () {
return ! empty( $this->data->comment_author_url ) ? $this->data->comment_author_url : null;

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Avoid too many return statements within this method.

@coveralls
Copy link

coveralls commented Sep 10, 2024

Coverage Status

coverage: 84.035% (-0.1%) from 84.176%
when pulling 22793d1 on jasonbahl:feat/expose-commenter-edge-fields
into d3542ef on wp-graphql:develop.

- add ipAddress field
@qlty-cloud-legacy
Copy link

Code Climate has analyzed commit 22793d1 and detected 8 issues on this pull request.

Here's the issue category breakdown:

Category Count
Complexity 8

View more on Code Climate.

Copy link
Member

@josephfusco josephfusco left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

CleanShot 2024-09-12 at 13 38 49@2x
I'm able too see the commenter fields using the same query provided in the PR 🎉

@jasonbahl jasonbahl merged commit eaef11f into wp-graphql:develop Sep 12, 2024
@jasonbahl jasonbahl mentioned this pull request Sep 19, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

CommentAuthor no longer returning the name set in comment_author for comments by non-anonymous users

3 participants