forked from wp-graphql/wp-graphql-woocommerce
/
class-orders.php
88 lines (83 loc) · 2.41 KB
/
class-orders.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
<?php
/**
* Connection - Orders
*
* Registers connections to Order
*
* @package WPGraphQL\Extensions\WooCommerce\Connection
*/
namespace WPGraphQL\Extensions\WooCommerce\Connection;
use WPGraphQL\Extensions\WooCommerce\Data\Factory;
/**
* Class - Orders
*/
class Orders extends WC_Connection {
/**
* Registers the various connections from other Types to Customer
*/
public static function register_connections() {
// From RootQuery.
register_graphql_connection( self::get_connection_config() );
// From Customer.
register_graphql_connection(
self::get_connection_config(
array(
'fromType' => 'Customer',
'fromFieldName' => 'orders',
)
)
);
}
/**
* Given an array of $args, this returns the connection config, merging the provided args
* with the defaults
*
* @access public
* @param array $args - Connection configuration.
*
* @return array
*/
public static function get_connection_config( $args = [] ) {
$defaults = array(
'fromType' => 'RootQuery',
'toType' => 'Order',
'fromFieldName' => 'orders',
'connectionArgs' => self::get_connection_args(),
'resolveNode' => function( $id, $args, $context, $info ) {
return Factory::resolve_crud_object( $id, $context );
},
'resolve' => function ( $source, $args, $context, $info ) {
return Factory::resolve_order_connection( $source, $args, $context, $info );
},
);
return array_merge( $defaults, $args );
}
/**
* Returns array of where args
*
* @return array
*/
public static function get_connection_args() {
return array_merge(
self::get_shared_connection_args(),
array(
'statuses' => array(
'type' => array( 'list_of' => 'OrderStatusEnum' ),
'description' => __( 'Limit result set to orders assigned a specific status.', 'wp-graphql-woocommerce' ),
),
'customerId' => array(
'type' => 'Int',
'description' => __( 'Limit result set to orders assigned a specific customer.', 'wp-graphql-woocommerce' ),
),
'customersIn' => array(
'type' => array( 'list_of' => 'Int' ),
'description' => __( 'Limit result set to orders assigned a specific group of customers.', 'wp-graphql-woocommerce' ),
),
'productId' => array(
'type' => 'Int',
'description' => __( 'Limit result set to orders assigned a specific product.', 'wp-graphql-woocommerce' ),
),
)
);
}
}