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

dev: add GraphQL Debug message to response when attempting to use Page.seo for the Posts Archive. #113

Merged
merged 2 commits into from
Aug 31, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

## [Unreleased]

- dev: Add GraphQL Debug message to response when attempting to use `Page.seo` for the Posts Archive. H/t @amoyanoakqa
- chore: Update Composer dev-deps.

## [0.3.2]
Expand Down
14 changes: 14 additions & 0 deletions src/Type/WPInterface/NodeWithSeo.php
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,20 @@ public static function get_fields(): array {
}

if ( empty( $source->uri ) ) {
/**
* This can occur when querying the `Posts` page, since the Model "casts" it as a `ContentType` due to the lack of archive support.
*
* @see \WPGraphQL\Model\Post::$uri
*/
if ( $source instanceof \WPGraphQL\Model\Post && $source->isPostsPage ) {
graphql_debug(
sprintf(
// translators: %d: The ID of the Post model being queried.
esc_html__( 'Post %d is configured as the Posts archive, but is being queried as a `Page`. To get the SEO data, please query the object as a `ContentType` (e.g. via `nodeByUri`).', 'wp-graphql-rank-math' ),
$source->databaseId,
)
);
}
return null;
}

Expand Down
Loading