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 [ 'keys' => [ 'type' => [ 'list_of' => 'ID' ], 'description' => static function () { return __( 'Cart item key of the item being removed', 'graphql-for-ecommerce' ); }, ], ]; } /** * Defines the mutation output field configuration * * @return array */ public static function get_output_fields() { return Cart_Remove_Items::get_output_fields(); } /** * Defines the mutation data modification closure. * * @return callable */ public static function mutate_and_get_payload() { return static function ( $input, AppContext $context, ResolveInfo $info ) { Cart_Mutation::check_session_token(); if ( empty( $input['keys'] ) ) { throw new UserError( __( 'No cart item keys provided', 'graphql-for-ecommerce' ) ); } // Restore cart items. foreach ( $input['keys'] as $key ) { $success = \WC()->cart->restore_cart_item( $key ); if ( false === $success ) { /* translators: Cart item not found message */ throw new UserError( sprintf( __( 'Failed to restore cart item with the key: %s', 'graphql-for-ecommerce' ), $key ) ); } } $cart_items = Cart_Mutation::retrieve_cart_items( $input, $context, $info, 'restore' ); do_action( 'woographql_update_session', true ); // Return payload. return [ 'items' => $cart_items ]; }; } }