Objects and Paths
All queries on this page assume the following schema.
module default {
type Person {
required name: str;
}
abstract type Content {
required title: str {
constraint exclusive
};
multi actors: Person {
character_name: str;
};
}
type Movie extending Content {
release_year: int64;
}
type TVShow extending Content {
num_seasons: int64;
}
}
Object types
All object types in your schema are reflected into the query builder, properly namespaced by module.
e.default.Person;
e.default.Movie;
e.default.TVShow;
e.my_module.SomeType;
For convenience, the contents of the default
module are also available at
the top-level of e
.
e.Person;
e.Movie;
e.TVShow;
Paths
EdgeQL-style paths are supported on object type references.
e.Person.name; // Person.name
e.Movie.title; // Movie.title
e.TVShow.actors.name; // Movie.actors.name
Paths can be constructed from any object expression, not just the root types.
e.select(e.Person).name;
// (select Person).name
e.op(e.Movie, 'union', e.TVShow).actors;
// (Movie union TVShow).actors
const ironMan = e.insert(e.Movie, {
title: "Iron Man"
});
ironMan.title;
// (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
:
e.Person.acted_in.is(e.TVShow);
// Person.acted_in[is TVShow]
Backlinks
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.
e.Person["<director[is Movie]"]
// 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.
e.Person['<director'].is(e.Movie);
// Person.<director[is Movie]