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: output list:$type keys for Root fields that return a listOf Nodes #2861

Merged

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;
Copy link

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;
Copy link

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;
Copy link

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;
Copy link

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;
Copy link

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 ) {
Copy link

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.

@codeclimate
Copy link

codeclimate bot commented Jul 19, 2023

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
32 of 33 checks passed
@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