From 1cf41e140fb2c8b810cdb4dc93f6befec9bf482a Mon Sep 17 00:00:00 2001 From: Dovid Levine Date: Sat, 31 Aug 2024 15:31:28 +0300 Subject: [PATCH] dev: add GraphQL Debug message to response when attempting to use `Page.seo` for the Posts Archive. (#113) * dev: add debug notice when querying for the posts archive as `Page` * chore: props --- CHANGELOG.md | 1 + src/Type/WPInterface/NodeWithSeo.php | 14 ++++++++++++++ 2 files changed, 15 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 7d515e8..3431041 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -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] diff --git a/src/Type/WPInterface/NodeWithSeo.php b/src/Type/WPInterface/NodeWithSeo.php index d2b6f44..29a33b6 100644 --- a/src/Type/WPInterface/NodeWithSeo.php +++ b/src/Type/WPInterface/NodeWithSeo.php @@ -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; }