Skip to content

Conversation

@justlevine
Copy link
Collaborator

@justlevine justlevine commented May 4, 2024

What does this implement/fix? Explain your changes.

This PR refactors the AbstractConnectionResolver in the following ways:

  • ::get_nodes() and ::get_edges() now instantiate AbstractConnectionResolver::$nodes and AbstractConnectionResolver::$edges only once.
  • The node generation logic has been relocated from ::get_nodes() into the new ::prepare_nodes() method.
  • The edge generation logic has been relocated from ::get_edges() into the new ::prepare_edges() method. The ::prepare_edges() method itself calls the new ::prepare_edge() method, and wraps it in the preexisting graphql_connection_edge filter.

Together, these changes improve the DX by reducing the amount of boilerplate needed when extending the AbstractConnectionResolver class, and improving lifecycle consistency, with potential performance benefits for child classes with complex node/edge generation logic.

There are no breaking changes in this PR.

Important

This PR requires #3120 which should be merged first.

The relevant diff for this PR can be seen at b266d3e

Does this close any currently open issues?

Part of #2749

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

Any other comments?

  • The AbstractConnectionResolver::$nodes and ::$edges properties still manually instantiated and graphql_connection_nodes and graphql_connection_edges filters appiled in AbstractConnectionResolver::get_connection(), to maintain b/c compatibility with classes that are currently overloading ::get_edges() and ::get_nodes() directly.

Where has this been tested?

Operating System: Ubuntu 20.04 (wsl2 + devilbox + php 8.1.15)

WordPress Version: 6.5.2

@justlevine justlevine changed the title dev: refactor AbstractConnectionResolver::get_nodes() and get_edges() into prepare_*() refactor: split AbstractConnectionResolver::get_nodes() and get_edges() into prepare_*() methods May 4, 2024
@qlty-cloud-legacy
Copy link

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

View more on Code Climate.

@justlevine justlevine added type: enhancement Improvements to existing functionality status: in review Awaiting review before merging or closing needs: reviewer response This needs the attention of a codeowner or maintainer component: connections Relating to GraphQL Connections scope: api Issues related to access functions, actions, and filters labels May 4, 2024
@justlevine justlevine requested a review from jasonbahl May 4, 2024 01:38
@coveralls
Copy link

Coverage Status

coverage: 84.346% (+0.02%) from 84.33%
when pulling b266d3e on justlevine:dev/prepare-edges-nodes
into cb18964 on wp-graphql:develop.

@justlevine justlevine changed the title refactor: split AbstractConnectionResolver::get_nodes() and get_edges() into prepare_*() methods refactor: split AbstractConnectionResolver::get_nodes() and get_edges() into prepare_*() methods May 4, 2024
jasonbahl
jasonbahl previously approved these changes May 8, 2024
@justlevine justlevine dismissed jasonbahl’s stale review May 8, 2024 14:54

The merge-base changed after approval.

@jasonbahl jasonbahl merged commit f814f75 into wp-graphql:develop May 8, 2024
@justlevine justlevine deleted the dev/prepare-edges-nodes branch May 8, 2024 15:47
@jasonbahl jasonbahl mentioned this pull request May 8, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

component: connections Relating to GraphQL Connections needs: reviewer response This needs the attention of a codeowner or maintainer scope: api Issues related to access functions, actions, and filters status: in review Awaiting review before merging or closing type: enhancement Improvements to existing functionality

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants