Files
wp-graphql-woocommerce/includes/connection/class-payment-gateways.php
T
a7714d0cd2 Updates to be compatible with WPGraphQL v1.6.1 (#537)
* fix: Huge refactor across schema and unit tests

* - add shipping_method loader in class-core-schema-filters.php

* - Update class-wc-db-loader.php to respect the new SHIPPING_METHOD loader with a `load_shipping_method_from_id()` function

* - Convert Shipping_Method_Connection_Resolver to extend AbstractConnectionResolver

* - Replace resolver for Shipping Methods connection. Remove use of `resolveNode` and replace the resolver with the new connection class `get_connection()` call

* chore: Factory class refactored.

* - update the function that registers Product Types to the Schema to use the value from the `get_enabled_product_types()` as the Type name and the key as the fieldName

* chore: PaymentGatewayQueriesTest refactored.

* chore: WPCS compliance met

* chore: Syntax error fixed.

Co-authored-by: Jason Bahl <jasonbahl@mac.com>
2021-08-11 14:26:09 -04:00

66 lines
1.6 KiB
PHP

<?php
/**
* Connection - PaymentGateways
*
* Registers connections to PaymentGateway
*
* @package WPGraphQL\WooCommerce\Connection
*/
namespace WPGraphQL\WooCommerce\Connection;
use GraphQL\Type\Definition\ResolveInfo;
use WPGraphQL\AppContext;
use WPGraphQL\WooCommerce\Data\Connection\Payment_Gateway_Connection_Resolver;
/**
* Class - PaymentGateways
*/
class Payment_Gateways {
/**
* Registers the various connections from other Types to Customer.
*/
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
* with the defaults.
*
* @param array $args - Connection configuration.
* @return array
*/
public static function get_connection_config( $args = array() ): array {
return array_merge(
array(
'fromType' => 'RootQuery',
'toType' => 'PaymentGateway',
'fromFieldName' => 'paymentGateways',
'connectionArgs' => self::get_connection_args(),
'resolve' => function ( $source, array $args, AppContext $context, ResolveInfo $info ) {
$resolver = new Payment_Gateway_Connection_Resolver();
return $resolver->resolve( $source, $args, $context, $info );
},
),
$args
);
}
/**
* Returns array of where args.
*
* @return array
*/
public static function get_connection_args(): array {
return array(
'all' => array(
'type' => 'Boolean',
'description' => __( 'Include disabled payment gateways?', 'wp-graphql-woocommerce' ),
),
);
}
}