This section assumes a basic understanding of EdgeQL. If you aren’t familiar with it, feel free to skip this page for now.

Object types can contain computed links and properties. Computed properties and links are not persisted in the database. Instead, they are evaluated on the fly whenever that field is queried.

Copy
type Person {
  property name -> str;
  property all_caps_name := str_upper(__subject__.name);
}

Computed fields are associated with an EdgeQL expression. This expression can be an arbitrary EdgeQL query. This expression is evaluated whenever the field is referenced in a query.

Computed fields don’t need to be pre-defined in your schema; you can drop them into individual queries as well. They behave in exactly the same way. For more information, see the EdgeQL > Select > Computeds.

The example above used the special keyword __subject__ to refer to the current object; it’s analogous to this in many object-oriented languages.

However, explicitly using __subject__ is optional here; inside the scope of an object type declaration, you can omit it entirely and use the .<name> shorthand.

Copy
type Person {
  property first_name -> str;
  property last_name -> str;
  property full_name := .first_name ++ ' ' ++ .last_name;
}

The type and cardinality of a computed field is inferred from the expression. There’s no need for the modifier keywords you use for non-computed fields (like multi and required). However, it’s common to specify them anyway; it makes the schema more readable and acts as a sanity check: if the provided EdgeQL expression disagrees with the modifiers, an error will be thrown the next time you try to create a migration.

Copy
type Person {
  property first_name -> str;
  required property name_upper := str_upper(.name); # invalid
}

If you find yourself writing the same filter expression repeatedly in queries, consider defining a computed field that encapsulates the filter.

Copy
type Club {
  multi link members -> Person;
  link active_members := (
    select .members filter .is_active = true
  )
}

type Person {
  property name -> str;
  property is_active -> bool;
}
Light
Dark
System