feat: improve query amount handling in AbstractConnectionResolver#3087
Merged
jasonbahl merged 1 commit intochore/connection-resolvers-cleanupfrom Apr 22, 2024
Conversation
jasonbahl
approved these changes
Apr 22, 2024
This was referenced Apr 22, 2024
Merged
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What does this implement/fix? Explain your changes.
This PR refactors how
AbstractConnectionResolvercalculates the query amount in the following ways:::get_query_amount()to only calculate the query amount 1x in the lifecycle, by checking ifAbstractConnectionResolver::$query_amountis set.$max_query_amountfrom::max_query_amount(), allowing child classes to overload the max amount without using thegraphql_connection_max_query_amountfilter. Child classes using that filter have been updated to set::max_query_amount()instead.graphql_connection_amount_requestedfilter into::get_query_amount()to improve DX. The filter will only be applied once due to the aformentionedisset().graphql_connection_default_query_amountfilter, for changing the default query amount when nofirstorlastargument is passed to the query.::get_amount_requested().::$query_amountwith::get_query_amount().::get_query_args()child methods to rely on::get_query_amount()and avoid unnecessarymin()/max()ing.There are no breaking changes in this release.
Does this close any currently open issues?
Part of #2749
Any relevant logs, error output, GraphiQL screenshots, etc?
Any other comments?
get_query_amount()is called both in::get_args()and in the constructor, so there is no possibility of::$query_amountbeingnullin the child class. Since the types and method signatures, overloaded classes will work as they do currently, making the enhancements in this PR essentially opt-in (i.e. devs can refactor at their leisure).Where has this been tested?
Operating System: Ubuntu 20.04 (wsl2 + devilbox + php 8.1.15)
WordPress Version: 6.4.3