Org-roam-refile :: no filter function support

Hi,
I have implemented filter functions with other org-roam functions (e.g. org-roam-node-find), but it seems there’s no ability to use a filter function with org-roam-refile. Is there an alternative method to achieve something similar?

It seems filtering the list of nodes to refile into could be useful.

One way might be to use advice-add like this perhaps?
Seems to work on my end.

You’d need to add your own filter function in place of my lambda function in +org-roam-node-read below.

One cautious note is that it changes the behavour of org-roam-node-read, which is widely used such as org-roam-node-find and org-roam-capture, etc.
(advice-remove #'org-roam-node-read #'+org-roam-node-read) removes the advice to return to the original behaviour. Please understand how you can remove the advice before you try it.

unwind-protect is there to remove the advice even when you cancel the refile operation – this seems to work, but please test it thoroughly on your end…

(defun +org-roam-node-read (orig-fn &rest args)
  (funcall orig-fn nil (lambda (node)
                         (string= "2023-05-19T181811" (org-roam-node-id node)))
           nil 'require-match))

(defun my/org-roam-refile ()
  (interactive)
  (advice-add #'org-roam-node-read :around #'+org-roam-node-read)
  (unwind-protect
      (org-roam-refile)
    (advice-remove #'org-roam-node-read #'+org-roam-node-read)))

Thanks Nobiot, I have tested this and it seems to work perfectly from what I can tell.

I have incorporated it into my setup.
I’ll continue to use it & post an update if I encounter any problems - for the benefit of anyone else who stumbles onto this.