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

refactor: split AbstractConnectionResolver::get_nodes() and get_edges() into prepare_*() methods #3121

Merged
merged 3 commits into from
May 8, 2024

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

codeclimate bot commented May 4, 2024

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

View more on Code Climate.

@justlevine justlevine added Type: Enhancement New feature or request Status: In Review Needs to be reviewed by a project maintainer before merge Needs: Reviewer Response This needs the attention of a codeowner or maintainer. Component: Connections Issues related to 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
33 checks passed
@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 Issues related to 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 Needs to be reviewed by a project maintainer before merge Type: Enhancement New feature or request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants