|
1 | 1 | <?php |
2 | 2 | namespace WPGraphQL\Type; |
3 | 3 |
|
4 | | -use Closure; |
5 | | -use Exception; |
6 | 4 | use GraphQL\Exception\InvalidArgument; |
7 | 5 | use WPGraphQL\Registry\TypeRegistry; |
8 | 6 | use WPGraphQL\Type\InterfaceType\PageInfo; |
@@ -510,29 +508,34 @@ protected function get_pagination_args(): array { |
510 | 508 | * Registers the connection in the Graph |
511 | 509 | * |
512 | 510 | * @return void |
| 511 | + * @throws \Exception |
513 | 512 | */ |
514 | 513 | public function register_connection_field(): void { |
515 | 514 |
|
| 515 | + // merge the config so the raw data passed to the connection |
| 516 | + // is passed to the field and can be accessed via $info in resolvers |
| 517 | + $field_config = array_merge( $this->config, [ |
| 518 | + 'type' => true === $this->one_to_one ? $this->connection_name . 'Edge' : $this->connection_name, |
| 519 | + 'args' => array_merge( $this->get_pagination_args(), $this->where_args ), |
| 520 | + 'auth' => $this->auth, |
| 521 | + 'deprecationReason' => ! empty( $this->config['deprecationReason'] ) ? $this->config['deprecationReason'] : null, |
| 522 | + 'description' => ! empty( $this->config['description'] ) ? $this->config['description'] : sprintf( __( 'Connection between the %1$s type and the %2$s type', 'wp-graphql' ), $this->from_type, $this->to_type ), |
| 523 | + 'resolve' => function ( $root, $args, $context, $info ) { |
| 524 | + $context->connection_query_class = $this->query_class; |
| 525 | + $resolve_connection = $this->resolve_connection; |
| 526 | + |
| 527 | + /** |
| 528 | + * Return the results of the connection resolver |
| 529 | + */ |
| 530 | + return $resolve_connection( $root, $args, $context, $info ); |
| 531 | + }, |
| 532 | + 'allowFieldUnderscores' => isset( $this->config['allowFieldUnderscores'] ) && true === $this->config['allowFieldUnderscores'], |
| 533 | + ] ); |
| 534 | + |
516 | 535 | $this->type_registry->register_field( |
517 | 536 | $this->from_type, |
518 | 537 | $this->from_field_name, |
519 | | - [ |
520 | | - 'type' => true === $this->one_to_one ? $this->connection_name . 'Edge' : $this->connection_name, |
521 | | - 'args' => array_merge( $this->get_pagination_args(), $this->where_args ), |
522 | | - 'auth' => $this->auth, |
523 | | - 'deprecationReason' => ! empty( $this->config['deprecationReason'] ) ? $this->config['deprecationReason'] : null, |
524 | | - 'description' => ! empty( $this->config['description'] ) ? $this->config['description'] : sprintf( __( 'Connection between the %1$s type and the %2$s type', 'wp-graphql' ), $this->from_type, $this->to_type ), |
525 | | - 'resolve' => function ( $root, $args, $context, $info ) { |
526 | | - $context->connection_query_class = $this->query_class; |
527 | | - $resolve_connection = $this->resolve_connection; |
528 | | - |
529 | | - /** |
530 | | - * Return the results of the connection resolver |
531 | | - */ |
532 | | - return $resolve_connection( $root, $args, $context, $info ); |
533 | | - }, |
534 | | - 'allowFieldUnderscores' => isset( $this->config['allowFieldUnderscores'] ) && true === $this->config['allowFieldUnderscores'], |
535 | | - ] |
| 538 | + $field_config |
536 | 539 | ); |
537 | 540 |
|
538 | 541 | } |
|
0 commit comments