Skip to content

Commit

Permalink
Merge pull request #249 from wp-graphql/release/v0.5.0
Browse files Browse the repository at this point in the history
Release/v0.5.0
  • Loading branch information
kidunot89 committed Mar 27, 2020
2 parents df8e25c + f89adcc commit f4571b6
Show file tree
Hide file tree
Showing 44 changed files with 642 additions and 444 deletions.
2 changes: 2 additions & 0 deletions .github/workflows/testing-integration.yml
@@ -1,6 +1,8 @@
name: Testing Integration

on:
schedule:
- cron: '* * */7 * *'
push:
branches:
- develop
Expand Down
2 changes: 1 addition & 1 deletion README.txt
Expand Up @@ -5,7 +5,7 @@ Requires at least: 4.9
Tested up to: 5.2
Requires PHP: 7.0
Requires WooCommerce: 3.0.0
Requires WPGraphQL: 0.6.0+
Requires WPGraphQL: 0.8.0+
Works with WPGraphQL-JWT-Authentication: 0.4.0+
Stable tag: 0.4.4
License: GPL-3
Expand Down
30 changes: 0 additions & 30 deletions bin/install-wp-tests.sh → bin/install-test-env.sh
Expand Up @@ -110,35 +110,6 @@ install_wp() {
download https://raw.github.com/markoheijnen/wp-mysqli/master/db.php $WP_CORE_DIR/wp-content/db.php
}

install_test_suite() {
# portable in-place argument for both GNU sed and Mac OSX sed
if [[ $(uname -s) == 'Darwin' ]]; then
local ioption='-i.bak'
else
local ioption='-i'
fi

# set up testing suite if it doesn't yet exist
if [ ! -d $WP_TESTS_DIR ]; then
# set up testing suite
mkdir -p $WP_TESTS_DIR
svn co --quiet https://develop.svn.wordpress.org/${WP_TESTS_TAG}/tests/phpunit/includes/ $WP_TESTS_DIR/includes
svn co --quiet https://develop.svn.wordpress.org/${WP_TESTS_TAG}/tests/phpunit/data/ $WP_TESTS_DIR/data
fi

if [ ! -f wp-tests-config.php ]; then
download https://develop.svn.wordpress.org/${WP_TESTS_TAG}/wp-tests-config-sample.php "$WP_TESTS_DIR"/wp-tests-config.php
# remove all forward slashes in the end
WP_CORE_DIR=$(echo $WP_CORE_DIR | sed "s:/\+$::")
sed $ioption "s:dirname( __FILE__ ) . '/src/':'$WP_CORE_DIR/':" "$WP_TESTS_DIR"/wp-tests-config.php
sed $ioption "s/youremptytestdbnamehere/$DB_NAME/" "$WP_TESTS_DIR"/wp-tests-config.php
sed $ioption "s/yourusernamehere/$DB_USER/" "$WP_TESTS_DIR"/wp-tests-config.php
sed $ioption "s/yourpasswordhere/$DB_PASS/" "$WP_TESTS_DIR"/wp-tests-config.php
sed $ioption "s|localhost|${DB_HOST}|" "$WP_TESTS_DIR"/wp-tests-config.php
fi

}

