I’m having trouble writing a query. could you help me figure out what the problem is and how to write a query better.
I created the following schema (why this is done is an interesting question, but so far I have indicated only the necessary fields):
client_id: string @index(exact, fulltext, trigram) @upsert .
client_secret: password .
has_keys: [uid] @count @reverse .
has_access: uid @reverse .
type: uid @reverse .
cabinet_name: string @index(exact, fulltext, trigram) @lang @upsert .
has_cabinets: [uid] @count @reverse .
belongs_to: uid @reverse .
inventary_number: int @index(int) @upsert .
type user {
client_id: string
client_secret: password
has_keys: [cabinet_key]
}
type cabinet_key {
has_access: cabinet
}
type cabinet {
type: cabinet_type
}
type cabinet_type {
cabinet_name: string
}
type organization {
has_cabinets: [cabinet]
}
type office {
has_cabinets: [cabinet]
belongs_to: organization
}
type device{
has_cabinets: [cabinet]
belongs_to: office
inventary_number: int
}
The most difficult part of the question for me. Let’s say we have a set of entities and I know the values of the client_id (user), uid (user), cabinet_name (cabinet_type) and inventary_number (device) fields. Having 4 of these fields, I need to find out the corresponding uid (cabinet_key).
I have already tried to write a query like this:
{
dev as var(func: type(device)) @filter(eq(inventary_number, "13265165818136521"))
cabinetsDevInv as var(func: type(cabinet)) @filter(eq(~has_cabinets, dev))
cabinetTypeDev as var(func: type(cabinet_type)) @filter(eq(cabinet_name, "dev"))
cabinetsDev as var(func: type(cabinet)) @filter(eq(type, cabinetTypeDev))
cabinets as var(func: type(cabinet)) @filter(eq(cabinetsDevInv, cabinetsDev))
cabinetsKeys as var(func: type(cabinet_key)) @filter(eq(has_access, cabinets))
getPrachkomatKey(func: uid(0x759d)) {
has_keys @filter(uid(cabinetsKeys)) {
uid
}
}
}
But I’m having trouble understanding the syntax. Can you help me figure out what I should pay attention to and what I’m doing wrong?
In response I get the following:
Error Name: t
Message: Some variables are defined but not used Defined:[cabinetTypeDev cabinets cabinetsKeys cabinetsDev cabinetsDevInv dev] Used:[cabinetsKeys]
Raw Error:
{
"name": "t",
"url": "http://localhost:8080/query?timeout=20s&debug=true",
"errors": [
{
"message": "Some variables are defined but not used\nDefined:[cabinetTypeDev cabinets cabinetsKeys cabinetsDev cabinetsDevInv dev]\nUsed:[cabinetsKeys]\n",
"extensions": {
"code": "ErrorInvalidRequest"
}
}
]
}