Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Release v0.4.0 #217

Merged
merged 11 commits into from
Jan 22, 2020
5 changes: 2 additions & 3 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,7 @@ branches:
only:
- develop
- master
- release-v0.1.2
- release-v0.2.2
- release-v0.3.3
- release/v0.4.0

cache:
apt: true
Expand Down Expand Up @@ -77,6 +75,7 @@ before_script:
docker-compose build \
--build-arg DESIRED_PHP_VERSION=${PHP_VERSION} \
--build-arg DESIRED_WP_VERSION=${WP_VERSION} \
--build-arg USE_XDEBUG=${USE_XDEBUG} \
testing
fi
# Install PHP CodeSniffer and WPCS.
Expand Down
9 changes: 8 additions & 1 deletion Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -17,14 +17,16 @@ SHELL [ "/bin/bash", "-c" ]
# Redeclare ARGs and set as environmental variables for reuse.
ARG DESIRED_WP_VERSION
ARG DESIRED_PHP_VERSION
ARG USE_XDEBUG
ENV WP_VERSION=${DESIRED_WP_VERSION}
ENV PHP_VERSION=${DESIRED_PHP_VERSION}
ENV USING_XDEBUG=${USE_XDEBUG}

# Install php extensions
RUN docker-php-ext-install pdo_mysql

# Install PCOV and XDebug
RUN if [ "$PHP_VERSION" != "5.6" ] && [ "$PHP_VERSION" != "7.0" ]; then \
RUN if [ "$PHP_VERSION" != "5.6" ] && [ "$PHP_VERSION" != "7.0" ] && [[ -z "$USING_XDEBUG" ]]; then \
apt-get install zip unzip -y && \
pecl install pcov && \
docker-php-ext-enable pcov && \
Expand All @@ -35,6 +37,11 @@ RUN if [ "$PHP_VERSION" != "5.6" ] && [ "$PHP_VERSION" != "7.0" ]; then \
&& echo "zend_extension=$(find /usr/local/lib/php/extensions/ -name xdebug.so)" > /usr/local/etc/php/conf.d/xdebug.ini \
&& echo "xdebug.remote_enable=on" >> /usr/local/etc/php/conf.d/xdebug.ini \
&& echo "xdebug.remote_autostart=off" >> /usr/local/etc/php/conf.d/xdebug.ini; \
elif [ "$PHP_VERSION" == "7.0" ]; then \
yes | pecl install xdebug-2.6.1 \
&& echo "zend_extension=$(find /usr/local/lib/php/extensions/ -name xdebug.so)" > /usr/local/etc/php/conf.d/xdebug.ini \
&& echo "xdebug.remote_enable=on" >> /usr/local/etc/php/conf.d/xdebug.ini \
&& echo "xdebug.remote_autostart=off" >> /usr/local/etc/php/conf.d/xdebug.ini; \
else \
yes | pecl install xdebug \
&& echo "zend_extension=$(find /usr/local/lib/php/extensions/ -name xdebug.so)" > /usr/local/etc/php/conf.d/xdebug.ini \
Expand Down
7 changes: 5 additions & 2 deletions README.txt
Original file line number Diff line number Diff line change
@@ -1,10 +1,13 @@
=== WP GraphQL WooCommerce ===
Contributors: kidunot89, ranaaterning
Contributors: kidunot89, ranaaterning, jasonbahl, saleebm
Tags: GraphQL, WooCommerce, WPGraphQL
Requires at least: 4.9
Tested up to: 5.2
Requires PHP: 5.6
Stable tag: 0.3.3
Requires WooCommerce: 3.0.0
Requires WPGraphQL: 0.6.0+
Works with WPGraphQL-JWT-Authentication: 0.4.0+
Stable tag: 0.4.0
License: GPL-3
License URI: https://www.gnu.org/licenses/gpl-3.0.html
Maintained at: https://github.com/wp-graphql/wp-graphql-woocommerce
Expand Down
17 changes: 14 additions & 3 deletions bin/testing-entrypoint.sh
Original file line number Diff line number Diff line change
Expand Up @@ -53,12 +53,12 @@ fi
COMPOSER_MEMORY_LIMIT=-1 composer install --prefer-source --no-interaction

