Skip to content

Commit a74dcb9

Browse files
authored
Merge branch 'develop' into feat/set-query-class
2 parents 0ecb285 + 0c1c7ea commit a74dcb9

File tree

9 files changed

+87
-28
lines changed

9 files changed

+87
-28
lines changed

build/app.asset.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
<?php return array('dependencies' => array('react', 'react-dom', 'wp-element', 'wp-hooks'), 'version' => '029d819e2c38c9f70120');
1+
<?php return array('dependencies' => array('react', 'react-dom', 'wp-element', 'wp-hooks'), 'version' => '2663f617f0b84d60b40c');

build/app.js

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
<?php return array('dependencies' => array('react', 'react-dom', 'wp-element'), 'version' => 'b91f164360ab2451247e');
1+
<?php return array('dependencies' => array('react', 'react-dom', 'wp-element'), 'version' => 'b3f83ad4cac3c77ff4d2');

build/graphiqlQueryComposer.js

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

packages/graphiql-query-composer/components/AbstractArgView.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -443,7 +443,7 @@ const AbstractArgView = (props) => {
443443
>
444444
{isInputObjectType(argType) ? (
445445
<span>
446-
{!!argValue
446+
{argValue
447447
? props.styleConfig.arrowOpen
448448
: props.styleConfig.arrowClosed}
449449
</span>

readme.txt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
=== WPGraphQL ===
22
Contributors: jasonbahl, tylerbarnes1, ryankanner, hughdevore, chopinbach, kidunot89
3-
Tags: GraphQL, API, Gatsby, Headless, Decoupled, React, Nextjs, Vue, Apollo, REST, JSON, HTTP, Remote, Query Language
3+
Tags: GraphQL, JSON, API, Gatsby, Faust, Headless, Decoupled, Svelte, React, Nextjs, Vue, Apollo, REST, JSON, HTTP, Remote, Query Language
44
Requires at least: 5.0
5-
Tested up to: 6.1
5+
Tested up to: 6.2
66
Requires PHP: 7.1
77
Stable tag: 1.14.3
88
License: GPL-3

src/Type/WPConnectionType.php

Lines changed: 22 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,6 @@
11
<?php
22
namespace WPGraphQL\Type;
33

4-
use Closure;
5-
use Exception;
64
use GraphQL\Exception\InvalidArgument;
75
use WPGraphQL\Registry\TypeRegistry;
86
use WPGraphQL\Type\InterfaceType\PageInfo;
@@ -510,29 +508,34 @@ protected function get_pagination_args(): array {
510508
* Registers the connection in the Graph
511509
*
512510
* @return void
511+
* @throws \Exception
513512
*/
514513
public function register_connection_field(): void {
515514

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+
516535
$this->type_registry->register_field(
517536
$this->from_type,
518537
$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
536539
);
537540

538541
}

src/Type/WPMutationType.php

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,9 @@
22
namespace WPGraphQL\Type;
33

44
use Closure;
5-
use Exception;
65
use GraphQL\Type\Definition\ResolveInfo;
76
use WPGraphQL\AppContext;
87
use WPGraphQL\Registry\TypeRegistry;
9-
use WPGraphQL\Utils\Utils;
108

119
/**
1210
* Class WPMutationType

tests/wpunit/ConnectionRegistrationTest.php

Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -671,13 +671,70 @@ public function testWithQueryClass() : void {
671671
$this->markTestIncomplete();
672672
}
673673

674+
public function testConnectionConfigIsAvailableInResolvers() {
675+
676+
$expected = uniqid( 'test', true );
677+
678+
// Pass the $expected value to the connection.
679+
// We will filter the resolver to do something with the value
680+
// And assert we have access to it
681+
register_graphql_connection([
682+
'fromType' => 'RootQuery',
683+
'toType' => 'Post',
684+
'fromFieldName' => 'connectionWithConfig',
685+
'testField' => $expected
686+
]);
687+
688+
// Here we filter the resolver and throw an error
689+
// if the field definition had a value for testField
690+
add_filter( 'graphql_resolve_field', function( $result, $source, $args, $context, \GraphQL\Type\Definition\ResolveInfo $info ) {
691+
692+
if ( ! empty( $info->fieldDefinition->config['testField'] ) ) {
693+
throw new \GraphQL\Error\UserError( $info->fieldDefinition->config['testField'] );
694+
}
695+
696+
return $result;
697+
698+
}, 10, 5 );
699+
700+
$query = '
701+
{
702+
connectionWithConfig {
703+
nodes {
704+
__typename
705+
}
706+
}
707+
}
708+
';
709+
710+
$actual = $this->graphql([
711+
'query' => $query,
712+
]);
713+
714+
codecept_debug( [
715+
'$actual' => $actual,
716+
]);
717+
718+
// Here we're asserting that the $expected value exists in the errors
719+
// This ensures that the value passed in to the connection config
720+
// Is indeed accessible in the $info of the resolver
721+
$this->assertQueryError($actual, [
722+
$this->expectedErrorPath( 'connectionWithConfig' ),
723+
$this->expectedErrorMessage( $expected, self::MESSAGE_EQUALS ),
724+
$this->expectedField( 'connectionWithConfig', self::IS_NULL ),
725+
]);
726+
727+
728+
}
729+
674730
protected function assertValidTypes( $actual ) : void {
675731
$this->assertEquals( 'RootQueryToTestObjectConnection', $actual['data']['testConnection']['__typename'] );
676732
$this->assertEquals( 'RootQueryToTestObjectConnectionEdge', $actual['data']['testConnection']['edges'][0]['__typename'] );
677733
$this->assertEquals( 'TestObject', $actual['data']['testConnection']['edges'][0]['node']['__typename'] );
678734
$this->assertEquals( 'TestObject', $actual['data']['testConnection']['nodes'][0]['__typename'] );
679735
}
680736

737+
681738
public function testRegisteringConnectionsWithCustomQueryClasses() {
682739
add_action( 'graphql_register_types', function () {
683740
register_graphql_connection([
@@ -759,4 +816,5 @@ public function testRegisteringConnectionsWithCustomQueryClasses() {
759816

760817
$this->assertQueryError( $response, $expected );
761818
}
819+
762820
}

0 commit comments

Comments
 (0)