spinelsun
(Or Chen)
January 6, 2021, 10:46am
1
I Want to Do
Filter all branches that don’t have the name master and find their latest version.
What I Did
var(func: uid($repoId)){
Repository.branches @filter(NOT eq(Branch.name, "master")){
Branch.versions {
N as Version.number
}
LV as max(val(N))
}
}
repo_branches(func: uid($repoId), first: 8) @normalize {
Repository.branches(orderasc: Branch.name){
branch_name: Branch.name
Branch.versions @filter(eq(Version.number, val(LV))) {
latest_version: Version.number
}
}
}
Error
"errors": [
{
"message": ": eq expects atleast 1 argument.",
"extensions": {
"code": "ErrorInvalidRequest"
}
}
]
Any idea for why does it happen?
Thanks,
spinelsun
MichelDiz
(Michel Diz)
January 6, 2021, 3:28pm
2
Weird, it works just fine on my end. As it should, there is nothing wrong in that query.
spinelsun
(Or Chen)
January 6, 2021, 4:10pm
3
It is part of this query maybe something is wrong in the larger scope:
var(func: uid($repoId)){
Repository.branches @filter(eq(Branch.name, "master")){
Branch.versions{
NUM as Version.number
}
LATEST as max(val(NUM))
}
}
var(func: uid($repoId)){
Repository.branches @filter(NOT eq(Branch.name, "master")) {
Branch.versions {
N as Version.number
}
LV as max(val(N))
}
}
get_repo(func: uid($repoId)) {
name: Repository.name
uname: Repository.unique_name
description: Repository.description
is_public: Repository.is_public
last_update: Repository.last_updated
created_at: Repository.created_at
owner: Repository.owner {
uid
username: User.username
}
Repository.branches @filter(eq(Branch.name, "master")) {
Branch.name
Branch.versions @filter(eq(Version.number, val(LATEST))) {
number: Version.number
Version.artifacts (orderasc: Artifact.name) {
types: dgraph.type
name: Artifact.name
last_updated: Artifact.last_updated
}
}
}
}
repo_branches(func: uid($repoId), first: 7) @normalize {
Repository.branches(orderdesc: Branch.last_updated, orderasc: Branch.name){
branch_name: Branch.name
Branch.versions @filter(eq(Version.number, val(LV))) {
latest_version: Version.number
}
}
}
}
Update
I tried it by it self and it didn’t work either.
I am checking if it happens in a grater version of dgraph.
I used 20.03.0
and upgrading know to the latest
spinelsun
(Or Chen)
January 6, 2021, 4:50pm
4
@MichelDiz
Ok I figured it out
The reason that it doesn’t work is that I don’t have branches that are not the Master
.
So no data reutrns from the var LV and as a result the eq function fails.
Any ideas how to bypass it?
1 Like
MichelDiz
(Michel Diz)
January 6, 2021, 4:59pm
5
Nope, maybe a fake master with empty values?
This could fit Custom Block - Discussion - As you could have a string value variable to avoid this problem.
Also, I think this error is bad, cuz it throws an erroneous error message that might confuse users who don’t have a full idea of their dataset. We should improve it. @dmai @hardik
In this case we should throw an error like “the value variable returned empty value”.
spinelsun
(Or Chen)
January 6, 2021, 5:12pm
6
I used the following filter @filter(Not eq(Branch.name, "master")
in the query so now the whole solution looks like this:
var(func: uid($repoId)){
Repository.branches @filter(NOT eq(Branch.name, "master")) {
Branch.versions {
N as Version.number
}
LV as max(val(N))
}
}
repo_branches(func: uid($repoId), first: 7) @normalize {
Repository.branches(orderdesc: Branch.last_updated, orderasc: Branch.name) @filter(Not eq(Branch.name, "master")){
branch_name: Branch.name
Branch.versions @filter(eq(Version.number, val(LV))) {
latest_version: Version.number
}
}
}
What do you think
MichelDiz
(Michel Diz)
January 6, 2021, 5:37pm
7
Not sure what to look here. This looks pretty much the same to me.
spinelsun
(Or Chen)
January 6, 2021, 5:47pm
8
I added another filter on the query itself on the Repository.branches predicate after the sorting block
So now I don’t arrive to this equal function with an empty variable