# Install pcov/clobber if PHP7.1+
if version_gt $PHP_VERSION 7.0 && [[ "$COVERAGE" == "1" ]]; then
if version_gt $PHP_VERSION 7.0 && [[ "$COVERAGE" == "1" ]] && [[ -z "$USING_XDEBUG" ]]; then
echo "Installing pcov/clobber"
COMPOSER_MEMORY_LIMIT=-1 composer require --dev pcov/clobber
vendor/bin/pcov clobber
elif [ "$COVERAGE" == "1" ]; then
echo "Sorry, there is no PCOV support for this PHP ${PHP_VERSION} at this time"
echo "Using XDebug for codecoverage"
fi

# Set output permission
Expand All @@ -81,11 +81,22 @@ if [ -f "${TESTS_OUTPUT}/coverage.xml" ] && [[ "$COVERAGE" == "1" ]]; then
sed -i "s~$pattern~~g" "$TESTS_OUTPUT"/coverage.xml

# Remove pcov/clobber
if version_gt $PHP_VERSION 7.0 && [ "$SKIP_TESTS_CLEANUP" != "1" ]; then
if version_gt $PHP_VERSION 7.0 && [ "$SKIP_TESTS_CLEANUP" != "1" ] && [[ -z "$USING_XDEBUG" ]]; then
echo 'Removing pcov/clobber.'
vendor/bin/pcov unclobber
COMPOSER_MEMORY_LIMIT=-1 composer remove --dev pcov/clobber
fi

if [ "$SKIP_TESTS_CLEANUP" != "1" ]; then
echo 'Changing composer configuration in container.'
composer config --global discard-changes true

echo 'Removing devDependencies.'
composer install --no-dev -n

echo 'Removing composer.lock'
rm composer.lock
fi
fi

