@@ -23,26 +23,35 @@ public static function register_connections() {
2323 register_graphql_connection ( self ::get_connection_config () );
2424
2525 // From Coupon.
26+ register_graphql_connection ( self ::get_connection_config ( array ( 'fromType ' => 'Coupon ' ) ) );
2627 register_graphql_connection (
2728 self ::get_connection_config (
2829 array (
2930 'fromType ' => 'Coupon ' ,
30- 'fromFieldName ' => 'products ' ,
31+ 'fromFieldName ' => 'excludedProducts ' ,
3132 )
3233 )
3334 );
35+
36+ // Connections from all product types to related and upsell.
3437 register_graphql_connection (
3538 self ::get_connection_config (
3639 array (
37- 'fromType ' => 'Coupon ' ,
38- 'fromFieldName ' => 'excludedProducts ' ,
40+ 'fromType ' => 'Product ' ,
41+ 'fromFieldName ' => 'related ' ,
42+ )
43+ )
44+ );
45+ register_graphql_connection (
46+ self ::get_connection_config (
47+ array (
48+ 'fromType ' => 'Product ' ,
49+ 'fromFieldName ' => 'upsell ' ,
3950 )
4051 )
4152 );
4253
43- // Connections from all product types.
4454 $ product_types = array_values ( \WP_GraphQL_WooCommerce::get_enabled_product_types () );
45-
4655 foreach ( $ product_types as $ product_type ) {
4756 register_graphql_connection (
4857 self ::get_connection_config (
@@ -61,6 +70,11 @@ public static function register_connections() {
6170 )
6271 );
6372 }
73+
74+ // Group product children connection.
75+ register_graphql_connection ( self ::get_connection_config ( array ( 'fromType ' => 'GroupProduct ' ) ) );
76+
77+ // Product cross-sell connections.
6478 register_graphql_connection (
6579 self ::get_connection_config (
6680 array (
@@ -77,14 +91,6 @@ public static function register_connections() {
7791 )
7892 )
7993 );
80- register_graphql_connection (
81- self ::get_connection_config (
82- array (
83- 'fromType ' => 'GroupProduct ' ,
84- 'fromFieldName ' => 'products ' ,
85- )
86- )
87- );
8894
8995 // From VariableProduct to ProductVariation.
9096 register_graphql_connection (
@@ -98,34 +104,17 @@ public static function register_connections() {
98104 );
99105
100106 // From ProductCategory.
101- register_graphql_connection (
102- self ::get_connection_config (
103- array (
104- 'fromType ' => 'ProductCategory ' ,
105- 'fromFieldName ' => 'products ' ,
106- )
107- )
108- );
107+ register_graphql_connection ( self ::get_connection_config ( array ( 'fromType ' => 'ProductCategory ' ) ) );
109108
110109 // From ProductTag.
111- register_graphql_connection (
112- self ::get_connection_config (
113- array (
114- 'fromType ' => 'ProductTag ' ,
115- 'fromFieldName ' => 'products ' ,
116- )
117- )
118- );
110+ register_graphql_connection ( self ::get_connection_config ( array ( 'fromType ' => 'ProductTag ' ) ) );
119111
120112 // From WooCommerce product attributes.
121113 $ attributes = \WP_GraphQL_WooCommerce::get_product_attribute_taxonomies ();
122114 foreach ( $ attributes as $ attribute ) {
123115 register_graphql_connection (
124116 self ::get_connection_config (
125- array (
126- 'fromType ' => ucfirst ( graphql_format_field_name ( $ attribute ) ),
127- 'fromFieldName ' => 'products ' ,
128- )
117+ array ( 'fromType ' => ucfirst ( graphql_format_field_name ( $ attribute ) ) )
129118 )
130119 );
131120 register_graphql_connection (
@@ -152,7 +141,7 @@ public static function register_connections() {
152141 public static function get_connection_config ( $ args = [] ) {
153142 $ defaults = array (
154143 'fromType ' => 'RootQuery ' ,
155- 'toType ' => 'ProductUnion ' ,
144+ 'toType ' => 'Product ' ,
156145 'fromFieldName ' => 'products ' ,
157146 'connectionArgs ' => self ::get_connection_args (),
158147 'resolveNode ' => function ( $ id , $ args , $ context , $ info ) {
0 commit comments