Paths​

A path expression (or simply a path) represents a set of values that are reachable by traversing a given sequence of links or properties from some source set of objects.

Consider the following schema:

  1. type User {
  2. required property email -> str;
  3. multi link friends -> User;
  4. }
  5. type BlogPost {
  6. required property title -> str;
  7. required link author -> User;
  8. }

The simplest path is simply User. This is a set reference that refers to all User objects in the database.

  1. select User;

Paths can traverse links. The path below refers to all Users who are the friend of another User.

  1. select User.friends;

Paths can traverse arbitrarily many links.

  1. select BlogPost.author.friends.friends;

Paths can terminate with a property reference.

  1. select BlogPost.title; # all blog post titles
  2. select BlogPost.author.email; # all author emails
  3. select User.friends.email; # all friends' emails

All examples thus far have traversed links in the forward direction, however it’s also possible to traverse links backwards with .< notation. These are called backlinks.

Starting from each user, the path below traverses all incoming links labeled author and returns the union of their sources.

  1. select User.<author;

As written, EdgeDB infers the type of this expression to be BaseObject, not BlogPost. Why? Because in theory, there may be several links named author that point to User.

BaseObject is the root ancestor of all object types and it only contains a single property, id.

Consider the following addition to the schema:

  1. type User {
  2. # as before
  3. }
  4. type BlogPost {
  5. required link author -> User;
  6. }
  7. type Comment {
  8. required link author -> User;
  9. }

With the above schema, the path User.<author would return a mixed set of BlogPost and Comment objects. This may be desirable in some cases, but commonly you’ll want to narrow the results to a particular type. To do so, use the type intersection operator: [is Foo]:

  1. select User.<author[is BlogPost]; # returns all blog posts
  2. select User.<author[is Comment]; # returns all comments

Paths can also reference link properties with @ notation. To demonstrate this, let’s add a property to the User. friends link:

  1. type User {
  2. required property email -> str;
  3. multi link friends -> User;
  4. multi link friends -> User {
  5. property since -> cal::local_date;
  6. }
  7. }

The following represents a set of all dates on which friendships were formed.

  1. select User.friends@since;

Path roots​

For simplicity, all examples above use set references like User as the root of the path; however, the root can be any expression returning object types. Below, the root of the path is a subquery.

  1. with edgedb_lovers := (
  2. select BlogPost filter .title ilike "EdgeDB is awesome"
  3. )
  4. select edgedb_lovers.author;

This expression returns a set of all Users who have written a blog post titled “EdgeDB is awesome”.

For a full syntax definition, see the Reference > Paths.