# Set public test result files permissions.
Expand Down
5 changes: 3 additions & 2 deletions docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -41,8 +41,9 @@ services:
context: .
dockerfile: Dockerfile
args:
DESIRED_PHP_VERSION: "${PHP_VERSION:-7.3}"
DESIRED_WP_VERSION: "${WP_VERSION:-5.2}"
- DESIRED_PHP_VERSION="${PHP_VERSION:-7.3}"
- DESIRED_WP_VERSION="${WP_VERSION:-5.2}"
- USE_XDEBUG
image: woographql-testing
volumes:
- '.:/var/www/html/wp-content/plugins/wp-graphql-woocommerce'
Expand Down
12 changes: 11 additions & 1 deletion includes/class-core-schema-filters.php
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,17 @@ public static function add_filters() {
add_filter(
'graphql_term_object_connection_query_args',
array(
'\WPGraphQL\WooCommerce\Data\Connection\WC_Terms_Connection_Resolver',
'\WPGraphQL\WooCommerce\Data\Connection\WC_Term_Connection_Resolver',
'get_query_args',
),
10,
5
);

add_filter(
'graphql_comment_connection_query_args',
array(
'\WPGraphQL\WooCommerce\Data\Connection\Product_Review_Connection_Resolver',
'get_query_args',
),
10,
Expand Down
51 changes: 17 additions & 34 deletions includes/class-jwt-auth-schema-filters.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,57 +23,40 @@ class JWT_Auth_Schema_Filters {
*/
public static function add_filters() {
// Confirm WPGraphQL JWT Authentication is install and activated.
if ( class_exists( '\WPGraphQL\JWT_Authentication\JWT_Authentication' ) ) {
add_filter( 'graphql_customer_fields', array( __CLASS__, 'add_jwt_token_fields' ), 10 );
add_filter( 'graphql_registerCustomerPayload_fields', array( __CLASS__, 'add_jwt_output_fields' ), 10, 1 );
add_filter( 'graphql_updateCustomerPayload_fields', array( __CLASS__, 'add_jwt_output_fields' ), 10, 1 );
if ( defined( 'WPGRAPHQL_JWT_AUTHENTICATION_VERSION' ) ) {
add_filter( 'graphql_jwt_user_types', array( __CLASS__, 'add_customer_to_jwt_user_types' ), 10 );
add_filter( 'graphql_registerCustomerPayload_fields', array( __CLASS__, 'add_jwt_output_fields' ), 10, 3 );
add_filter( 'graphql_updateCustomerPayload_fields', array( __CLASS__, 'add_jwt_output_fields' ), 10, 3 );
add_action( 'graphql_register_types', array( __CLASS__, 'add_customer_to_login_payload' ), 10 );
}
}

/**
* Adds all JWT related fields to the Customer type.
* Adds Customer type to the JWT User type list.
*
* @param array $fields Customer type field definitions.
* @param array $types JWT User types.
*
* @return array
*/
public static function add_jwt_token_fields( $fields ) {
$jwt_token_fields = array();

// Wrapper field resolvers in a lambda that retrieves the WP_User object for the corresponding customer.
foreach ( \WPGraphQL\JWT_Authentication\ManageTokens::add_user_fields( array() ) as $field_name => $field ) {
$root_resolver = $field['resolve'];
$jwt_token_fields[ $field_name ] = array_merge(
$field,
array(
'resolve' => function( $source, array $args, AppContext $context, ResolveInfo $info ) use ( $root_resolver ) {
$wp_user = get_user_by( 'id', $source->ID );
if ( $wp_user ) {
$user = new User( $wp_user );
return $root_resolver( $user, $args, $context, $info );
}

return null;
},
)
);
}
public static function add_customer_to_jwt_user_types( $types ) {
$types[] = 'Customer';

$fields = array_merge( $fields, $jwt_token_fields );

return $fields;
return $types;
}

/**
* Adds all JWT related fields to the Customer mutation output.
*
* @param array $fields mutation output field definitions.
* @param array $fields Mutation output field definitions.
* @param \WPGraphQL\Type\WPInputObjectType $object The WPInputObjectType the fields are be added to.
* @param \WPGraphQL\Registry\TypeRegistry $type_registry TypeRegistry instance.
*/
public static function add_jwt_output_fields( $fields ) {
public static function add_jwt_output_fields( $fields, $object, $type_registry ) {
$fields = array_merge(
$fields,
array(
'authToken' => array(
'type' => \WPGraphQL\Types::string(),
'type' => $type_registry->get_type( 'String' ),
'description' => __( 'JWT Token that can be used in future requests for Authentication', 'wp-graphql-woocommerce' ),
'resolve' => function( $payload ) {
$user = get_user_by( 'ID', $payload['id'] );
Expand All @@ -87,7 +70,7 @@ public static function add_jwt_output_fields( $fields ) {
},
),
'refreshToken' => array(
'type' => \WPGraphQL\Types::string(),
'type' => $type_registry->get_type( 'String' ),
'description' => __( 'A JWT token that can be used in future requests to get a refreshed jwtAuthToken. If the refresh token used in a request is revoked or otherwise invalid, a valid Auth token will NOT be issued in the response headers.', 'wp-graphql-woocommerce' ),
'resolve' => function( $payload ) {
$user = get_user_by( 'ID', $payload['id'] );
Expand Down
7 changes: 6 additions & 1 deletion includes/class-type-registry.php
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ public function init( \WPGraphQL\Registry\TypeRegistry $type_registry ) {
\WPGraphQL\WooCommerce\Type\WPEnum\Manage_Stock::register();
\WPGraphQL\WooCommerce\Type\WPEnum\Order_Status::register();
\WPGraphQL\WooCommerce\Type\WPEnum\Product_Types::register();
\WPGraphQL\WooCommerce\Type\WPEnum\Product_Attribute_Types::register();
\WPGraphQL\WooCommerce\Type\WPEnum\Stock_Status::register();
\WPGraphQL\WooCommerce\Type\WPEnum\Tax_Class::register();
\WPGraphQL\WooCommerce\Type\WPEnum\Tax_Status::register();
Expand Down Expand Up @@ -54,15 +55,17 @@ public function init( \WPGraphQL\Registry\TypeRegistry $type_registry ) {

// Interfaces.
\WPGraphQL\WooCommerce\Type\WPInterface\Product::register_interface( $type_registry );
\WPGraphQL\WooCommerce\Type\WPInterface\Product_Attribute::register_interface( $type_registry );

// Objects.
\WPGraphQL\WooCommerce\Type\WPObject\Coupon_Type::register();
\WPGraphQL\WooCommerce\Type\WPObject\Product_Types::register();
\WPGraphQL\WooCommerce\Type\WPObject\Product_Attribute_Types::register();
\WPGraphQL\WooCommerce\Type\WPObject\Product_Variation_Type::register();
\WPGraphQL\WooCommerce\Type\WPObject\Order_Type::register();
\WPGraphQL\WooCommerce\Type\WPObject\Order_Item_Type::register();
\WPGraphQL\WooCommerce\Type\WPObject\Downloadable_Item_Type::register();
\WPGraphQL\WooCommerce\Type\WPObject\Refund_Type::register();
\WPGraphQL\WooCommerce\Type\WPObject\Product_Attribute_Type::register();
\WPGraphQL\WooCommerce\Type\WPObject\Product_Download_Type::register();
\WPGraphQL\WooCommerce\Type\WPObject\Customer_Type::register();
\WPGraphQL\WooCommerce\Type\WPObject\Customer_Address_Type::register();
Expand All @@ -81,10 +84,12 @@ public function init( \WPGraphQL\Registry\TypeRegistry $type_registry ) {
// Connections.
\WPGraphQL\WooCommerce\Connection\Posts::register_connections();
\WPGraphQL\WooCommerce\Connection\WC_Terms::register_connections();
\WPGraphQL\WooCommerce\Connection\Product_Reviews::register_connections();
\WPGraphQL\WooCommerce\Connection\Coupons::register_connections();
\WPGraphQL\WooCommerce\Connection\Products::register_connections();
\WPGraphQL\WooCommerce\Connection\Orders::register_connections();
\WPGraphQL\WooCommerce\Connection\Order_Items::register_connections();
\WPGraphQL\WooCommerce\Connection\Downloadable_Items::register_connections();
\WPGraphQL\WooCommerce\Connection\Refunds::register_connections();
\WPGraphQL\WooCommerce\Connection\Product_Attributes::register_connections();
\WPGraphQL\WooCommerce\Connection\Variation_Attributes::register_connections();
Expand Down
70 changes: 70 additions & 0 deletions includes/connection/class-downloadable-items.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
<?php
/**
* Connection - Downloadable_Items
*
* Registers connections to DownloadableItem
*
* @package WPGraphQL\WooCommerce\Connection
* @since 0.4.0
*/

namespace WPGraphQL\WooCommerce\Connection;

use WPGraphQL\WooCommerce\Data\Factory;

/**
* Class - Downloadable_Items
*/
class Downloadable_Items {
/**
* Registers the various connections from other Types to DownloadableItem
*/
public static function register_connections() {
// From Order.
register_graphql_connection( self::get_connection_config() );
}

/**
* Given an array of $args, this returns the connection config, merging the provided args
* with the defaults
*
* @access public
* @param array $args - Connection configuration.
*
* @return array
*/
public static function get_connection_config( $args = array() ) {
$defaults = array(
'fromType' => 'Order',
'toType' => 'DownloadableItem',
'fromFieldName' => 'downloadableItems',
'connectionArgs' => self::get_connection_args(),
'resolve' => function ( $source, $args, $context, $info ) {
return Factory::resolve_downloadable_item_connection( $source, $args, $context, $info );
},
);
return array_merge( $defaults, $args );
}

/**
* Returns array of where args
*
* @return array
*/
public static function get_connection_args() {
return array(
'active' => array(
'type' => 'Boolean',
'description' => __( 'Limit results to downloadable items that can be downloaded now.', 'wp-graphql-woocommerce' ),
),
'expired' => array(
'type' => 'Boolean',
'description' => __( 'Limit results to downloadable items that are expired.', 'wp-graphql-woocommerce' ),
),
'hasDownloadsRemaining' => array(
'type' => 'Boolean',
'description' => __( 'Limit results to downloadable items that have downloads remaining.', 'wp-graphql-woocommerce' ),
),
);
}
}
36 changes: 35 additions & 1 deletion includes/connection/class-product-attributes.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,26 @@ class Product_Attributes {
public static function register_connections() {
// From Product to ProductAttribute.
register_graphql_connection( self::get_connection_config() );

// From Product to LocalProductAttribute.
register_graphql_connection(
self::get_connection_config(
array(
'toType' => 'LocalProductAttribute',
'fromFieldName' => 'localAttributes',
)
)
);

// From Product to GlobalProductAttribute.
register_graphql_connection(
self::get_connection_config(
array(
'toType' => 'GlobalProductAttribute',
'fromFieldName' => 'globalAttributes',
)
)
);
}

/**
Expand All @@ -38,12 +58,26 @@ public static function get_connection_config( $args = array() ) {
'fromType' => 'Product',
'toType' => 'ProductAttribute',
'fromFieldName' => 'attributes',
'connectionArgs' => array(),
'connectionArgs' => self::get_connection_args(),
'resolve' => function ( $root, $args, $context, $info ) {
return Factory::resolve_product_attribute_connection( $root, $args, $context, $info );
},
);

return array_merge( $defaults, $args );
}

/**
* Returns array of where args
*
* @return array
*/
public static function get_connection_args() {
return array(
'type' => array(
'type' => 'ProductAttributeTypesEnum',
'description' => __( 'Filter results by attribute scope.', 'wp-graphql-woocommerce' ),
),
);
}
}
Loading