Skip to content

type_bridge.expressions.builtin

builtin

Built-in TypeQL function expressions.

TypeQL 3.8.0 introduced built-in functions that can be used in expressions: - iid($var) - Get the internal ID of a thing - label($var) - Get the type label of a thing - abs($num) - Absolute value - ceil($num) - Round up to nearest integer - floor($num) - Round down to nearest integer - round($num) - Round to nearest integer - len($list) - Length of a list - max($a, $b, ...) - Maximum value - min($a, $b, ...) - Minimum value

BuiltinFunctionExpr dataclass

BuiltinFunctionExpr(name, *args)

Bases: Expression

Expression for TypeQL built-in functions.

Built-in functions can be used in fetch clauses, let assignments, and other expression contexts.

Example

expr = BuiltinFunctionExpr("iid", "$e") expr.to_typeql("$e") 'iid($e)'

In a fetch clause:

fetch

Create a built-in function expression.

Parameters:

Name Type Description Default
name str

Function name (iid, label, abs, ceil, floor, round, len, max, min)

required
*args str

Variable names or literal values as arguments

()
Source code in type_bridge/expressions/builtin.py
def __init__(self, name: str, *args: str):
    """Create a built-in function expression.

    Args:
        name: Function name (iid, label, abs, ceil, floor, round, len, max, min)
        *args: Variable names or literal values as arguments
    """
    self.name = name
    self.args = args

to_ast

to_ast(var)

Built-in functions are values, not patterns.

Use to_value_ast() instead for AST representation.

Source code in type_bridge/expressions/builtin.py
def to_ast(self, var: str) -> list[Pattern]:
    """Built-in functions are values, not patterns.

    Use to_value_ast() instead for AST representation.
    """
    # Return empty list since built-in functions don't produce match patterns
    return []

to_typeql

to_typeql(var)

Generate TypeQL for this built-in function call.

Parameters:

Name Type Description Default
var str

Ignored (built-in functions use their own args)

required

Returns:

Type Description
str

TypeQL function call string (e.g., "iid($e)")

Source code in type_bridge/expressions/builtin.py
def to_typeql(self, var: str) -> str:
    """Generate TypeQL for this built-in function call.

    Args:
        var: Ignored (built-in functions use their own args)

    Returns:
        TypeQL function call string (e.g., "iid($e)")
    """
    args_str = ", ".join(self.args)
    return f"{self.name}({args_str})"

to_value_ast

to_value_ast(var=None)

Convert to AST FunctionCallValue.

Source code in type_bridge/expressions/builtin.py
def to_value_ast(self, var: str | None = None) -> Value:
    """Convert to AST FunctionCallValue."""
    from type_bridge.query.ast import FunctionCallValue

    return FunctionCallValue(function=self.name, args=list(self.args))

get_attribute_types

get_attribute_types()

Built-in functions don't reference attribute types.

Source code in type_bridge/expressions/builtin.py
def get_attribute_types(self) -> set[type[Attribute]]:
    """Built-in functions don't reference attribute types."""
    return set()

iid

iid(var)

Get the internal ID of a thing.

Parameters:

Name Type Description Default
var str

Variable name (e.g., "$e" or "e")

required

Returns:

Type Description
BuiltinFunctionExpr

Expression that generates "iid($var)"

Example

iid("$e").to_typeql("") 'iid($e)'

Use in fetch: fetch

Source code in type_bridge/expressions/builtin.py
def iid(var: str) -> BuiltinFunctionExpr:
    """Get the internal ID of a thing.

    Args:
        var: Variable name (e.g., "$e" or "e")

    Returns:
        Expression that generates "iid($var)"

    Example:
        >>> iid("$e").to_typeql("")
        'iid($e)'

        >>> # Use in fetch: fetch { "_iid": iid($e) }
    """
    if not var.startswith("$"):
        var = f"${var}"
    return BuiltinFunctionExpr("iid", var)

label

label(var)

Get the type label of a thing.

Parameters:

Name Type Description Default
var str

Variable name (e.g., "$e" or "e")

required

Returns:

Type Description
BuiltinFunctionExpr

Expression that generates "label($var)"

Example

label("$e").to_typeql("") 'label($e)'

Use in fetch: fetch

