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: Fixes an Interface field argument regression #3112

Merged

Conversation

kidunot89
Copy link
Member

@kidunot89 kidunot89 commented Apr 30, 2024

What does this implement/fix? Explain your changes.

This fixes a regression to #3102 / #3100

Does this close any currently open issues?

closes: #3108

Any other comments?

Given the following code:

add_action( 'graphql_register_types', function() {

	register_graphql_interface_type( 'InterfaceWithArgs', [
		'fields' => [
			'fieldWithArgs' => [
				'type' => 'String',
				'args' => [
					'interfaceArg' => [
						'type' => 'String',
					],
				],
				'resolve' => function( $source, $args ) {
					return $args['arg'];
				}
			],
		]
	] );

	register_graphql_object_type( 'ObjectTypeImplementingInterfaceWithArgs', [
		'interfaces' => [ 'InterfaceWithArgs' ],
		'fields' => [
			'fieldWithArgs' => [
				'type' => 'String',
				'resolve' => function() {
					return 'object value';
				}
			],
		],
	] );

	register_graphql_field( 'RootQuery', 'interfaceArgsTest', [
		'type' => 'ObjectTypeImplementingInterfaceWithArgs',
		'resolve' => function() {
			return true;
		},
	]);

});

Before

The schema would be invalid:

CleanShot 2024-04-26 at 11 33 56

And this query would be invalid:

CleanShot 2024-04-26 at 11 35 38

After

The schema loads as valid and the test field can be queried

CleanShot 2024-04-26 at 11 35 05

@kidunot89 kidunot89 assigned kidunot89 and unassigned kidunot89 Apr 30, 2024
@kidunot89 kidunot89 marked this pull request as draft April 30, 2024 21:29
@kidunot89 kidunot89 changed the title WIP: fix: Fixes an Interface field argument regression fix: Fixes an Interface field argument regression Apr 30, 2024
return $type->name;
}

return '';
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.

@kidunot89 kidunot89 marked this pull request as ready for review April 30, 2024 23:13
*
* @return string
*/
private function field_arg_type_to_string( $type ) {
Copy link

Choose a reason for hiding this comment

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

Function field_arg_type_to_string has a Cognitive Complexity of 12 (exceeds 5 allowed). Consider refactoring.

@coveralls
Copy link

coveralls commented Apr 30, 2024

Coverage Status

coverage: 84.343% (+0.02%) from 84.323%
when pulling dc959aa on kidunot89:fix/interface-field-arg-regression-fix
into 89ee7cf on wp-graphql:develop.

@justlevine
Copy link
Collaborator

@kidunot89 is this addressing something different than #3109 or is it just a different approach?

@jasonbahl
Copy link
Collaborator

@kidunot89 this breaks most of the workflows: https://github.com/wp-graphql/wp-graphql/pull/3112/checks

@kidunot89
Copy link
Member Author

@jasonbahl @justlevine The breaking workflows are because of WPGraphQL TestCase. It should be resolved in the 3.0 release which I'm working on right now. I'll get it up and update the PR.

@justlevine
Copy link
Collaborator

@jasonbahl @justlevine The breaking workflows are because of WPGraphQL TestCase. It should be resolved in the 3.0 release which I'm working on right now. I'll get it up and update the PR.

Do we need update wp-graphql-test-case in a bugfix PR?

Also, I'm still unclear how this differs in approach (or purpose?) to #3109 .

I'm happy to give the same sort of code review (inline docs and reduced cyclomatic complexity), but it would be helpful to know what (if anything) I should be comparing.

@jasonbahl
Copy link
Collaborator

Do we need update wp-graphql-test-case in a bugfix PR?

@kidunot89 ya, I think we should handle any updates needed for WPGraphQL Test Case separately. Let's focus on the specific issue at hand here, a regression to the merging of Interface Fields with Object Type fields. The other changes are creating side effects that maybe should ultimately be handled, but not within this PR.

*
* @return string
*/
private function field_arg_type_to_string( $type ) {
Copy link

Choose a reason for hiding this comment

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

Function field_arg_type_to_string has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring.

@kidunot89 kidunot89 force-pushed the fix/interface-field-arg-regression-fix branch from 579f6e5 to cc87110 Compare May 2, 2024 21:36
*
* @return string
*/
private function field_arg_type_to_string( $type ) {
Copy link

Choose a reason for hiding this comment

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

Function field_arg_type_to_string has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring.

…rface-field-arg-regression-fix

# Conflicts:
#	src/Type/WPInterfaceTrait.php
#	tests/wpunit/InterfaceTest.php
@jasonbahl
Copy link
Collaborator

@kidunot89 I added another test to cover complex arg types, such as:

	'args' => [
		'nonNullableArg' => [
			'type' => [ 'non_null' => 'String' ],
			'defaultValue' => 'nonNullableArg',
		],
		'listOfArg' => [
			'type' => [ 'list_of' => 'String' ],
			'defaultValue' => [ 'listOfArg', 'listOfArg 2' ],
		],
		'nonNullListOfString' => [
			'type' => [ 'non_null' => [ 'list_of' => 'String' ] ],
			'defaultValue' => [ 'nonNullListOfString', 'nonNullListOfString 2' ],
		],
		'listOfNonNullString' => [
			'type' => [ 'list_of' => [ 'non_null' => 'String' ] ],
			'defaultValue' => [ 'listOfNonNullString', 'listOfNonNullString 2' ],
		],
	],

Copy link

codeclimate bot commented May 2, 2024

Code Climate has analyzed commit dc959aa and detected 1 issue on this pull request.

Here's the issue category breakdown:

Category Count
Complexity 1

View more on Code Climate.

@jasonbahl jasonbahl merged commit a0d1103 into wp-graphql:develop May 2, 2024
30 of 31 checks passed
@justlevine
Copy link
Collaborator

@jasonbahl I'm going to open up a follow up PR to add some code quality improvements and add the failure cases

@jasonbahl
Copy link
Collaborator

@jasonbahl I'm going to open up a follow up PR to add some code quality improvements and add the failure cases

@justlevine can you open the PR to the release branch and include updates to the changelogs as well?

@kidunot89 kidunot89 deleted the fix/interface-field-arg-regression-fix branch May 2, 2024 23:18
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.

Arguments defined on Interface Fields are not inherited by the fields on the Implementing Object Type
4 participants