Skip to content

fix: output list:$type keys for Root fields that return a listOf Nodes#2861

Merged
jasonbahl merged 3 commits intowp-graphql:developfrom
jasonbahl:fix/#2860-missing-list-type-keys
Jul 24, 2023
Merged

fix: output list:$type keys for Root fields that return a listOf Nodes#2861
jasonbahl merged 3 commits intowp-graphql:developfrom
jasonbahl:fix/#2860-missing-list-type-keys

Conversation

@jasonbahl
Copy link
Collaborator

@jasonbahl jasonbahl commented Jul 18, 2023

What does this implement/fix? Explain your changes.

This fixes a regression to the 1.14.5 release where list:$type keys are no longer being output for RootQuery fields that return a listOf Nodes.

Does this close any currently open issues?

closes #2860

related: wp-graphql/wp-graphql-smart-cache#228

Any other comments?

Given the following snippet:

add_action( 'graphql_register_types', function() {

	register_graphql_field( 'RootQuery', 'testListOfPosts', [
		'type' => [
			'non_null' => [
				'list_of' => [
					'non_null' => 'Post'
				],
			],
		],
		'resolve' => function() {
			$posts = new \WP_Query([ 'posts_per_page' => 10 ]);
			return array_map( function( $post ) { return new Post( $post ); }, $posts->posts );
		}
	]);

});

I could query for testListOfPosts:

Before

We do not see list:post in the keys

CleanShot 2023-07-18 at 17 04 56

After

We DO see list:post in the keys

CleanShot 2023-07-18 at 17 05 06

@jasonbahl jasonbahl changed the title fix: output list:$type keys for Root fields that return a listOf Nodes fix: output list:$type keys for Root fields that return a listOf Nodes Jul 18, 2023
return $type;
}

return null;

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Avoid too many return statements within this method.


$to_type = $field_def->config['toType'] ?? null;
if ( empty( $to_type ) ) {
return null;

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Avoid too many return statements within this method.

return null;
}

return $to_type;

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Avoid too many return statements within this method.

return null;
}

return $type;

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Avoid too many return statements within this method.

}

if ( ! $is_list_type ) {
return null;

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Avoid too many return statements within this method.

@coveralls
Copy link

coveralls commented Jul 18, 2023

Coverage Status

coverage: 85.049% (+0.02%) from 85.034% when pulling 18da2f0 on jasonbahl:fix/#2860-missing-list-type-keys into e3940e3 on wp-graphql:develop.

@jasonbahl jasonbahl self-assigned this Jul 19, 2023
*
* @return \GraphQL\Type\Definition\Type|String|null
*/
public function get_wrapped_field_type( Type $type, FieldDefinition $field_def, $parent_type, bool $is_list_type = false ) {

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Function get_wrapped_field_type has a Cognitive Complexity of 20 (exceeds 5 allowed). Consider refactoring.

@qlty-cloud-legacy
Copy link

Code Climate has analyzed commit 18da2f0 and detected 6 issues on this pull request.

Here's the issue category breakdown:

Category Count
Complexity 6

View more on Code Climate.

@jasonbahl jasonbahl merged commit a71b261 into wp-graphql:develop Jul 24, 2023
@jasonbahl jasonbahl mentioned this pull request Jul 24, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

QueryAnalyzer not outputting list:$type keys when a field is registered as a listOf type from the root query

3 participants