self::get_input_fields(), 'outputFields' => self::get_output_fields(), 'mutateAndGetPayload' => self::mutate_and_get_payload(), ] ); } /** * Defines the mutation input field configuration * * @return array */ public static function get_input_fields() { return [ 'id' => [ 'type' => [ 'non_null' => 'Int' ], 'description' => static function () { return __( 'The ID of the tax rate to update.', 'graphql-for-ecommerce' ); }, ], ]; } /** * Defines the mutation output field configuration * * @return array */ public static function get_output_fields() { return [ 'taxRate' => [ 'type' => 'TaxRate', 'resolve' => static function ( $payload ) { return $payload['taxRate']; }, ], ]; } /** * Defines the mutation data modification closure. * * @return callable */ public static function mutate_and_get_payload() { return static function ( $input, AppContext $context, ResolveInfo $info ) { if ( ! \wc_rest_check_manager_permissions( 'settings', 'delete' ) ) { throw new UserError( __( 'Sorry, you are not allowed to delete tax rates.', 'graphql-for-ecommerce' ), \rest_authorization_required_code() ); } global $wpdb; $id = Utils::get_database_id_from_id( $input['id'] ); if ( ! $id ) { throw new UserError( __( 'Invalid tax rate ID.', 'graphql-for-ecommerce' ) ); } $tax = $context->get_loader( 'tax_rate' )->load( $id ); if ( ! $tax ) { throw new UserError( __( 'Failed to locate tax rate', 'graphql-for-ecommerce' ) ); } /** * Action before deleting tax rate. * * @param object $tax_rate The tax rate object. * @param array $input Request input. */ do_action( 'graphql_woocommerce_before_tax_rate_delete', $tax, $input ); \WC_Tax::_delete_tax_rate( $id ); if ( 0 === $wpdb->rows_affected ) { throw new UserError( __( 'Failed to delete tax rate.', 'graphql-for-ecommerce' ) ); } /** * Filter tax rate object before responding. * * @param object $tax_rate The shipping method object. * @param array $input Request input. */ $tax = apply_filters( 'graphql_woocommerce_tax_rate_delete', $tax, $input ); return [ 'taxRate' => $tax, ]; }; } }