Objects and paths​

All queries on this page assume the following schema.

  1. module default {
  2. type Account {
  3. required property username -> str {
  4. constraint exclusive;
  5. };
  6. multi link watchlist -> Media;
  7. }
  8. type Person {
  9. required property name -> str;
  10. }
  11. abstract type Media {
  12. required property title -> str;
  13. multi link cast -> Person {
  14. property character_name -> str;
  15. };
  16. }
  17. type Movie extending Media {
  18. property runtime -> duration;
  19. }
  20. type TVShow extending Media {
  21. property number_of_seasons -> int64;
  22. }
  23. }

Object types​

All object types in your schema are reflected into the query builder, properly namespaced by module.

  1. e.default.Person;
  2. e.default.Movie;
  3. e.default.TVShow;
  4. e.my_module.SomeType;

For convenience, the contents of the default module are also available at the top-level of e.

  1. e.Person;
  2. e.Movie;
  3. e.TVShow;

Paths​

EdgeQL-style paths are supported on object type references.

  1. e.Person.name; // Person.name
  2. e.Movie.title; // Movie.title
  3. e.TVShow.cast.name; // Movie.cast.name

Paths can be constructed from any object expression, not just the root types.

  1. e.select(e.Person).name;
  2. // (select Person).name
  3. e.op(e.Movie, 'union', e.TVShow).cast;
  4. // (Movie union TVShow).cast
  5. const ironMan = e.insert(e.Movie, {
  6. title: "Iron Man"
  7. });
  8. ironMan.title;
  9. // (insert Movie { title := "Iron Man" }).title

Type intersections​

Use the type intersection operator to narrow the type of a set of objects. For instance, to represent the elements of an Account’s watchlist that are of type TVShow:

  1. e.Person.acted_in.is(e.TVShow);
  2. // Person.acted_in[is TVShow]

All possible backlinks are auto-generated and can be auto-completed by TypeScript. They behave just like forward links. However, because they contain special characters, you must use bracket syntax instead of simple dot notation.

  1. e.Person["<directed[is Movie]"]
  2. // Person.<directed[is Movie]

For convenience, these backlinks automatically combine the backlink operator and type intersection into a single key. However, the query builder also provides “naked” backlinks; these can be refined with the .is type intersection method.

  1. e.Person['<directed'].is(e.Movie);
  2. // Person.<directed[is Movie]