Skip to content

Conversation

@justlevine
Copy link
Collaborator

@justlevine justlevine commented Jun 8, 2024

What does this implement/fix? Explain your changes.

The PR cleans up the InterfaceTrait class and addresses regressions in #3100 and #3112 in the following ways:

  • chore: Reduce code complexity by breaking up nested conditionals into smaller methods with simpler logic. Similarly, variables were renamed and additional annotations added to improve readability.
  • dev: Add new graphql_debug() message when a field has no associated type. The faux PostObject.ancestors and PostObject.parent have been fixed to be registered as deprecated Connections (that resolve null) to prevent schema breaks for people using those deprecated fields in the same query as a HierarchicalContentNode.ancestors/parent.
  • fix: the use of $this->name to $this->config['name'] for getting the Interface name in the trait.
  • fix: the config "inheritence loop", so all interface properties are inherited when they are not set on the implementing type.
  • tests: fix InterfaceTest:testInvalidArgsOnInheritedObjectFieldsAreCaptured whose errors should be explicitly caught.
  • tests: Added a (failing) test case for "arg type" != "same arg type" (Interface Recursion Issues #3106 (comment))
  • Rename field_arg_type_to_string() to normalize_type_name() and change the usage to handle callables/resolved types.

Does this close any currently open issues?

closes #3106
closes wpengine/wp-graphql-content-blocks#240

Any relevant logs, error output, GraphiQL screenshots, etc?

Any other comments?

Where has this been tested?

Operating System: Ubuntu 20.04 (wsl2 + devilbox + php8.1.15)

WordPress Version: 6.5.3

*
* @return array<string,array<string,mixed>>
*/
private function get_fields_from_implemented_interfaces( TypeRegistry $registry ): array {

Choose a reason for hiding this comment

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

Function get_fields_from_implemented_interfaces has a Cognitive Complexity of 11 (exceeds 5 allowed). Consider refactoring.

*
* @return ?array<string,mixed> The field config with inherited values. Null if the field type cannot be determined.
*/
private function inherit_field_config_from_interface( string $field_name, array $field, array $interface_fields ): ?array {

Choose a reason for hiding this comment

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

Function inherit_field_config_from_interface has a Cognitive Complexity of 8 (exceeds 5 allowed). Consider refactoring.

*
* @return array<string,array<string,mixed>> The merged field args.
*/
private function merge_field_args( string $field_name, array $field_args, array $interface_args ): array {

Choose a reason for hiding this comment

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

Function merge_field_args has a Cognitive Complexity of 8 (exceeds 5 allowed). Consider refactoring.

@justlevine justlevine force-pushed the fix/interface-identical-args-regression branch from 4961b58 to 7ee16f8 Compare June 9, 2024 00:26
@justlevine
Copy link
Collaborator Author

justlevine commented Jun 9, 2024

edit: fixed in 76a5dc9 now ready for review


@jasonbahl / @josephfusco - I didn't have time yet to address wpengine/wp-graphql-content-blocks#240, but the other changes in this PR should make the class a lot easier to reason with.

I'll hope to have some more time to wrap this up soon, but if you want to try and take this over the finish line before I can, please go ahead.

*
* @param string|array<string,mixed>|callable|\GraphQL\Type\Definition\Type $type The type to normalize.
*/
private function normalize_type_name( $type ): string {

Choose a reason for hiding this comment

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

Function normalize_type_name has a Cognitive Complexity of 8 (exceeds 5 allowed). Consider refactoring.

@coveralls
Copy link

Coverage Status

coverage: 84.237% (-0.05%) from 84.29%
when pulling 76a5dc9 on justlevine:fix/interface-identical-args-regression
into 8d06960 on wp-graphql:develop.

@justlevine justlevine marked this pull request as ready for review June 9, 2024 09:24
@justlevine justlevine added status: in review Awaiting review before merging or closing needs: reviewer response This needs the attention of a codeowner or maintainer component: interfaces Relating to GraphQL Interface Types regression Bug that causes a regression to a previously working feature labels Jun 9, 2024
@jasonbahl jasonbahl self-assigned this Jun 27, 2024
jasonbahl
jasonbahl previously approved these changes Jun 27, 2024
@jasonbahl
Copy link
Collaborator

@jasonbahl / @josephfusco - I didn't have time yet to address wpengine/wp-graphql-content-blocks#240, but the other changes in this PR should make the class a lot easier to reason with.

@justlevine looks like the debug messages related to wpengine/wp-graphql-content-blocks#240 are resolved with this PR. 👏🏻

I'll work on a test to prevent future regressions.

@qlty-cloud-legacy
Copy link

Code Climate has analyzed commit 12b1b14 and detected 4 issues on this pull request.

Here's the issue category breakdown:

Category Count
Complexity 4

View more on Code Climate.

@jasonbahl jasonbahl merged commit 8efa191 into wp-graphql:develop Jun 27, 2024
@coveralls
Copy link

Coverage Status

coverage: 84.237% (-0.05%) from 84.29%
when pulling 12b1b14 on justlevine:fix/interface-identical-args-regression
into 8d06960 on wp-graphql:develop.

@jasonbahl jasonbahl mentioned this pull request Jul 3, 2024
@justlevine justlevine deleted the fix/interface-identical-args-regression branch February 10, 2025 22:37
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

component: interfaces Relating to GraphQL Interface Types needs: reviewer response This needs the attention of a codeowner or maintainer regression Bug that causes a regression to a previously working feature status: in review Awaiting review before merging or closing

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Interface field argument error in GraphQL IDE after update to WPGraphQL 1.26 Interface Recursion Issues

3 participants