Source code in type_bridge/expressions/builtin.py
def label(var: str) -> BuiltinFunctionExpr:
    """Get the type label of a thing.

    Args:
        var: Variable name (e.g., "$e" or "e")

    Returns:
        Expression that generates "label($var)"

    Example:
        >>> label("$e").to_typeql("")
        'label($e)'

        >>> # Use in fetch: fetch { "_type": label($e) }
    """
    if not var.startswith("$"):
        var = f"${var}"
    return BuiltinFunctionExpr("label", var)

abs_

abs_(var)

Get the absolute value of a number.

Parameters:

Name Type Description Default
var str

Variable name or numeric expression

required

Returns:

Type Description
BuiltinFunctionExpr

Expression that generates "abs($var)"

Source code in type_bridge/expressions/builtin.py
def abs_(var: str) -> BuiltinFunctionExpr:
    """Get the absolute value of a number.

    Args:
        var: Variable name or numeric expression

    Returns:
        Expression that generates "abs($var)"
    """
    if not var.startswith("$"):
        var = f"${var}"
    return BuiltinFunctionExpr("abs", var)

ceil

ceil(var)

Round up to nearest integer.

Parameters:

Name Type Description Default
var str

Variable name or numeric expression

required

Returns:

Type Description
BuiltinFunctionExpr

Expression that generates "ceil($var)"

Source code in type_bridge/expressions/builtin.py
def ceil(var: str) -> BuiltinFunctionExpr:
    """Round up to nearest integer.

    Args:
        var: Variable name or numeric expression

    Returns:
        Expression that generates "ceil($var)"
    """
    if not var.startswith("$"):
        var = f"${var}"
    return BuiltinFunctionExpr("ceil", var)

floor

floor(var)

Round down to nearest integer.

Parameters:

Name Type Description Default
var str

Variable name or numeric expression

required

Returns:

Type Description
BuiltinFunctionExpr

Expression that generates "floor($var)"

Source code in type_bridge/expressions/builtin.py
def floor(var: str) -> BuiltinFunctionExpr:
    """Round down to nearest integer.

    Args:
        var: Variable name or numeric expression

    Returns:
        Expression that generates "floor($var)"
    """
    if not var.startswith("$"):
        var = f"${var}"
    return BuiltinFunctionExpr("floor", var)

round_

round_(var)

Round to nearest integer.

Parameters:

Name Type Description Default
var str

Variable name or numeric expression

required

Returns:

Type Description
BuiltinFunctionExpr

Expression that generates "round($var)"

Source code in type_bridge/expressions/builtin.py
def round_(var: str) -> BuiltinFunctionExpr:
    """Round to nearest integer.

    Args:
        var: Variable name or numeric expression

    Returns:
        Expression that generates "round($var)"
    """
    if not var.startswith("$"):
        var = f"${var}"
    return BuiltinFunctionExpr("round", var)

len_

len_(var)

Get length of a list.

Parameters:

Name Type Description Default
var str

Variable name of a list

required

Returns:

Type Description
BuiltinFunctionExpr

Expression that generates "len($var)"

Source code in type_bridge/expressions/builtin.py
def len_(var: str) -> BuiltinFunctionExpr:
    """Get length of a list.

    Args:
        var: Variable name of a list

    Returns:
        Expression that generates "len($var)"
    """
    if not var.startswith("$"):
        var = f"${var}"
    return BuiltinFunctionExpr("len", var)

max_

max_(*args)

Get maximum value.

Parameters:

Name Type Description Default
*args str

Variable names or values to compare

()

Returns:

Type Description
BuiltinFunctionExpr

Expression that generates "max($a, $b, ...)"

Source code in type_bridge/expressions/builtin.py
def max_(*args: str) -> BuiltinFunctionExpr:
    """Get maximum value.

    Args:
        *args: Variable names or values to compare

    Returns:
        Expression that generates "max($a, $b, ...)"
    """
    normalized = tuple(f"${a}" if not a.startswith("$") else a for a in args)
    return BuiltinFunctionExpr("max", *normalized)

min_

min_(*args)

Get minimum value.

Parameters:

Name Type Description Default
*args str

Variable names or values to compare

()

Returns:

Type Description
BuiltinFunctionExpr

Expression that generates "min($a, $b, ...)"

Source code in type_bridge/expressions/builtin.py
def min_(*args: str) -> BuiltinFunctionExpr:
    """Get minimum value.

    Args:
        *args: Variable names or values to compare

    Returns:
        Expression that generates "min($a, $b, ...)"
    """
    normalized = tuple(f"${a}" if not a.startswith("$") else a for a in args)
    return BuiltinFunctionExpr("min", *normalized)