Skip to content

Commit 8afc1e9

Browse files
committed
More queries updated.
1 parent 43d529f commit 8afc1e9

11 files changed

+129
-52
lines changed

includes/mutation/class-checkout.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -97,7 +97,7 @@ public static function get_output_fields() {
9797
return is_user_logged_in() ? new Customer( get_current_user_id() ) : null;
9898
},
9999
),
100-
'result' => array(
100+
'result' => array(
101101
'type' => 'String',
102102
'resolve' => function( $payload ) {
103103
return $payload['result'];

includes/type/enum/class-id-type-enums.php

Lines changed: 16 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ public static function register() {
2323
register_graphql_enum_type(
2424
'CouponIdTypeEnum',
2525
array(
26-
'description' => __( 'The Type of Identifier used to fetch a single resource. Default is ID.', 'wp-graphql' ),
26+
'description' => __( 'The Type of Identifier used to fetch a single Coupon. Default is ID.', 'wp-graphql' ),
2727
'values' => array(
2828
'id' => self::get_value( 'id' ),
2929
'database_id' => self::get_value( 'database_id' ),
@@ -39,7 +39,7 @@ public static function register() {
3939
register_graphql_enum_type(
4040
'OrderIdTypeEnum',
4141
array(
42-
'description' => __( 'The Type of Identifier used to fetch a single resource. Default is ID.', 'wp-graphql' ),
42+
'description' => __( 'The Type of Identifier used to fetch a single Order. Default is ID.', 'wp-graphql' ),
4343
'values' => array(
4444
'id' => self::get_value( 'id' ),
4545
'database_id' => self::get_value( 'database_id' ),
@@ -55,7 +55,7 @@ public static function register() {
5555
register_graphql_enum_type(
5656
'ProductIdTypeEnum',
5757
array(
58-
'description' => __( 'The Type of Identifier used to fetch a single resource. Default is ID.', 'wp-graphql' ),
58+
'description' => __( 'The Type of Identifier used to fetch a single Product. Default is ID.', 'wp-graphql' ),
5959
'values' => array(
6060
'id' => self::get_value( 'id' ),
6161
'database_id' => self::get_value( 'database_id' ),
@@ -72,7 +72,7 @@ public static function register() {
7272
register_graphql_enum_type(
7373
'ProductVariationIdTypeEnum',
7474
array(
75-
'description' => __( 'The Type of Identifier used to fetch a single resource. Default is ID.', 'wp-graphql' ),
75+
'description' => __( 'The Type of Identifier used to fetch a single ProductVariation. Default is ID.', 'wp-graphql' ),
7676
'values' => array(
7777
'id' => self::get_value( 'id' ),
7878
'database_id' => self::get_value( 'database_id' ),
@@ -83,7 +83,18 @@ public static function register() {
8383
register_graphql_enum_type(
8484
'RefundIdTypeEnum',
8585
array(
86-
'description' => __( 'The Type of Identifier used to fetch a single resource. Default is ID.', 'wp-graphql' ),
86+
'description' => __( 'The Type of Identifier used to fetch a single Refund. Default is ID.', 'wp-graphql' ),
87+
'values' => array(
88+
'id' => self::get_value( 'id' ),
89+
'database_id' => self::get_value( 'database_id' ),
90+
),
91+
)
92+
);
93+
94+
register_graphql_enum_type(
95+
'ShippingMethodIdTypeEnum',
96+
array(
97+
'description' => __( 'The Type of Identifier used to fetch a single Shipping Method. Default is ID.', 'wp-graphql' ),
8798
'values' => array(
8899
'id' => self::get_value( 'id' ),
89100
'database_id' => self::get_value( 'database_id' ),

includes/type/interface/class-product-attribute.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ public static function get_fields() {
6060
return ! empty( $attribute->get_name() ) ? $attribute->get_name() : null;
6161
},
6262
),
63-
'options' => array(
63+
'options' => array(
6464
'type' => array( 'list_of' => 'String' ),
6565
'description' => __( 'Attribute options', 'wp-graphql-woocommerce' ),
6666
'resolve' => function ( $attribute ) {

includes/type/interface/class-product.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,8 @@ public static function register_interface( &$type_registry ) {
5656
'description' => __( 'A product object', 'wp-graphql-woocommerce' ),
5757
'args' => array(
5858
'id' => array(
59-
'type' => array( 'non_null' => 'ID' ),
59+
'type' => array( 'non_null' => 'ID' ),
60+
'description' => __( 'The ID for identifying the product', 'wp-graphql-woocommerce' ),
6061
),
6162
'idType' => array(
6263
'type' => 'ProductIdTypeEnum',

includes/type/object/class-order-type.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -329,7 +329,7 @@ public static function register() {
329329
'args' => array(
330330
'id' => array(
331331
'type' => 'ID',
332-
'description' => __( 'Get the order by its global ID', 'wp-graphql-woocommerce' ),
332+
'description' => __( 'The ID for identifying the order', 'wp-graphql-woocommerce' ),
333333
),
334334
'idType' => array(
335335
'type' => 'OrderIdTypeEnum',

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

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -315,7 +315,11 @@ private static function register_product_query( $type ) {
315315
'args' => array(
316316
'id' => array(
317317
'type' => 'ID',
318-
'description' => __( 'ID to identify product with', 'wp-graphql-woocommerce' ),
318+
'description' => sprintf(
319+
/* translators: %s: product type */
320+
__( 'The ID for identifying the %s product', 'wp-graphql-woocommerce' ),
321+
$type
322+
),
319323
),
320324
'idType' => array(
321325
'type' => 'ProductIdTypeEnum',

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

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -253,15 +253,15 @@ public static function register() {
253253
'args' => array(
254254
'id' => array(
255255
'type' => 'ID',
256-
'description' => __( 'Get the product variation by its global ID', 'wp-graphql-woocommerce' ),
256+
'description' => __( 'The ID for identifying the product variation', 'wp-graphql-woocommerce' ),
257257
),
258258
'idType' => array(
259259
'type' => 'ProductVariationIdTypeEnum',
260260
'description' => __( 'Type of ID being used identify product variation', 'wp-graphql-woocommerce' ),
261261
),
262262
'variationId' => array(
263-
'type' => 'Int',
264-
'description' => __( 'Get the product variation by its database ID', 'wp-graphql-woocommerce' ),
263+
'type' => 'Int',
264+
'description' => __( 'Get the product variation by its database ID', 'wp-graphql-woocommerce' ),
265265
'isDeprecated' => true,
266266
'deprecationReason' => __(
267267
'This argument has been deprecation, and will be removed in v0.5.x. Please use "productVariation(id: value, idType: DATABASE_ID)" instead',

includes/type/object/class-refund-type.php

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -71,9 +71,8 @@ public static function register() {
7171
'description' => __( 'A refund object', 'wp-graphql-woocommerce' ),
7272
'args' => array(
7373
'id' => array(
74-
'type' => array(
75-
'non_null' => 'ID',
76-
),
74+
'type' => array( 'non_null' => 'ID' ),
75+
'description' => __( 'The ID for identifying the refund', 'wp-graphql-woocommerce' ),
7776
),
7877
'idType' => array(
7978
'type' => 'RefundIdTypeEnum',

includes/type/object/class-shipping-method-type.php

Lines changed: 37 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -61,26 +61,49 @@ public static function register() {
6161
'args' => array(
6262
'id' => array(
6363
'type' => 'ID',
64-
'description' => __( 'Get the shipping method by its global ID', 'wp-graphql-woocommerce' ),
64+
'description' => __( 'The ID for identifying the shipping method', 'wp-graphql-woocommerce' ),
65+
),
66+
'idType' => array(
67+
'type' => 'ShippingMethodIdTypeEnum',
68+
'description' => __( 'Type of ID being used identify product variation', 'wp-graphql-woocommerce' ),
6569
),
6670
'methodId' => array(
67-
'type' => 'ID',
68-
'description' => __( 'Get the shipping method by its database ID', 'wp-graphql-woocommerce' ),
71+
'type' => 'ID',
72+
'description' => __( 'Get the shipping method by its database ID', 'wp-graphql-woocommerce' ),
73+
'isDeprecated' => true,
74+
'deprecationReason' => __(
75+
'This argument has been deprecation, and will be removed in v0.5.x. Please use "shippingMethod(id: value, idType: DATABASE_ID)" instead.',
76+
'wp-graphql-woocommerce'
77+
),
6978
),
7079
),
7180
'resolve' => function ( $source, array $args ) {
72-
$method_id = 0;
73-
if ( ! empty( $args['id'] ) ) {
74-
$id_components = Relay::fromGlobalId( $args['id'] );
75-
if ( empty( $id_components['id'] ) || empty( $id_components['type'] ) ) {
76-
throw new UserError( __( 'The "id" is invalid', 'wp-graphql-woocommerce' ) );
77-
}
81+
$id = isset( $args['id'] ) ? $args['id'] : null;
82+
$id_type = isset( $args['idType'] ) ? $args['idType'] : 'global_id';
83+
84+
/**
85+
* Process deprecated arguments
86+
*
87+
* Will be removed in v0.5.x.
88+
*/
89+
if ( ! empty( $args['methodId'] ) ) {
90+
$id = $args['methodId'];
91+
$id_type = 'database_id';
92+
}
7893

79-
$arg = 'ID';
80-
$method_id = $id_components['id'];
81-
} elseif ( ! empty( $args['methodId'] ) ) {
82-
$arg = 'database ID';
83-
$method_id = $args['methodId'];
94+
$method_id = null;
95+
switch ( $id_type ) {
96+
case 'database_id':
97+
$method_id = $id;
98+
break;
99+
case 'global_id':
100+
default:
101+
$id_components = Relay::fromGlobalId( $id );
102+
if ( empty( $id_components['id'] ) || empty( $id_components['type'] ) ) {
103+
throw new UserError( __( 'The "id" is invalid', 'wp-graphql-woocommerce' ) );
104+
}
105+
$method_id = $id_components['id'];
106+
break;
84107
}
85108

86109
return Factory::resolve_shipping_method( $method_id );

includes/type/object/class-tax-rate-type.php

Lines changed: 37 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -97,26 +97,49 @@ public static function register() {
9797
'args' => array(
9898
'id' => array(
9999
'type' => 'ID',
100-
'description' => __( 'Get the tax rate by its global ID', 'wp-graphql-woocommerce' ),
100+
'description' => __( 'The ID for identifying the tax rate', 'wp-graphql-woocommerce' ),
101+
),
102+
'idType' => array(
103+
'type' => 'TaxRateIdTypeEnum',
104+
'description' => __( 'Type of ID being used identify tax rate', 'wp-graphql-woocommerce' ),
101105
),
102106
'rateId' => array(
103-
'type' => 'Int',
104-
'description' => __( 'Get the tax rate by its database ID', 'wp-graphql-woocommerce' ),
107+
'type' => 'Int',
108+
'description' => __( 'Get the tax rate by its database ID', 'wp-graphql-woocommerce' ),
109+
'isDeprecated' => true,
110+
'deprecationReason' => __(
111+
'This argument has been deprecation, and will be removed in v0.5.x. Please use "taxRate(id: value, idType: DATABASE_ID)" instead.',
112+
'wp-graphql-woocommerce'
113+
),
105114
),
106115
),
107116
'resolve' => function ( $source, array $args ) {
108-
$rate_id = 0;
109-
if ( ! empty( $args['id'] ) ) {
110-
$id_components = Relay::fromGlobalId( $args['id'] );
111-
if ( empty( $id_components['id'] ) || empty( $id_components['type'] ) ) {
112-
throw new UserError( __( 'The "id" is invalid', 'wp-graphql-woocommerce' ) );
113-
}
117+
$id = isset( $args['id'] ) ? $args['id'] : null;
118+
$id_type = isset( $args['idType'] ) ? $args['idType'] : 'global_id';
119+
120+
/**
121+
* Process deprecated arguments
122+
*
123+
* Will be removed in v0.5.x.
124+
*/
125+
if ( ! empty( $args['rateId'] ) ) {
126+
$id = $args['rateId'];
127+
$id_type = 'database_id';
128+
}
114129

115-
$arg = 'ID';
116-
$rate_id = absint( $id_components['id'] );
117-
} elseif ( ! empty( $args['rateId'] ) ) {
118-
$arg = 'database ID';
119-
$rate_id = absint( $args['rateId'] );
130+
$rate_id = null;
131+
switch ( $id_type ) {
132+
case 'database_id':
133+
$rate_id = absint( $id );
134+
break;
135+
case 'global_id':
136+
default:
137+
$id_components = Relay::fromGlobalId( $id );
138+
if ( empty( $id_components['id'] ) || empty( $id_components['type'] ) ) {
139+
throw new UserError( __( 'The "id" is invalid', 'wp-graphql-woocommerce' ) );
140+
}
141+
$rate_id = absint( $id_components['id'] );
142+
break;
120143
}
121144

122145
return Factory::resolve_tax_rate( $rate_id );

0 commit comments

Comments
 (0)