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

fix: uri field is null when querying the page for posts uri #2792

Merged
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.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
3 changes: 1 addition & 2 deletions src/Data/NodeResolver.php
Expand Up @@ -201,8 +201,7 @@ public function resolve_uri( string $uri, $extra_query_vars = '' ) {
return null;
}

/** @todo resolve to an Archive Type. */
$post_type_object = get_post_type_object( $queried_object->post_type );
$post_type_object = get_post_type_object( 'post' );
justlevine marked this conversation as resolved.
Show resolved Hide resolved

if ( ! $post_type_object ) {
return null;
Expand Down
57 changes: 54 additions & 3 deletions tests/wpunit/NodeByUriTest.php
Expand Up @@ -1084,13 +1084,13 @@ public function testPostFormatByUri() {
codecept_debug( $uri );

$term = get_term_by('slug', 'post-format-aside', 'post_format');

/**
* NodeResolver::parse_request() will generate the following query vars:
* uri => /type/aside/
* post_format => post-format-aside
* post_type => [ post ]
*
*
*/
$actual = $this->graphql([
'query' => $query,
Expand Down Expand Up @@ -1669,7 +1669,7 @@ public function testPageQueryWhenPageIsSetToHomePage() {
}

/**
* Tests the Posts Archive Page URI
* Tests the Posts Archive Page URI
*/
public function testPageForPostsByUri() {

Expand Down Expand Up @@ -1894,6 +1894,57 @@ public function testNodeByUriWithCustomPermalinkStructureAndFrontPageSet() {
// cleanup
update_option( 'page_on_front', 0 );
update_option( 'show_on_front', 0 );
wp_delete_post( $page_id, true );

}

public function testQueryPostsPageByUriReturnsExpectedUriOnNode() {

$page_id = $this->factory()->post->create([
'post_type' => 'page',
'post_status' => 'publish',
]);

$page_for_posts = $this->factory()->post->create([
'post_type' => 'page',
'post_status' => 'publish',
'post_title' => 'Page for Posts'
]);

update_option( 'page_on_front', $page_id );
update_option( 'show_on_front', 'page' );
update_option( 'page_for_posts', $page_for_posts );

$query = '
query GetPostsPage( $uri: String! ) {
nodeByUri(uri: $uri) {
__typename
uri
}
}
';

$uri = parse_url( get_permalink( $page_for_posts ), PHP_URL_PATH );

$variables = [
'uri' => $uri
];

codecept_debug( [
'variables' => $variables,
]);

$actual = $this->graphql([
'query' => $query,
'variables' => $variables
]);

self::assertQuerySuccessful( $actual, [
// the query should return a null value as the uri
// cannot be found
$this->expectedField( 'nodeByUri.__typename', 'ContentType' ),
$this->expectedField( 'nodeByUri.uri', $uri ),
] );

}

Expand Down