2019-04-12 18:28:08 -04:00
|
|
|
<?php
|
|
|
|
|
/**
|
|
|
|
|
* Connection - Shipping_Methods
|
|
|
|
|
*
|
|
|
|
|
* Registers connections to ShippingMethod
|
|
|
|
|
*
|
2019-10-25 19:13:36 -04:00
|
|
|
* @package WPGraphQL\WooCommerce\Connection
|
2019-04-12 18:28:08 -04:00
|
|
|
* @since 0.0.2
|
|
|
|
|
*/
|
|
|
|
|
|
2019-10-25 19:13:36 -04:00
|
|
|
namespace WPGraphQL\WooCommerce\Connection;
|
2019-04-12 18:28:08 -04:00
|
|
|
|
2020-02-27 21:30:21 -03:00
|
|
|
use GraphQL\Type\Definition\ResolveInfo;
|
|
|
|
|
use WPGraphQL\AppContext;
|
2021-08-11 14:26:09 -04:00
|
|
|
use WPGraphQL\WooCommerce\Data\Connection\Shipping_Method_Connection_Resolver;
|
2019-04-12 18:28:08 -04:00
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Class - Shipping_Methods
|
|
|
|
|
*/
|
|
|
|
|
class Shipping_Methods {
|
|
|
|
|
/**
|
|
|
|
|
* Registers the various connections from other Types to TaxRate
|
2023-06-13 23:17:02 +03:00
|
|
|
*
|
|
|
|
|
* @return void
|
2019-04-12 18:28:08 -04:00
|
|
|
*/
|
|
|
|
|
public static function register_connections() {
|
|
|
|
|
// From RootQuery.
|
|
|
|
|
register_graphql_connection( self::get_connection_config() );
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Given an array of $args, this returns the connection config, merging the provided args
|
2020-02-27 21:30:21 -03:00
|
|
|
* with the defaults.
|
2019-04-12 18:28:08 -04:00
|
|
|
*
|
|
|
|
|
* @param array $args - Connection configuration.
|
|
|
|
|
* @return array
|
|
|
|
|
*/
|
2022-08-26 14:53:36 -04:00
|
|
|
public static function get_connection_config( $args = [] ): array {
|
2020-02-27 21:30:21 -03:00
|
|
|
return array_merge(
|
2022-08-26 14:53:36 -04:00
|
|
|
[
|
2020-02-27 21:30:21 -03:00
|
|
|
'fromType' => 'RootQuery',
|
|
|
|
|
'toType' => 'ShippingMethod',
|
|
|
|
|
'fromFieldName' => 'shippingMethods',
|
2022-08-26 14:53:36 -04:00
|
|
|
'connectionArgs' => [],
|
2023-07-20 00:11:25 +03:00
|
|
|
'resolve' => static function ( $source, array $args, AppContext $context, ResolveInfo $info ) {
|
2021-08-11 14:26:09 -04:00
|
|
|
$resolver = new Shipping_Method_Connection_Resolver( $source, $args, $context, $info );
|
|
|
|
|
|
|
|
|
|
return $resolver->get_connection();
|
2020-02-27 21:30:21 -03:00
|
|
|
},
|
2022-08-26 14:53:36 -04:00
|
|
|
],
|
2020-02-27 21:30:21 -03:00
|
|
|
$args
|
2019-04-12 18:28:08 -04:00
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
}
|