Provided you have a rich text (portable text) field called body, you can query all links it contains like this:

*[ defined(body) ]
  .body[ _type == "block" ]
  .markDefs[ _type == "link" ]
  .href

And if instead you want to list documents which contain a specific link (here /searched/path) in their rich text field (here body), you can do it like this:

*[ defined(body) ] {
  body
}[
  count(
     body[ _type == "block" ]
    .markDefs[ _type == "link" ]
    [ href == "/searched/path" ]
  ) > 0
]

Kind thanks to Julia for her help with these queries.

Read previous snippet: <IconLink />

Read next snippet: .ribbon {}