Skip to main content

Negate a condition with NOT (!)  

Negate a condition to match the opposite.
::WHERE(!<condition>)

Example: ! can be used infront of any condition that returns a boolean.

QUERY GetActiveUsersWithFollowers () =>
    followers <- N<User>::WHERE(
        !AND( // Negate the AND condition
            !_::{is_active}::EQ(true), // Negate the EQ condition
            _::Out<Follows>::COUNT::LT(10)
        )
    )
    RETURN followers
The ! operator can also be combined with EXISTS to find elements without certain relationships:
QUERY GetUsersWithoutFollowers () =>
    users <- N<User>::WHERE(!EXISTS(_::In<Follows>))
    RETURN users

Enforce all conditions with AND  

Takes a list of conditions and returns true only if all conditions are true.
::WHERE(AND(<condition1>, <condition2>, ...))

Enforce any condition with OR  

Takes a list of conditions and returns true if at least one condition is true.
::WHERE(OR(<condition1>, <condition2>, ...))
When using the SDKs or curling the endpoint, the query name must match what is defined in the queries.hx file exactly.

Example 1: Using AND for range filtering

QUERY GetYoungAdults () =>
    users <- N<User>::WHERE(AND(_::{age}::GT(18), _::{age}::LT(30)))
    RETURN users

QUERY CreateUser (name: String, age: U8, email: String) =>
    user <- AddN<User>({
        name: name,
        age: age,
        email: email
    })
    RETURN user
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, "email": "alice@example.com"},
    {"name": "Bob", "age": 16, "email": "bob@example.com"},
    {"name": "Charlie", "age": 35, "email": "charlie@example.com"},
    {"name": "Diana", "age": 22, "email": "diana@example.com"},
    {"name": "Eve", "age": 17, "email": "eve@example.com"},
]

for user in users:
    client.query("CreateUser", user)

result = client.query("GetYoungAdults", {})
print(result)

Example 2: Using OR for multiple valid options

QUERY GetSpecificUsers () =>
    users <- N<User>::WHERE(OR(_::{name}::EQ("Alice"), _::{name}::EQ("Bob")))
    RETURN users

QUERY CreateUser (name: String, age: U8, email: String) =>
    user <- AddN<User>({
        name: name,
        age: age,
        email: email
    })
    RETURN user
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, "email": "alice@example.com"},
    {"name": "Bob", "age": 30, "email": "bob@example.com"},
    {"name": "Charlie", "age": 28, "email": "charlie@example.com"},
    {"name": "Diana", "age": 22, "email": "diana@example.com"},
]

for user in users:
    client.query("CreateUser", user)

result = client.query("GetSpecificUsers", {})
print(result)

Example 3: Complex nested AND and OR conditions

QUERY GetFilteredUsers () =>
    users <- N<User>::WHERE(
        AND(
            _::{age}::GT(18),
            OR(_::{name}::EQ("Alice"), _::{name}::EQ("Bob"))
        )
    )
    RETURN users

QUERY CreateUser (name: String, age: U8, email: String) =>
    user <- AddN<User>({
        name: name,
        age: age,
        email: email
    })
    RETURN user
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, "email": "alice@example.com"},
    {"name": "Bob", "age": 16, "email": "bob@example.com"},
    {"name": "Alice", "age": 17, "email": "alice2@example.com"},
    {"name": "Charlie", "age": 30, "email": "charlie@example.com"},
    {"name": "Bob", "age": 22, "email": "bob2@example.com"},
]

for user in users:
    client.query("CreateUser", user)

result = client.query("GetFilteredUsers", {})
print(result)