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 [ 'slug' => [ 'type' => [ 'non_null' => 'String' ], 'description' => static function () { return __( 'Slug of the tax class.', 'graphql-for-ecommerce' ); }, ], ]; } /** * Defines the mutation output field configuration * * @return array */ public static function get_output_fields() { return [ 'taxClass' => [ 'type' => 'TaxClass', 'resolve' => static function ( $payload ) { return ! empty( $payload['taxClass'] ) ? $payload['taxClass'] : null; }, ], ]; } /** * 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 classes.', 'graphql-for-ecommerce' ), \rest_authorization_required_code() ); } $slug = $input['slug']; /** @var array|false $tax_class */ $tax_class = \WC_Tax::get_tax_class_by( 'slug', $slug ); if ( ! $tax_class ) { throw new UserError( __( 'Invalid tax class slug.', 'graphql-for-ecommerce' ) ); } /** * Action hook before deleting tax class. * * @param array $tax_class The tax class object. * @param array $input Request input. */ do_action( 'graphql_woocommerce_before_tax_class_delete', $tax_class, $input ); $deleted = \WC_Tax::delete_tax_class_by( 'slug', $slug ); if ( ! $deleted ) { throw new UserError( __( 'Failed to delete tax class.', 'graphql-for-ecommerce' ) ); } /** * Filter tax class object before responding. * * @param array $tax_class The shipping method object. * @param array $input Request input. */ $tax_class = apply_filters( 'graphql_woocommerce_tax_class_delete', $tax_class, $input ); return [ 'taxClass' => $tax_class ]; }; } }