Copy
Ask AI
_::<traversal>::<operation>
When using the SDKs or curling the endpoint, the query name must match what is defined in the
queries.hx
file exactly.Example 1: Filter by relationship count
Copy
Ask AI
QUERY GetInfluentialUsers () =>
users <- N<User>::WHERE(_::In<Follows>::COUNT::GT(100))
RETURN users
QUERY CreateUser (name: String, age: U8, email: String) =>
user <- AddN<User>({
name: name,
age: age,
email: email
})
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"
Copy
Ask AI
from helix.client import Client
client = Client(local=True, port=6969)
users = [
{"name": "Alice", "age": 25, "email": "alice@example.com"},
{"name": "Bob", "age": 30, "email": "bob@example.com"},
{"name": "Charlie", "age": 28, "email": "charlie@example.com"},
]
user_ids = []
for user in users:
result = client.query("CreateUser", user)
user_ids.append(result[0]["user"]["id"])
for j in range(150):
fake_user = client.query("CreateUser", {
"name": f"Follower{j}",
"age": 20,
"email": f"follower{j}@example.com"
})
fake_id = fake_user[0]["user"]["id"]
client.query("CreateFollow", {"follower_id": fake_id, "following_id": user_ids[0]})
result = client.query("GetInfluentialUsers", {})
print(result)
Example 2: Property-based filtering with anonymous traversal
Copy
Ask AI
QUERY GetActiveUsersWithPosts () =>
users <- N<User>::WHERE(AND(_::{status}::EQ("active"), _::Out<HasPost>::COUNT::GT(0)))
RETURN users
QUERY CreateUser (name: String, age: U8, email: String, status: String) =>
user <- AddN<User>({
name: name,
age: age,
email: email,
status: status
})
RETURN user
QUERY CreatePost (user_id: ID, title: String, content: String) =>
user <- N<User>(user_id)
post <- AddN<Post>({
title: title,
content: content
})
AddE<HasPost>::From(user)::To(post)
RETURN post
Copy
Ask AI
from helix.client import Client
client = Client(local=True, port=6969)
users = [
{"name": "Alice", "age": 25, "email": "alice@example.com", "status": "active"},
{"name": "Bob", "age": 30, "email": "bob@example.com", "status": "active"},
{"name": "Charlie", "age": 28, "email": "charlie@example.com", "status": "inactive"},
{"name": "Diana", "age": 22, "email": "diana@example.com", "status": "active"},
]
user_ids = []
for user in users:
result = client.query("CreateUser", user)
user_ids.append(result[0]["user"]["id"])
client.query("CreatePost", {
"user_id": user_ids[0],
"title": "My First Post",
"content": "This is Alice's first post"
})
client.query("CreatePost", {
"user_id": user_ids[1],
"title": "Bob's Thoughts",
"content": "This is Bob's post"
})
result = client.query("GetActiveUsersWithPosts", {})
print(result)