mirror of
https://github.com/wp-graphql/wp-graphql-woocommerce.git
synced 2026-08-14 12:53:44 +02:00
* chore: setup PHPStan * chore: General code cleanup for PHPStan * chore: PHPStan to level 2 * chore: PHPStan to level 2 * fix: Syntax error fixed. * devops: PHPStan level 2 reached. * devops: PHPStan level 3 passed * devops: PHPStan level 4 passed * chore: fix bad typehints from jwt-auth [phpstan] * chore: simplify conditional logic in WC_Terms::register_connections() * chore: add stubs for WP type properties. * fix: check for valid WC_Order_Item before caching order. * chore: lint * devops: PHPStan level 6 passed. * chore: Linter compliance met. * chore: simplify logic and check for valid term. * fix: ensure valid types (partial) * chore: [phpcs] allow inline type annotations * devops: PHPStan level 8 reached. * devops: More stability fixes. * fix: general bugfixes and improvements * devops: Code Quality GA script added. * devops: Linter compliance met & 2 "phpstan-ignore" statements set. * devops: PHPStan config and CI script fixed. * fix: "cartItem" query resolution refactored * devops: GA scripts updated. * chore: Simple copy changes --------- Co-authored-by: Geoff Taylor <geoff@axistaylor.com>
70 lines
1.7 KiB
PHP
70 lines
1.7 KiB
PHP
<?php
|
|
/**
|
|
* Connection type - VariationAttributes
|
|
*
|
|
* Registers connections to VariationAttribute
|
|
*
|
|
* @package WPGraphQL\WooCommerce\Connection
|
|
* @since 0.0.4
|
|
*/
|
|
|
|
namespace WPGraphQL\WooCommerce\Connection;
|
|
|
|
use GraphQL\Type\Definition\ResolveInfo;
|
|
use WPGraphQL\AppContext;
|
|
use WPGraphQL\WooCommerce\WP_GraphQL_WooCommerce;
|
|
use WPGraphQL\WooCommerce\Data\Connection\Variation_Attribute_Connection_Resolver;
|
|
|
|
/**
|
|
* Class Product_Attributes
|
|
*/
|
|
class Variation_Attributes {
|
|
|
|
/**
|
|
* Registers the various connections from other Types to VariationAttribute
|
|
*
|
|
* @return void
|
|
*/
|
|
public static function register_connections() {
|
|
// From ProductVariation.
|
|
register_graphql_connection( self::get_connection_config() );
|
|
|
|
// From product types.
|
|
$product_types = array_values( WP_GraphQL_WooCommerce::get_enabled_product_types() );
|
|
foreach ( $product_types as $product_type ) {
|
|
register_graphql_connection(
|
|
self::get_connection_config(
|
|
[
|
|
'fromType' => $product_type,
|
|
'fromFieldName' => 'defaultAttributes',
|
|
]
|
|
)
|
|
);
|
|
}
|
|
}
|
|
|
|
/**
|
|
* 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 {
|
|
return array_merge(
|
|
[
|
|
'fromType' => 'ProductVariation',
|
|
'toType' => 'VariationAttribute',
|
|
'fromFieldName' => 'attributes',
|
|
'connectionArgs' => [],
|
|
'resolve' => function( $source, array $args, AppContext $context, ResolveInfo $info ) {
|
|
$resolver = new Variation_Attribute_Connection_Resolver();
|
|
|
|
return $resolver->resolve( $source, $args, $context, $info );
|
|
},
|
|
],
|
|
$args
|
|
);
|
|
}
|
|
}
|