1010
1111namespace WPGraphQL \WooCommerce \Connection ;
1212
13+ use GraphQL \Error \Error ;
1314use GraphQL \Type \Definition \ResolveInfo ;
1415use WPGraphQL \AppContext ;
1516use WPGraphQL \WooCommerce \Data \Connection \Product_Attribute_Connection_Resolver ;
@@ -24,15 +25,11 @@ class Product_Attributes {
2425 * @return void
2526 */
2627 public static function register_connections () {
27- // From Product to ProductAttribute.
28- register_graphql_connection (
29- self ::get_connection_config ()
30- );
31-
3228 // From Product to LocalProductAttribute.
3329 register_graphql_connection (
3430 self ::get_connection_config (
3531 [
32+ 'fromType ' => 'Product ' ,
3633 'toType ' => 'LocalProductAttribute ' ,
3734 'fromFieldName ' => 'localAttributes ' ,
3835 'connectionArgs ' => [],
@@ -44,6 +41,7 @@ public static function register_connections() {
4441 register_graphql_connection (
4542 self ::get_connection_config (
4643 [
44+ 'fromType ' => 'Product ' ,
4745 'toType ' => 'GlobalProductAttribute ' ,
4846 'fromFieldName ' => 'globalAttributes ' ,
4947 'connectionArgs ' => [],
@@ -57,15 +55,23 @@ public static function register_connections() {
5755 * with the defaults.
5856 *
5957 * @param array $args - Connection configuration.
58+ * @throws \GraphQL\Error\Error If the "fromType" or "toType" is not provided.
59+ *
6060 * @return array
6161 */
6262 public static function get_connection_config ( $ args = [] ): array {
63+ if ( ! isset ( $ args ['fromType ' ] ) ) {
64+ throw new Error ( __ ( 'The "fromType" is required for the ProductAttributes connection. ' , 'wp-graphql-woocommerce ' ) );
65+ }
66+
67+ if ( ! isset ( $ args ['toType ' ] ) ) {
68+ throw new Error ( __ ( 'The "toType" is required for the ProductAttributes connection. ' , 'wp-graphql-woocommerce ' ) );
69+ }
70+
6371 return array_merge (
6472 [
65- 'fromType ' => 'Product ' ,
66- 'toType ' => 'ProductAttribute ' ,
6773 'fromFieldName ' => 'attributes ' ,
68- 'connectionArgs ' => self :: get_connection_args () ,
74+ 'connectionArgs ' => [] ,
6975 'resolve ' => static function ( $ source , array $ args , AppContext $ context , ResolveInfo $ info ) {
7076 $ resolver = new Product_Attribute_Connection_Resolver ();
7177 // phpcs:ignore WordPress.NamingConventions.ValidVariableName.UsedPropertyNotSnakeCase
@@ -82,18 +88,4 @@ public static function get_connection_config( $args = [] ): array {
8288 $ args
8389 );
8490 }
85-
86- /**
87- * Returns array of where args.
88- *
89- * @return array
90- */
91- public static function get_connection_args (): array {
92- return [
93- 'type ' => [
94- 'type ' => 'ProductAttributeTypesEnum ' ,
95- 'description ' => __ ( 'Filter results by attribute scope. ' , 'wp-graphql-woocommerce ' ),
96- ],
97- ];
98- }
9991}
0 commit comments