Query todos recursively under ProjectA/Module1/Sub-Module1

Hi all,

I have the following page structures to track my projects

ProjectA/Module1/Sub-Module1
ProjectA/Module1/Sub-Module2
ProjectA/Module2/Sub-Module1

I would like a list of all todos in Module1 - i.e. todos in Module1, Sub-Module1, Sub-Module2 - to show in Module1 for a query.

Similarly for ProjectA all Todos recursively under the pages reference in it.

Can someone please suggest a query to add in each of the pages, such that it shows the todos of the pages referenced under it?

Regards,
#Valmick

I have a similar setup. After a lot of trial and error, I landed at the following query, based on this hint:

#+BEGIN_QUERY
{ :title "List tasks within namespace"
  :query [:find (pull ?b [*])
        :in $ ?current-page %
        :where
        [?b :block/marker ?marker]
        [?b :block/page ?p]
        [(contains? #{"TODO"} ?marker)]
        [?ns :block/name ?current-page]
        (ns-rec ?p ?ns)
    ]
  :inputs
    [:current-page
        [
                [[ns-rec ?b ?ns]
				[(= ?b ?ns)]]
                [[ns-rec ?b ?ns]
				[?b :block/namespace ?ns]]
				[[ns-rec ?b ?ns]
				[?child :block/namespace ?ns]
				(ns-rec ?b ?child)]]]
  :result-transform (fn [result]
      (->> result
         (map (fn [r] (assoc r :block/properties {"priority" (get r :block/priority)})))
      )
   )
  :collapsed? False
}
#+END_QUERY
1 Like
#+BEGIN_QUERY
{
 :query [:find (pull ?b [*])
    :in $ % 
         :where
     [?nsn :block/name "projecta/module1"]
     [ns ?nsn ?p]
     [?b :block/page ?p]
     [?b :block/marker ?m]
     [(contains? #{"TODO"} ?m)]
]
 :rules [[(ns ?p ?c)
     [?c :block/namespace ?p]]
    [(ns ?p ?c)
     [?t :block/namespace ?p]
     (ns ?t ?c)]] 
}
#+END_QUERY