install_db() {

if [ ${SKIP_DB_CREATE} = "true" ]; then
Expand Down Expand Up @@ -215,7 +186,6 @@ setup_plugin() {
}

install_wp
install_test_suite
install_db
configure_wordpress
setup_woocommerce
Expand Down
4 changes: 2 additions & 2 deletions composer.json
Expand Up @@ -32,7 +32,7 @@
},
"autoload": {
"files":[
"includes/connection/common-post-type-args.php",
"includes/connection/wc-cpt-connection-args.php",
"includes/functions.php"
],
"psr-4": {
Expand All @@ -43,7 +43,7 @@
]
},
"scripts": {
"install-wp-tests": "bash bin/install-wp-tests.sh",
"install-test-env": "bash bin/install-test-env.sh",
"test": "vendor/bin/codecept run",
"functional-test": "vendor/bin/codecept run functional",
"acceptance-test": "vendor/bin/codecept run acceptance",
Expand Down
61 changes: 14 additions & 47 deletions includes/class-core-schema-filters.php
Expand Up @@ -9,27 +9,14 @@
namespace WPGraphQL\WooCommerce;

use WPGraphQL\WooCommerce\Data\Loader\WC_Customer_Loader;
use WPGraphQL\WooCommerce\Data\Loader\WC_Post_Crud_Loader;
use WPGraphQL\WooCommerce\Data\Loader\WC_CPT_Loader;
use WPGraphQL\WooCommerce\Data\Loader\WC_Db_Loader;
use WPGraphQL\WooCommerce\Data\Factory;

/**
* Class Core_Schema_Filters
*/
class Core_Schema_Filters {
/**
* Stores instance WC_Customer_Loader
*
* @var WC_Customer_Loader
*/
private static $customer_loader;

/**
* Stores instance WC_Post_Crud_Loader
*
* @var WC_Post_Crud_Loader
*/
private static $post_crud_loader;

/**
* Register filters
*/
Expand Down Expand Up @@ -104,34 +91,6 @@ public static function add_filters() {
);
}

/**
* Initializes WC_Loader instance
*
* @param AppContext $context - AppContext.
*
* @return WC_Post_Crud_Loader
*/
public static function post_crud_loader( $context ) {
if ( is_null( self::$post_crud_loader ) ) {
self::$post_crud_loader = new WC_Post_Crud_Loader( $context );
}
return self::$post_crud_loader;
}

/**
* Initializes Customer_Loader instance
*
* @param AppContext $context - AppContext.
*
* @return WC_Customer_Loader
*/
public static function customer_loader( $context ) {
if ( is_null( self::$customer_loader ) ) {
self::$customer_loader = new WC_Customer_Loader( $context );
}
return self::$customer_loader;
}

/**
* Registers WooCommerce post-types to be used in GraphQL schema
*
Expand Down Expand Up @@ -255,12 +214,20 @@ public static function register_taxonomy_args( $args, $taxonomy ) {
*/
public static function graphql_data_loaders( $loaders, $context ) {
// WooCommerce customer loader.
$customer_loader = self::customer_loader( $context );
$customer_loader = new WC_Customer_Loader( $context );
$loaders['wc_customer'] = &$customer_loader;

// WooCommerce crud object loader.
$post_crud_loader = self::post_crud_loader( $context );
$loaders['wc_post_crud'] = &$post_crud_loader;
// WooCommerce CPT loader.
$cpt_loader = new WC_CPT_Loader( $context );
$loaders['wc_cpt'] = &$cpt_loader;

// WooCommerce DB loaders.
$cart_item_loader = new WC_Db_Loader( $context, 'CART_ITEM' );
$loaders['cart_item'] = &$cart_item_loader;
$downloadable_item_loader = new WC_Db_Loader( $context, 'DOWNLOADABLE_ITEM' );
$loaders['downloadable_item'] = &$downloadable_item_loader;
$tax_rate_loader = new WC_Db_Loader( $context, 'TAX_RATE' );
$loaders['tax_rate'] = &$tax_rate_loader;

return $loaders;
}
Expand Down
7 changes: 2 additions & 5 deletions includes/connection/class-coupons.php
Expand Up @@ -50,10 +50,7 @@ public static function get_connection_config( $args = array() ): array {
'toType' => 'Coupon',
'fromFieldName' => 'coupons',
'connectionArgs' => self::get_connection_args(),
'resolveNode' => function( $id, array $args, AppContext $context ) {
return Factory::resolve_crud_object( $id, $context );
},
'resolve' => function ( $source, array $args, AppContext $context, ResolveInfo $info ) {
'resolve' => function ( $source, $args, $context, $info ) {
return Factory::resolve_coupon_connection( $source, $args, $context, $info );
},
),
Expand All @@ -68,7 +65,7 @@ public static function get_connection_config( $args = array() ): array {
*/
public static function get_connection_args(): array {
return array_merge(
get_common_post_type_args(),
get_wc_cpt_connection_args(),
array(
'code' => array(
'type' => 'String',
Expand Down
3 changes: 0 additions & 3 deletions includes/connection/class-customers.php
Expand Up @@ -54,9 +54,6 @@ public static function get_connection_config( $args ): array {
return array_merge(
array(
'connectionArgs' => self::get_connection_args(),
'resolveNode' => function( $id, array $args, AppContext $context ) {
return Factory::resolve_customer( $id, $context );
},
'resolve' => function ( $source, array $args, AppContext $context, ResolveInfo $info ) {
return Factory::resolve_customer_connection( $source, $args, $context, $info );
},
Expand Down
5 changes: 1 addition & 4 deletions includes/connection/class-orders.php
Expand Up @@ -54,9 +54,6 @@ public static function get_connection_config( $args = array() ): array {
'toType' => 'Order',
'fromFieldName' => 'orders',
'connectionArgs' => self::get_connection_args(),
'resolveNode' => function( $id, $args, AppContext $context ) {
return Factory::resolve_crud_object( $id, $context );
},
'resolve' => function ( $source, array $args, AppContext $context, ResolveInfo $info ) {
return Factory::resolve_order_connection( $source, $args, $context, $info );
},
Expand All @@ -75,7 +72,7 @@ public static function get_connection_args( $access = 'public' ): array {
switch ( $access ) {
case 'private':
return array_merge(
get_common_post_type_args(),
get_wc_cpt_connection_args(),
array(
'statuses' => array(
'type' => array( 'list_of' => 'OrderStatusEnum' ),
Expand Down
3 changes: 2 additions & 1 deletion includes/connection/class-product-reviews.php
Expand Up @@ -46,7 +46,8 @@ public static function register_connections() {
'type' => 'Float',
'description' => __( 'Review rating', 'wp-graphql-woocommerce' ),
'resolve' => function( $source ) {
$rating = get_comment_meta( $source['node'], 'rating', true );
$review = $source['node'];
$rating = get_comment_meta( $review->commentId, 'rating', true );
return $rating ? $rating : 0;
},
),
Expand Down
5 changes: 1 addition & 4 deletions includes/connection/class-products.php
Expand Up @@ -126,9 +126,6 @@ public static function get_connection_config( $args = array() ): array {
'toType' => 'Product',
'fromFieldName' => 'products',
'connectionArgs' => self::get_connection_args(),
'resolveNode' => function( $id, array $args, AppContext $context ) {
return Factory::resolve_crud_object( $id, $context );
},
'resolve' => function( $source, array $args, AppContext $context, ResolveInfo $info ) {
return Factory::resolve_product_connection( $source, $args, $context, $info );
},
Expand Down Expand Up @@ -277,6 +274,6 @@ public static function get_connection_args(): array {
);
}

return array_merge( get_common_post_type_args(), $args );
return array_merge( get_wc_cpt_connection_args(), $args );
}
}
5 changes: 1 addition & 4 deletions includes/connection/class-refunds.php
Expand Up @@ -51,9 +51,6 @@ public static function get_connection_config( $args = array() ): array {
'toType' => 'Refund',
'fromFieldName' => 'refunds',
'connectionArgs' => self::get_connection_args(),
'resolveNode' => function( $id, array $args, AppContext $context ) {
return Factory::resolve_crud_object( $id, $context );
},
'resolve' => function( $source, array $args, AppContext $context, ResolveInfo $info ) {
return Factory::resolve_refund_connection( $source, $args, $context, $info );
},
Expand All @@ -69,7 +66,7 @@ public static function get_connection_config( $args = array() ): array {
*/
public static function get_connection_args(): array {
return array_merge(
get_common_post_type_args(),
get_wc_cpt_connection_args(),
array(
'statuses' => array(
'type' => array( 'list_of' => 'String' ),
Expand Down
3 changes: 0 additions & 3 deletions includes/connection/class-tax-rates.php
Expand Up @@ -41,9 +41,6 @@ public static function get_connection_config( $args = array() ): array {
'toType' => 'TaxRate',
'fromFieldName' => 'taxRates',
'connectionArgs' => self::get_connection_args(),
'resolveNode' => function( $id ) {
return Factory::resolve_tax_rate( $id );
},
'resolve' => function( $source, array $args, AppContext $context, ResolveInfo $info ) {
return Factory::resolve_tax_rate_connection( $source, $args, $context, $info );
},
Expand Down
@@ -1,6 +1,6 @@
<?php
/**
* Define common arguments for post-type connections.
* Define common connection arguments for CPT connections.
*
* @package WPGraphQL\WooCommerce\Connection
* @since 0.2.2
Expand All @@ -9,11 +9,11 @@
namespace WPGraphQL\WooCommerce\Connection;

/**
* Returns argument definitions for argument common on all post-type connections.
* Returns argument definitions for argument common on CPT connections.
*
* @return array
*/
function get_common_post_type_args(): array {
function get_wc_cpt_connection_args(): array {
return array(
'search' => array(
'type' => 'String',
Expand Down

0 comments on commit f4571b6

Please sign in to comment.