Skip to content

Commit

Permalink
Merge f7309af into 36f3a7e
Browse files Browse the repository at this point in the history
  • Loading branch information
jasonbahl committed Apr 22, 2024
2 parents 36f3a7e + f7309af commit a2e89fb
Show file tree
Hide file tree
Showing 14 changed files with 421 additions and 237 deletions.
475 changes: 326 additions & 149 deletions src/Data/Connection/AbstractConnectionResolver.php

Large diffs are not rendered by default.

9 changes: 4 additions & 5 deletions src/Data/Connection/CommentConnectionResolver.php
Expand Up @@ -29,8 +29,7 @@ public function get_query_args() {
/**
* Prepare for later use
*/
$last = ! empty( $this->args['last'] ) ? $this->args['last'] : null;
$first = ! empty( $this->args['first'] ) ? $this->args['first'] : null;
$last = ! empty( $this->args['last'] ) ? $this->args['last'] : null;

$query_args = [];

Expand All @@ -49,7 +48,7 @@ public function get_query_args() {
*
* @since 0.0.6
*/
$query_args['number'] = min( max( absint( $first ), absint( $last ), 10 ), $this->get_query_amount() ) + 1;
$query_args['number'] = $this->get_query_amount() + 1;

/**
* Set the default order
Expand Down Expand Up @@ -158,7 +157,7 @@ public function get_query() {
/**
* {@inheritDoc}
*/
public function get_loader_name() {
protected function loader_name(): string {
return 'comment';
}

Expand All @@ -183,7 +182,7 @@ public function get_ids_from_query() {
* @return array<string,mixed>
*/
public function get_args(): array {
$args = $this->args;
$args = $this->get_unfiltered_args();

if ( ! empty( $args['where'] ) ) {
// Ensure all IDs are converted to database IDs.
Expand Down
2 changes: 1 addition & 1 deletion src/Data/Connection/ContentTypeConnectionResolver.php
Expand Up @@ -61,7 +61,7 @@ public function get_query() {
/**
* {@inheritDoc}
*/
public function get_loader_name() {
protected function loader_name(): string {
return 'post_type';
}

Expand Down
36 changes: 8 additions & 28 deletions src/Data/Connection/EnqueuedScriptsConnectionResolver.php
@@ -1,39 +1,12 @@
<?php
namespace WPGraphQL\Data\Connection;

use GraphQL\Type\Definition\ResolveInfo;
use WPGraphQL\AppContext;

/**
* Class EnqueuedScriptsConnectionResolver
*
* @package WPGraphQL\Data\Connection
*/
class EnqueuedScriptsConnectionResolver extends AbstractConnectionResolver {

/**
* {@inheritDoc}
*/
public function __construct( $source, array $args, AppContext $context, ResolveInfo $info ) {

/**
* Filter the query amount to be 1000 for
*/
add_filter(
'graphql_connection_max_query_amount',
static function ( $max, $source, $args, $context, ResolveInfo $info ) {
if ( 'enqueuedScripts' === $info->fieldName || 'registeredScripts' === $info->fieldName ) {
return 1000;
}
return $max;
},
10,
5
);

parent::__construct( $source, $args, $context, $info );
}

/**
* {@inheritDoc}
*/
Expand Down Expand Up @@ -72,10 +45,17 @@ public function get_query() {
/**
* {@inheritDoc}
*/
public function get_loader_name() {
protected function loader_name(): string {
return 'enqueued_script';
}

/**
* {@inheritDoc}
*/
protected function max_query_amount(): int {
return 1000;
}

/**
* {@inheritDoc}
*
Expand Down
35 changes: 8 additions & 27 deletions src/Data/Connection/EnqueuedStylesheetConnectionResolver.php
@@ -1,9 +1,6 @@
<?php
namespace WPGraphQL\Data\Connection;

use GraphQL\Type\Definition\ResolveInfo;
use WPGraphQL\AppContext;

/**
* Class EnqueuedStylesheetConnectionResolver
*
Expand All @@ -17,29 +14,6 @@ class EnqueuedStylesheetConnectionResolver extends AbstractConnectionResolver {
*/
protected $query;

/**
* {@inheritDoc}
*/
public function __construct( $source, array $args, AppContext $context, ResolveInfo $info ) {

/**
* Filter the query amount to be 1000 for
*/
add_filter(
'graphql_connection_max_query_amount',
static function ( $max, $source, $args, $context, ResolveInfo $info ) {
if ( 'enqueuedStylesheets' === $info->fieldName || 'registeredStylesheets' === $info->fieldName ) {
return 1000;
}
return $max;
},
10,
5
);

parent::__construct( $source, $args, $context, $info );
}

/**
* {@inheritDoc}
*/
Expand Down Expand Up @@ -78,10 +52,17 @@ public function get_query() {
/**
* {@inheritDoc}
*/
public function get_loader_name() {
protected function loader_name(): string {
return 'enqueued_stylesheet';
}

/**
* {@inheritDoc}
*/
protected function max_query_amount(): int {
return 1000;
}

/**
* {@inheritDoc}
*
Expand Down
4 changes: 2 additions & 2 deletions src/Data/Connection/MenuItemConnectionResolver.php
Expand Up @@ -80,7 +80,7 @@ public function get_query_args() {
* {@inheritDoc}
*/
public function get_args(): array {
$args = $this->args;
$args = $this->get_unfiltered_args();

if ( ! empty( $args['where'] ) ) {
// Ensure all IDs are converted to database IDs.
Expand All @@ -106,6 +106,6 @@ public function get_args(): array {
*
* @since 1.11.0
*/
return apply_filters( 'graphql_menu_item_connection_args', $args, $this->args );
return apply_filters( 'graphql_menu_item_connection_args', $args, $this->get_unfiltered_args() );
}
}
2 changes: 1 addition & 1 deletion src/Data/Connection/PluginConnectionResolver.php
Expand Up @@ -225,7 +225,7 @@ static function ( $plugin ) use ( $s ) {
/**
* {@inheritDoc}
*/
public function get_loader_name() {
protected function loader_name(): string {
return 'plugin';
}

Expand Down
13 changes: 6 additions & 7 deletions src/Data/Connection/PostObjectConnectionResolver.php
Expand Up @@ -69,7 +69,7 @@ public function __construct( $source, array $args, AppContext $context, ResolveI
/**
* {@inheritDoc}
*/
public function get_loader_name() {
protected function loader_name(): string {
return 'post';
}

Expand Down Expand Up @@ -149,8 +149,7 @@ public function get_query_args() {
/**
* Prepare for later use
*/
$last = ! empty( $this->args['last'] ) ? $this->args['last'] : null;
$first = ! empty( $this->args['first'] ) ? $this->args['first'] : null;
$last = ! empty( $this->args['last'] ) ? $this->args['last'] : null;

$query_args = [];
/**
Expand All @@ -176,10 +175,10 @@ public function get_query_args() {
/**
* Set posts_per_page the highest value of $first and $last, with a (filterable) max of 100
*/
$query_args['posts_per_page'] = $this->one_to_one ? 1 : min( max( absint( $first ), absint( $last ), 10 ), $this->query_amount ) + 1;
$query_args['posts_per_page'] = $this->one_to_one ? 1 : $this->get_query_amount() + 1;

// set the graphql cursor args
$query_args['graphql_cursor_compare'] = ( ! empty( $last ) ) ? '>' : '<';
$query_args['graphql_cursor_compare'] = ! empty( $last ) ? '>' : '<';
$query_args['graphql_after_cursor'] = $this->get_after_offset();
$query_args['graphql_before_cursor'] = $this->get_before_offset();

Expand Down Expand Up @@ -533,7 +532,7 @@ static function ( $status ) use ( $post_type_objects ) {
* {@inheritDoc}
*/
public function get_args(): array {
$args = $this->args;
$args = $this->get_unfiltered_args();

if ( ! empty( $args['where'] ) ) {
// Ensure all IDs are converted to database IDs.
Expand Down Expand Up @@ -580,7 +579,7 @@ static function ( $id ) {
*
* @since 1.11.0
*/
return apply_filters( 'graphql_post_object_connection_args', $args, $this, $this->args );
return apply_filters( 'graphql_post_object_connection_args', $args, $this, $this->get_unfiltered_args() );
}

/**
Expand Down
2 changes: 1 addition & 1 deletion src/Data/Connection/TaxonomyConnectionResolver.php
Expand Up @@ -62,7 +62,7 @@ public function get_query() {
/**
* {@inheritDoc}
*/
public function get_loader_name() {
protected function loader_name(): string {
return 'taxonomy';
}

Expand Down
11 changes: 5 additions & 6 deletions src/Data/Connection/TermObjectConnectionResolver.php
Expand Up @@ -59,8 +59,7 @@ public function get_query_args() {
/**
* Prepare for later use
*/
$last = ! empty( $this->args['last'] ) ? $this->args['last'] : null;
$first = ! empty( $this->args['first'] ) ? $this->args['first'] : null;
$last = ! empty( $this->args['last'] ) ? $this->args['last'] : null;

/**
* Set hide_empty as false by default
Expand All @@ -70,7 +69,7 @@ public function get_query_args() {
/**
* Set the number, ensuring it doesn't exceed the amount set as the $max_query_amount
*/
$query_args['number'] = min( max( absint( $first ), absint( $last ), 10 ), $this->query_amount ) + 1;
$query_args['number'] = $this->get_query_amount() + 1;

/**
* Don't calculate the total rows, it's not needed and can be expensive
Expand Down Expand Up @@ -174,7 +173,7 @@ public function get_ids_from_query() {
/**
* {@inheritDoc}
*/
public function get_loader_name() {
protected function loader_name(): string {
return 'term';
}

Expand Down Expand Up @@ -243,7 +242,7 @@ public function sanitize_input_fields() {
* {@inheritDoc}
*/
public function get_args(): array {
$args = $this->args;
$args = $this->get_unfiltered_args();

if ( ! empty( $args['where'] ) ) {
// Ensure all IDs are converted to database IDs.
Expand Down Expand Up @@ -284,7 +283,7 @@ static function ( $id ) {
*
* @since 1.11.0
*/
return apply_filters( 'graphql_term_object_connection_args', $args, $this, $this->args );
return apply_filters( 'graphql_term_object_connection_args', $args, $this, $this->get_unfiltered_args() );
}

/**
Expand Down
2 changes: 1 addition & 1 deletion src/Data/Connection/ThemeConnectionResolver.php
Expand Up @@ -56,7 +56,7 @@ public function get_query() {
/**
* {@inheritDoc}
*/
public function get_loader_name() {
protected function loader_name(): string {
return 'theme';
}

Expand Down
2 changes: 1 addition & 1 deletion src/Data/Connection/UserConnectionResolver.php
Expand Up @@ -23,7 +23,7 @@ class UserConnectionResolver extends AbstractConnectionResolver {
/**
* {@inheritDoc}
*/
public function get_loader_name() {
protected function loader_name(): string {
return 'user';
}

Expand Down
4 changes: 2 additions & 2 deletions src/Data/Connection/UserRoleConnectionResolver.php
Expand Up @@ -57,14 +57,14 @@ public function get_query_args() {
*/
public function get_query() {
$wp_roles = wp_roles();

return ! empty( $wp_roles->get_names() ) ? array_keys( $wp_roles->get_names() ) : [];
}

/**
* {@inheritDoc}
*/
public function get_loader_name() {
protected function loader_name(): string {
return 'user_role';
}

Expand Down

0 comments on commit a2e89fb

Please sign in to comment.