Skip to content

Commit 18e66cd

Browse files
lstellwaykidunot89
andauthored
Updates deprecated DataSource::resolve_post_object (#697)
* Updates deprecated DataSource::resolve_post_object * chore: Unneeded class declarations removed. --------- Co-authored-by: Geoff Taylor <[email protected]>
1 parent 82e5e72 commit 18e66cd

File tree

3 files changed

+15
-16
lines changed

3 files changed

+15
-16
lines changed

includes/type/interface/class-product.php

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,6 @@
1313
use GraphQL\Error\UserError;
1414
use GraphQLRelay\Relay;
1515
use WPGraphQL\AppContext;
16-
use WPGraphQL\Data\DataSource;
1716
use WPGraphQL\WooCommerce\Data\Factory;
1817
use WPGraphQL\WooCommerce\WP_GraphQL_WooCommerce;
1918

@@ -189,7 +188,7 @@ public static function get_fields() {
189188
if ( empty( $source->image_id ) || ! absint( $source->image_id ) ) {
190189
return null;
191190
}
192-
return DataSource::resolve_post_object( $source->image_id, $context );
191+
return $context->get_loader( 'post' )->load_deferred( $source->image_id );
193192
},
194193
],
195194
'onSale' => [

includes/type/object/class-product-category-type.php

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@
1111
namespace WPGraphQL\WooCommerce\Type\WPObject;
1212

1313
use WPGraphQL\AppContext;
14-
use WPGraphQL\Data\DataSource;
1514

1615
/**
1716
* Class - Product_Category_Type
@@ -31,7 +30,7 @@ public static function register_fields() {
3130
'resolve' => function( $source, array $args, AppContext $context ) {
3231
$thumbnail_id = get_term_meta( $source->term_id, 'thumbnail_id', true );
3332
return ! empty( $thumbnail_id )
34-
? DataSource::resolve_post_object( $thumbnail_id, $context )
33+
? $context->get_loader( 'post' )->load_deferred( $thumbnail_id )
3534
: null;
3635
},
3736
],

includes/type/object/class-product-variation-type.php

Lines changed: 13 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,6 @@
1313
use GraphQL\Error\UserError;
1414
use GraphQLRelay\Relay;
1515
use WPGraphQL\AppContext;
16-
use WPGraphQL\Data\DataSource;
1716
use WPGraphQL\WooCommerce\Data\Factory;
1817

1918
/**
@@ -75,8 +74,8 @@ public static function register() {
7574
],
7675
'resolve' => function( $source, $args ) {
7776
if ( isset( $args['format'] ) && 'raw' === $args['format'] ) {
78-
// @codingStandardsIgnoreLine.
79-
return $source->priceRaw;
77+
// @codingStandardsIgnoreLine.
78+
return $source->priceRaw;
8079
} else {
8180
return $source->price;
8281
}
@@ -93,11 +92,11 @@ public static function register() {
9392
],
9493
'resolve' => function( $source, $args ) {
9594
if ( isset( $args['format'] ) && 'raw' === $args['format'] ) {
96-
// @codingStandardsIgnoreLine.
97-
return $source->regularPriceRaw;
95+
// @codingStandardsIgnoreLine.
96+
return $source->regularPriceRaw;
9897
} else {
99-
// @codingStandardsIgnoreLine.
100-
return $source->regularPrice;
98+
// @codingStandardsIgnoreLine.
99+
return $source->regularPrice;
101100
}
102101
},
103102
],
@@ -112,11 +111,11 @@ public static function register() {
112111
],
113112
'resolve' => function( $source, $args ) {
114113
if ( isset( $args['format'] ) && 'raw' === $args['format'] ) {
115-
// @codingStandardsIgnoreLine.
116-
return $source->salePriceRaw;
114+
// @codingStandardsIgnoreLine.
115+
return $source->salePriceRaw;
117116
} else {
118-
// @codingStandardsIgnoreLine.
119-
return $source->salePrice;
117+
// @codingStandardsIgnoreLine.
118+
return $source->salePrice;
120119
}
121120
},
122121
],
@@ -232,7 +231,9 @@ public static function register() {
232231
'type' => 'MediaItem',
233232
'description' => __( 'Product variation main image', 'wp-graphql-woocommerce' ),
234233
'resolve' => function( $source, array $args, AppContext $context ) {
235-
return ! empty( $source->image_id ) ? DataSource::resolve_post_object( $source->image_id, $context ) : null;
234+
return ! empty( $source->image_id )
235+
? $context->get_loader( 'post' )->load_deferred( $source->image_id )
236+
: null;
236237
},
237238
],
238239

0 commit comments

Comments
 (0)