Skip to content

Commit 1cf41e1

Browse files
authored
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
1 parent be44374 commit 1cf41e1

File tree

2 files changed

+15
-0
lines changed

2 files changed

+15
-0
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
## [Unreleased]
44

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

78
## [0.3.2]

src/Type/WPInterface/NodeWithSeo.php

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -87,6 +87,20 @@ public static function get_fields(): array {
8787
}
8888

8989
if ( empty( $source->uri ) ) {
90+
/**
91+
* This can occur when querying the `Posts` page, since the Model "casts" it as a `ContentType` due to the lack of archive support.
92+
*
93+
* @see \WPGraphQL\Model\Post::$uri
94+
*/
95+
if ( $source instanceof \WPGraphQL\Model\Post && $source->isPostsPage ) {
96+
graphql_debug(
97+
sprintf(
98+
// translators: %d: The ID of the Post model being queried.
99+
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' ),
100+
$source->databaseId,
101+
)
102+
);
103+
}
90104
return null;
91105
}
92106

0 commit comments

Comments
 (0)