DQL conditional upsert with nested query value variables

Dgraph’s @if upserts currently do not directly support string equals in the directive itself. You’ll want to do those matches in the query and then match against the len() of your query variable.

Something like this will work, essentially moving your conditional check into the query section:

upsert {
  query {
    p as payment(func: uid(0x2)) {
      uid
      Payment.method
      Payment.isSuccessful
      Payment.reference {
        chargeId as ExternalXCharge.id
      }
    }
    match as var(func: eq(val(chargeId), "x_charge_id_12345"))
  }
  mutation @if(eq(len(match), 1)) {
    set {
      uid(p) <Payment.isSuccessful> "true" .
    }
  }
}


Yup, that’s expected. The encoding here accounts for the multi-tenancy namespace available in the enterprise version and Dgraph Cloud.

1 Like