Use Facets for Sorting

What I want to do

I want to query database to find nodes and sort them by facet edge value.

What I did

I set database with these data

{
  set {
    _:Node1 <hostname> "localhost" .
    _:Node2 <hostname> "server1" .
    
    _:A <name> "A" .
    _:A <link> _:Node1 (weight=1) .

    _:B <name> "B" .
    _:B <link> _:Node1 (weight=2) .
    _:B <link> _:Node2 (weight=12) .

    _:C <name> "C" .
    _:C <link> _:Node1 (weight=3) .
    _:C <link> _:Node2 (weight=11) .

    _:C <name> "D" .
    _:C <link> _:Node1 (weight=4) .
    _:C <link> _:Node2 (weight=10) .
    
  }
}

And after, I am trying to get all nodes connected via to Node1 (with hostname == “localhost”) and sort them by facet weight.

I expect to get something like this:

{
    r: [
       {"name": D, "weight": 4}, 
       {"name": C, "weight": 3}, 
       {"name": B, "weight": 2}, 
       {"name": A, "weight": 1}, 
    ]
}

And also I want to be able to get all nodes connected via to Node2 (with hostname == “server1”) and sort them by facet weight. And here I expect to get:

{
    r: [
       {"name": B, "weight": 12}, 
       {"name": C, "weight": 11}, 
       {"name": D, "weight": 10}, 
    ]
}

But unfortunately, I have no idea how I can do it. I am started from this query:

{
   n(func: eq(hostname, "localhost")) {
		U as uid
  }
  
  q(func: has(name)) @filter(uid_in(link, uid(U)))   {
    name
    link @filter(uid(U)) @facets(w as weight) {
      hostname
      val(w)
    }
  }
}

But I don’t know, how to apply filter and fetch facet weight value in query. Any help appreciated. Thanks!

Dgraph metadata

v21.03.0