I want to order by predicates is_default_nickname asc and sub_for_count desc. is_default_nickname ordering is priority then sub_for_count.
I run this big query:
query qlink($uuid: string, $limit: int, $top_100_limit: int) {
var(func: eq(uuid, $uuid)) {
we_may_know1 as ~HAS_CONTACT
we_may_know2 as HAS_CONTACT
target_uuid as uuid
}
qlinks as var(func: uid(we_may_know1, we_may_know2)) {
links as count(HAS_CONTACT @filter(uid(we_may_know1, we_may_know2)))
subs as count(~SUBSCRIBED @filter(uid(target_uuid)))
in_block as count(BLACKLISTED @filter(uid(target_uuid)))
out_block as count(~BLACKLISTED @filter(uid(target_uuid)))
default_nickname as is_default_nickname
}
top100_filtered as var(func: type("Top_100")) {
top100_subs as count(~SUBSCRIBED @filter(uid(target_uuid)))
top100_in_block as count(BLACKLISTED @filter(uid(target_uuid)))
top100_out_block as count(~BLACKLISTED @filter(uid(target_uuid)))
}
sort_nickname_value as var(func: uid(qlinks), first: $limit, orderdesc: val(links)) @filter(
has(uuid)
and not uid(target_uuid)
and (NOT has(is_blocked) or eq(is_blocked, 0))
and (NOT has(is_shadow_banned) or eq(is_shadow_banned, 0))
and eq(val(in_block), 0)
and eq(val(out_block), 0)
and eq(val(subs), 0)
) {
uuid
}
main(func: uid(sort_nickname_value), orderasc: val(default_nickname)) {
uuid
is_default_nickname
}
top_100_sub_for_count_sorting as var(
func: uid(top100_filtered),
orderasc: is_default_nickname, #<------ first ordering line
orderdesc: sub_for_count, #<------ second ordering line
first:$top_100_limit
) @filter(
has(uuid)
and not uid(target_uuid)
and (NOT has(is_blocked) or eq(is_blocked, 0))
and (NOT has(is_shadow_banned) or eq(is_shadow_banned, 0))
and eq(val(top100_in_block), 0)
and eq(val(top100_out_block), 0)
and eq(val(top100_subs), 0)
) {uuid}
top_100(func: uid(top_100_sub_for_count_sorting)){
uuid
is_default_nickname
sub_for_count
}
}
Why I got this error:
{
"errors": [
{
"message": ": Arguments of different type can not be compared.",
"extensions": {
"code": "ErrorInvalidRequest"
}
}
],
"data": null
}
But if I comment 36 or 37 line Dgraph returns success result.
At the moment the solution for me is:
query qlink($uuid: string, $limit: int, $top_100_limit: int) {
var(func: eq(uuid, $uuid)) {
we_may_know1 as ~HAS_CONTACT
we_may_know2 as HAS_CONTACT
target_uuid as uuid
}
qlinks as var(func: uid(we_may_know1, we_may_know2)) {
links as count(HAS_CONTACT @filter(uid(we_may_know1, we_may_know2)))
subs as count(~SUBSCRIBED @filter(uid(target_uuid)))
in_block as count(BLACKLISTED @filter(uid(target_uuid)))
out_block as count(~BLACKLISTED @filter(uid(target_uuid)))
default_nickname as is_default_nickname
}
top100_filtered as var(func: type("Top_100")) {
top100_subs as count(~SUBSCRIBED @filter(uid(target_uuid)))
top100_in_block as count(BLACKLISTED @filter(uid(target_uuid)))
top100_out_block as count(~BLACKLISTED @filter(uid(target_uuid)))
}
sort_nickname_value as var(func: uid(qlinks), first: $limit, orderdesc: val(links)) @filter(
has(uuid)
and not uid(target_uuid)
and (NOT has(is_blocked) or eq(is_blocked, 0))
and (NOT has(is_shadow_banned) or eq(is_shadow_banned, 0))
and eq(val(in_block), 0)
and eq(val(out_block), 0)
and eq(val(subs), 0)
) {
uuid
}
main(func: uid(sort_nickname_value), orderasc: val(default_nickname)) {
uuid
is_default_nickname
}
top_100_sub_for_count_sorting as var(
func: uid(top100_filtered),
first:$top_100_limit
) @filter(
has(uuid)
and not uid(target_uuid)
and (NOT has(is_blocked) or eq(is_blocked, 0))
and (NOT has(is_shadow_banned) or eq(is_shadow_banned, 0))
and eq(val(top100_in_block), 0)
and eq(val(top100_out_block), 0)
and eq(val(top100_subs), 0)
) {uuid}
top_100(func: uid(top_100_sub_for_count_sorting), orderasc: is_default_nickname, orderdesc: sub_for_count){
uuid
is_default_nickname
sub_for_count
}
}
me schema {}:
{
"data": {
"schema": [
{
"predicate": "BLACKLISTED",
"type": "uid",
"reverse": true,
"list": true
},
{
"predicate": "HAS_CONTACT",
"type": "uid",
"reverse": true,
"list": true
},
{
"predicate": "SUBSCRIBED",
"type": "uid",
"reverse": true,
"list": true
},
{
"predicate": "blocked",
"type": "default"
},
{
"predicate": "created_at",
"type": "int"
},
{
"predicate": "device_id",
"type": "string"
},
{
"predicate": "dgraph.drop.op",
"type": "string"
},
{
"predicate": "dgraph.graphql.p_query",
"type": "string",
"index": true,
"tokenizer": [
"sha256"
]
},
{
"predicate": "dgraph.graphql.schema",
"type": "string"
},
{
"predicate": "dgraph.graphql.xid",
"type": "string",
"index": true,
"tokenizer": [
"exact"
],
"upsert": true
},
{
"predicate": "dgraph.type",
"type": "string",
"index": true,
"tokenizer": [
"exact"
],
"list": true
},
{
"predicate": "is_blocked",
"type": "bool"
},
{
"predicate": "is_default_nickname",
"type": "int"
},
{
"predicate": "is_shadow_banned",
"type": "bool"
},
{
"predicate": "phone",
"type": "string",
"index": true,
"tokenizer": [
"exact"
]
},
{
"predicate": "phone_book_order",
"type": "int"
},
{
"predicate": "predicate",
"type": "string"
},
{
"predicate": "schema",
"type": "uid",
"list": true
},
{
"predicate": "sub_for_count",
"type": "int",
"index": true,
"tokenizer": [
"int"
]
},
{
"predicate": "type",
"type": "string"
},
{
"predicate": "updated_at",
"type": "int"
},
{
"predicate": "uuid",
"type": "string",
"index": true,
"tokenizer": [
"exact"
]
}
],
"types": [
{
"fields": [],
"name": "Top100"
},
{
"fields": [
{
"name": "uuid"
},
{
"name": "updated_at"
},
{
"name": "is_blocked"
},
{
"name": "is_shadow_banned"
},
{
"name": "phone"
},
{
"name": "device_id"
}
],
"name": "User"
},
{
"fields": [
{
"name": "dgraph.graphql.schema"
},
{
"name": "dgraph.graphql.xid"
}
],
"name": "dgraph.graphql"
},
{
"fields": [
{
"name": "dgraph.graphql.p_query"
}
],
"name": "dgraph.graphql.persisted_query"
}
]
},
"extensions": {
"server_latency": {
"parsing_ns": 11526,
"processing_ns": 156705,
"assign_timestamp_ns": 1278691,
"total_ns": 1686551
},
"txn": {
"start_ts": 20906003
},
"metrics": {
"num_uids": {
"_total": 0
}
}
}
}
my Dgraph version is 23.1.0.