Filtering UIDs in DQL Upsert Query


Report a Dgraph Bug

What version of Dgraph are you using?

SlashGraphql v20.11.2-rc1-16-g4d041a3a

Have you tried reproducing the issue with the latest release?

Yes

What is the hardware spec (RAM, OS)?

N/A

Steps to reproduce the issue (command/config used to run Dgraph).

I am writing a pretty complex upsert query in DQL. I want to do something like:

...
Competition.competitors @cascade {
    winningCompetitor as uid
    Competitor.entity @filter(uid(winningTeamID)) {
        uid
    }
}
...

In the query block so I can then do the following in the mutation block:

set {
    ...
    uid(losingCompetitor) <Competitor.winner> "false"^^<xs:boolean> .
    uid(winningCompetitor) <Competitor.winner> "true"^^<xs:boolean> .
    ...
}

Expected behaviour and actual result.

I would like the losingCompetitor and winningCompetitor variables to be correctly bound to the subset of UIDs that represent losing and winning competitors, respectively, based on the winningTeamID filter.

However, I am finding that despite the query results only SHOWING the correct UIDs for losingCompetitor and winningCompetitor respectively, I find when I run the mutation, those variables are actually bound to all of the UIDs and therefore wrong in the context of the mutation. I am wondering if I am misunderstanding the use of the @cascade directive here, will it not actually filter out those UIDs when it comes to binding to a variable with uid() and instead just visually filters out records with missing subfields?


Try something like

Competition.competitors @filter(uid_in(Competitor.entity, uid(winningTeamID) )) {
    winningCompetitor as uid
}