The meaning of @filter on predicates

What I want to do

I am trying to find nodes that have a certain string value in some of its string predicates. For all those nodes, I want to only retrieve the predicates that match the string value, not the others.

What I did

I ran the following query:

{
  pred1 as var(func: has(<first_name>)) @filter(eq(<first_name>, "George"))
  pred2 as var(func: has(<last_name>)) @filter(eq(<last_name>, "George"))

  result (func: uid(pred1,pred2)) {
    uid
    <first_name> @filter(eq(<first_name>, "George"))
    <last_name> @filter(eq(<last_name>, "George"))
  }
}

I get all uid’s that have the string "George" in either first_name or last_name, but I retrieve both predicates no matter if they match the eq filter.

How can I filter server-side to retrieve only those predicates that match the filter?

That should be the query.

{
  pred1 as var(func: has(<first_name>)) @filter(eq(<first_name>, "George"))
  pred2 as var(func: has(<last_name>)) @filter(eq(<last_name>, "George"))

  result (func: uid(pred1,pred2)) 
  @filter(eq(<first_name>, "George") 
      AND eq(<last_name>, "George")){
         uid
         <first_name> 
         <last_name>
  }
}

But this doesn’t make sense. You wanna find a user called “George George”??

I want to retrieve all nodes that have either first_name or last_name equal "George", and for those nodes I want to only retrieve the predicate that equals "George".

So I do not want to retrieve

      {
        "uid": "0x3",
        "first_name": "George",
        "last_name": "Lucas"
      },
      {
        "uid": "0x4",
        "first_name": "Götz",
        "last_name": "George"
      }

but

      {
        "uid": "0x3",
        "first_name": "George",
      },
      {
        "uid": "0x4",
        "last_name": "George"
      }

Any chance to do that in DQL?

ahhh! get it.

No, it is not possible to have an optional predicate in the response based on the value.