Files

55 lines
1.3 KiB
PHP
Raw Permalink Normal View History

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;
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
*/
public static function get_connection_config( $args = [] ): array {
2020-02-27 21:30:21 -03:00
return array_merge(
[
2020-02-27 21:30:21 -03:00
'fromType' => 'RootQuery',
'toType' => 'ShippingMethod',
'fromFieldName' => 'shippingMethods',
'connectionArgs' => [],
'resolve' => static function ( $source, array $args, AppContext $context, ResolveInfo $info ) {
$resolver = new Shipping_Method_Connection_Resolver( $source, $args, $context, $info );
return $resolver->get_connection();
2020-02-27 21:30:21 -03:00
},
],
2020-02-27 21:30:21 -03:00
$args
2019-04-12 18:28:08 -04:00
);
}
}