Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: isPostsPage on content type #3048

Merged

Conversation

jasonbahl
Copy link
Collaborator

What does this implement/fix? Explain your changes.

This updates the ContentType.isPostsPage resolver to return true for the "Post" ContentType.

Does this close any currently open issues?

closes #2514

Any other comments?

BEFORE

isPostsPage and isFrontPage have to be separately queried for on Page and ContentType types, and isPostsPage returns false for the ContentType that is representing the Posts Page.

CleanShot 2024-02-16 at 13 04 41

AFTER

I can now query isFrontPage and isPostsPage as a field of the UniformResourceIdentifiable Type.

And now we see that isPostsPage appropriately returns true when a ContentType is returned as the posts page.

CleanShot 2024-02-16 at 13 03 01

…returns a `ContentType` that `isPostsPage` field returns true
…ble Interface as any node with a URI should be able to identify whether it is or is not the posts page or front page. Defaults to false, but individual implementing types (ContentType, Page) can override the resolver as applicable.

- update the PostType Model to return true if show_on_front is set to "page" and update Post model to return `false` for `isPostsPage` as a Post Object won't ever resolve as the posts page based on the current NodeResolver strategy (see: https://github.com/wp-graphql/wp-graphql/blob/develop/src/Data/NodeResolver.php#L226)

return false;
// the "post" ContentType is always represented as isPostsPage
return 'post' === $this->name;
Copy link

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.

@jasonbahl jasonbahl changed the title fix: 2514 is posts page on content type fix: 2514 is isPostsPage on content type Feb 16, 2024
@coveralls
Copy link

coveralls commented Feb 19, 2024

Coverage Status

coverage: 84.384% (+0.02%) from 84.366%
when pulling 7ca1dcd on jasonbahl:fix/2514-is-posts-page-on-content-type
into 54d0352 on wp-graphql:develop.

Copy link

codeclimate bot commented Feb 19, 2024

Code Climate has analyzed commit 7ca1dcd and detected 3 issues on this pull request.

Here's the issue category breakdown:

Category Count
Complexity 3

View more on Code Climate.

@jasonbahl jasonbahl changed the title fix: 2514 is isPostsPage on content type fix: isPostsPage on content type Feb 20, 2024
@jasonbahl jasonbahl merged commit b2712bd into wp-graphql:develop Feb 20, 2024
23 of 24 checks passed
@jasonbahl jasonbahl mentioned this pull request Feb 23, 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.

On ContentType union in nodeByUri returns incorrect isPostsPage
2 participants