Objects and Paths

All queries on this page assume the following schema.

  1. module default {
  2. type Person {
  3. required property name -> str;
  4. }
  5. abstract type Content {
  6. required property title -> str {constraint exclusive};
  7. multi link actors -> Person {
  8. property character_name -> str;
  9. };
  10. }
  11. type Movie extending Content {
  12. property release_year -> int64;
  13. }
  14. type TVShow extending Content {
  15. property num_seasons -> int64;
  16. }
  17. }

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.actors.name; // Movie.actors.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).actors;
  4. // (Movie union TVShow).actors
  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["<director[is Movie]"]
  2. // Person.<director[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['<director'].is(e.Movie);
  2. // Person.<director[is Movie]