From 257b4db088ca6e25b325a3e2ee80f35f3fd23120 Mon Sep 17 00:00:00 2001 From: David Levine Date: Sat, 31 Aug 2024 12:16:25 +0000 Subject: [PATCH 1/2] dev: add debug notice when querying for the posts archive as `Page` --- CHANGELOG.md | 1 + src/Type/WPInterface/NodeWithSeo.php | 14 ++++++++++++++ 2 files changed, 15 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 7d515e8..7df039e 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. - 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; } From 4b2af89f747c93cb3714cd53052aca5dc6362ea8 Mon Sep 17 00:00:00 2001 From: David Levine Date: Sat, 31 Aug 2024 12:16:34 +0000 Subject: [PATCH 2/2] chore: props --- CHANGELOG.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 7df039e..3431041 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,7 +2,7 @@ ## [Unreleased] -- dev: Add GraphQL Debug message to response when attempting to use `Page.seo` for the Posts Archive. +- 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]