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: arguments on Interface Fields were not properly applied to interfaces and object types implementing the Interface #3109

Conversation

jasonbahl
Copy link
Collaborator

@jasonbahl jasonbahl commented Apr 26, 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

Where has this been tested?

Operating System:

WordPress Version:

@jasonbahl jasonbahl self-assigned this Apr 26, 2024
@coveralls
Copy link

coveralls commented Apr 26, 2024

Coverage Status

coverage: 84.291% (+0.002%) from 84.289%
when pulling 105a74c on jasonbahl:fix/3108-args-not-inherited-from-interface-fields
into a66f3e1 on wp-graphql:develop.

Copy link

codeclimate bot commented Apr 26, 2024

Code Climate has analyzed commit 105a74c and detected 0 issues on this pull request.

View more on Code Climate.

Copy link
Collaborator

@justlevine justlevine left a comment

Choose a reason for hiding this comment

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

Code lgtm.

With those description lines moved, could probably simplify the complexity by continueing early if ! isset( $interface_fields[ $field_name ]['type'] ). But that can also be addressed by adding a few inline comments.

Note: I'm not by my computer to check, but I've run into previous issues using unset() on the looping array and then checking isset() on the modified array, vaguely related to scoping. If we don't early return instead, I'd say this might benefit from another unit test to ensure that conditional doesn't pass when it shouldn't, but also probably not necessary.

@justlevine
Copy link
Collaborator

Code lgtm.

With those description lines moved, could probably simplify the complexity by continueing early if ! isset( $interface_fields[ $field_name ]['type'] ). But that can also be addressed by adding a few inline comments.

Note: I'm not by my computer to check, but I've run into previous issues using unset() on the looping array and then checking isset() on the modified array, vaguely related to scoping. If we don't early return instead, I'd say this might benefit from another unit test to ensure that conditional doesn't pass when it shouldn't, but also probably not necessary.

See jasonbahl#11 for an example of what I mean.

@jasonbahl
Copy link
Collaborator Author

closing in favor of #3112 which handles some additional cases not covered by this PR

Tests from this PR are handled in #3112:

@jasonbahl jasonbahl closed this May 2, 2024
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
3 participants