Files

69 lines
1.6 KiB
PHP
Raw Permalink Normal View History

2019-07-29 19:01:42 -04:00
<?php
/**
* Connection - PaymentGateways
*
* Registers connections to PaymentGateway
*
2019-10-25 19:13:36 -04:00
* @package WPGraphQL\WooCommerce\Connection
2019-07-29 19:01:42 -04:00
*/
2019-10-25 19:13:36 -04:00
namespace WPGraphQL\WooCommerce\Connection;
2019-07-29 19:01:42 -04:00
2020-02-27 21:30:21 -03:00
use GraphQL\Type\Definition\ResolveInfo;
use WPGraphQL\AppContext;
use WPGraphQL\WooCommerce\Data\Connection\Payment_Gateway_Connection_Resolver;
2019-07-29 19:01:42 -04:00
/**
* Class - PaymentGateways
*/
class Payment_Gateways {
/**
2020-02-27 21:30:21 -03:00
* Registers the various connections from other Types to Customer.
2023-06-13 23:17:02 +03:00
*
* @return void
2019-07-29 19:01:42 -04:00
*/
public static function register_connections() {
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-07-29 19:01:42 -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' => 'PaymentGateway',
'fromFieldName' => 'paymentGateways',
'connectionArgs' => self::get_connection_args(),
'resolve' => static function ( $source, array $args, AppContext $context, ResolveInfo $info ) {
$resolver = new Payment_Gateway_Connection_Resolver();
return $resolver->resolve( $source, $args, $context, $info );
2020-02-27 21:30:21 -03:00
},
],
2020-02-27 21:30:21 -03:00
$args
2019-07-29 19:01:42 -04:00
);
}
/**
2020-02-27 21:30:21 -03:00
* Returns array of where args.
2019-07-29 19:01:42 -04:00
*
* @return array
*/
2020-02-27 21:30:21 -03:00
public static function get_connection_args(): array {
return [
'all' => [
2019-07-29 19:01:42 -04:00
'type' => 'Boolean',
'description' => static function () {
return __( 'Include disabled payment gateways?', 'graphql-for-ecommerce' );
},
],
];
2019-07-29 19:01:42 -04:00
}
}