Skip to content

Conversation

justlevine
Copy link
Collaborator

@justlevine justlevine commented Apr 19, 2025

What does this implement/fix? Explain your changes.

This PR cleans up the existing WPGraphQL Models in the following ways:

  • Fixes the model @property tags and sorts them.
  • Sorts the model fields (cosmetic, to make the diff's easier to read now and in the future)
  • Fixes individual model resolvers, either where the current return type could throw an error, or where they were "aliases" of other fields.
  • Replaced internal references to "alias fields" with their source of truth.
  • Fixes all references to model fields (exposed now that the types were fixed and better enforced).

As a result, we're also able to begin enforcing traversable types on new code via PHPStan.

Additional benefits:

  • Better types mean better usage with llms
  • Cleanup now paves the way for more important changes (breaking or nonbreaking) with smaller diffs.

Important

This PR is based on #3362 which should be merged first.

Relevant diffs:

  • Cleanup/fix the model fields: c5c58fc
  • Fix references to model fields: ca4b806
  • Avoid using alias field references: c2200a8

@coveralls
Copy link

Coverage Status

coverage: 82.665% (+0.06%) from 82.607%
when pulling ba5e717 on justlevine:fix/cleanup-model-resolvers
into b82f17c on wp-graphql:develop.

@justlevine justlevine added status: in review Awaiting review before merging or closing needs: reviewer response This needs the attention of a codeowner or maintainer type: chore Maintenance tasks, refactoring, and other non-functional changes labels Apr 19, 2025
@justlevine justlevine requested a review from jasonbahl April 19, 2025 18:19
return 'revision' === $this->data->post_type;
},
'isSticky' => function () {
return is_sticky( $this->data->ID );

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->post_parent ) ? absint( $this->data->post_parent ) : null;
},
'parentId' => function () {
return ( ! empty( $this->data->post_type ) && ! empty( $this->parentDatabaseId ) ) ? Relay::toGlobalId( 'post', (string) $this->parentDatabaseId ) : 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.

'pinged' => function () {
$punged = get_pung( $this->data->ID );

return empty( $punged ) ? null : implode( ',', (array) $punged );

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->previewRevisionDatabaseId ) ? Relay::toGlobalId( 'post', (string) $this->previewRevisionDatabaseId ) : null;
// Aliases.
'ID' => function () {
return $this->databaseId;

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 false;
'post_author' => function () {
return $this->authorDatabaseId;

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.

Copy link

Code Climate has analyzed commit 13b15ca and detected 53 issues on this pull request.

Here's the issue category breakdown:

Category Count
Complexity 53

View more on Code Climate.

@jasonbahl jasonbahl merged commit 2466c3b into wp-graphql:develop Apr 22, 2025
36 of 37 checks passed
@justlevine justlevine deleted the fix/cleanup-model-resolvers branch April 23, 2025 05:59
pull bot pushed a commit to Zezo-Ai/wp-graphql that referenced this pull request Apr 23, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
needs: reviewer response This needs the attention of a codeowner or maintainer status: in review Awaiting review before merging or closing type: chore Maintenance tasks, refactoring, and other non-functional changes
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants