Skip to content

Commit

Permalink
Updates deprecated DataSource::resolve_post_object (#697)
Browse files Browse the repository at this point in the history
* Updates deprecated DataSource::resolve_post_object

* chore: Unneeded class declarations removed.

---------

Co-authored-by: Geoff Taylor <geoff@axistaylor.com>
  • Loading branch information
lstellway and kidunot89 committed Feb 1, 2023
1 parent 82e5e72 commit 18e66cd
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 16 deletions.
3 changes: 1 addition & 2 deletions includes/type/interface/class-product.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@
use GraphQL\Error\UserError;
use GraphQLRelay\Relay;
use WPGraphQL\AppContext;
use WPGraphQL\Data\DataSource;
use WPGraphQL\WooCommerce\Data\Factory;
use WPGraphQL\WooCommerce\WP_GraphQL_WooCommerce;

Expand Down Expand Up @@ -189,7 +188,7 @@ public static function get_fields() {
if ( empty( $source->image_id ) || ! absint( $source->image_id ) ) {
return null;
}
return DataSource::resolve_post_object( $source->image_id, $context );
return $context->get_loader( 'post' )->load_deferred( $source->image_id );
},
],
'onSale' => [
Expand Down
3 changes: 1 addition & 2 deletions includes/type/object/class-product-category-type.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@
namespace WPGraphQL\WooCommerce\Type\WPObject;

use WPGraphQL\AppContext;
use WPGraphQL\Data\DataSource;

/**
* Class - Product_Category_Type
Expand All @@ -31,7 +30,7 @@ public static function register_fields() {
'resolve' => function( $source, array $args, AppContext $context ) {
$thumbnail_id = get_term_meta( $source->term_id, 'thumbnail_id', true );
return ! empty( $thumbnail_id )
? DataSource::resolve_post_object( $thumbnail_id, $context )
? $context->get_loader( 'post' )->load_deferred( $thumbnail_id )
: null;
},
],
Expand Down
25 changes: 13 additions & 12 deletions includes/type/object/class-product-variation-type.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@
use GraphQL\Error\UserError;
use GraphQLRelay\Relay;
use WPGraphQL\AppContext;
use WPGraphQL\Data\DataSource;
use WPGraphQL\WooCommerce\Data\Factory;

/**
Expand Down Expand Up @@ -75,8 +74,8 @@ public static function register() {
],
'resolve' => function( $source, $args ) {
if ( isset( $args['format'] ) && 'raw' === $args['format'] ) {
// @codingStandardsIgnoreLine.
return $source->priceRaw;
// @codingStandardsIgnoreLine.
return $source->priceRaw;
} else {
return $source->price;
}
Expand All @@ -93,11 +92,11 @@ public static function register() {
],
'resolve' => function( $source, $args ) {
if ( isset( $args['format'] ) && 'raw' === $args['format'] ) {
// @codingStandardsIgnoreLine.
return $source->regularPriceRaw;
// @codingStandardsIgnoreLine.
return $source->regularPriceRaw;
} else {
// @codingStandardsIgnoreLine.
return $source->regularPrice;
// @codingStandardsIgnoreLine.
return $source->regularPrice;
}
},
],
Expand All @@ -112,11 +111,11 @@ public static function register() {
],
'resolve' => function( $source, $args ) {
if ( isset( $args['format'] ) && 'raw' === $args['format'] ) {
// @codingStandardsIgnoreLine.
return $source->salePriceRaw;
// @codingStandardsIgnoreLine.
return $source->salePriceRaw;
} else {
// @codingStandardsIgnoreLine.
return $source->salePrice;
// @codingStandardsIgnoreLine.
return $source->salePrice;
}
},
],
Expand Down Expand Up @@ -232,7 +231,9 @@ public static function register() {
'type' => 'MediaItem',
'description' => __( 'Product variation main image', 'wp-graphql-woocommerce' ),
'resolve' => function( $source, array $args, AppContext $context ) {
return ! empty( $source->image_id ) ? DataSource::resolve_post_object( $source->image_id, $context ) : null;
return ! empty( $source->image_id )
? $context->get_loader( 'post' )->load_deferred( $source->image_id )
: null;
},
],

Expand Down

0 comments on commit 18e66cd

Please sign in to comment.