mirror of
https://github.com/wp-graphql/wp-graphql-woocommerce.git
synced 2026-08-14 12:53:44 +02:00
* 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>
54 lines
1.3 KiB
PHP
54 lines
1.3 KiB
PHP
<?php
|
|
/**
|
|
* Connection - Shipping_Methods
|
|
*
|
|
* Registers connections to ShippingMethod
|
|
*
|
|
* @package WPGraphQL\WooCommerce\Connection
|
|
* @since 0.0.2
|
|
*/
|
|
|
|
namespace WPGraphQL\WooCommerce\Connection;
|
|
|
|
use GraphQL\Type\Definition\ResolveInfo;
|
|
use WPGraphQL\AppContext;
|
|
use WPGraphQL\WooCommerce\Data\Connection\Shipping_Method_Connection_Resolver;
|
|
|
|
/**
|
|
* Class - Shipping_Methods
|
|
*/
|
|
class Shipping_Methods {
|
|
|
|
/**
|
|
* Registers the various connections from other Types to TaxRate
|
|
*/
|
|
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
|
|
* 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' => 'ShippingMethod',
|
|
'fromFieldName' => 'shippingMethods',
|
|
'connectionArgs' => array(),
|
|
'resolve' => function( $source, array $args, AppContext $context, ResolveInfo $info ) {
|
|
$resolver = new Shipping_Method_Connection_Resolver( $source, $args, $context, $info );
|
|
|
|
return $resolver->get_connection();
|
|
},
|
|
),
|
|
$args
|
|
);
|
|
}
|
|
}
|