::{
<new_property>: <schema_field>,
<computed_property>: <traversal_expression>
}
Property additions allow you to compute derived values and add metadata to your query results without modifying the underlying schema.
When using the SDKs or curling the endpoint, the query name must match what is defined in the queries.hx
file exactly.
Example 1: Adding computed properties with traversals
QUERY GetUserDetails () =>
users <- N<User>::RANGE(0, 5)
RETURN users::{
userID: ID,
followerCount: _::In<Follows>::COUNT
}
QUERY CreateUser (name: String, age: U8) =>
user <- AddN<User>({
name: name,
age: age
})
RETURN user
QUERY CreateFollow (follower_id: ID, following_id: ID) =>
follower <- N<User>(follower_id)
following <- N<User>(following_id)
AddE<Follows>::From(follower)::To(following)
RETURN "Success"
Here’s how to run the query using the SDKs or curl
from helix.client import Client
client = Client(local=True, port=6969)
users = [
{"name": "Alice", "age": 25},
{"name": "Bob", "age": 30},
{"name": "Charlie", "age": 28},
{"name": "Diana", "age": 22},
]
user_ids = []
for user in users:
result = client.query("CreateUser", user)
user_ids.append(result[0]["user"]["id"])
for i in range(1, len(user_ids)):
client.query("CreateFollow", {
"follower_id": user_ids[i],
"following_id": user_ids[0]
})
result = client.query("GetUserDetails", {})
print("User details with follower count:", result)