Skip to content

Commit

Permalink
dev: add GraphQL Debug message to response when attempting to use `Pa…
Browse files Browse the repository at this point in the history
…ge.seo` for the Posts Archive. (#113)

* dev: add debug notice when querying for the posts archive as `Page`

* chore: props
  • Loading branch information
justlevine authored Aug 31, 2024
1 parent be44374 commit 1cf41e1
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 0 deletions.
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

0 comments on commit 1cf41e1

Please sign in to comment.