Links​

This section describes the SDL declarations pertaining to links.

Examples​

Declare an abstract link “friends_base” with a helpful title:

  1. abstract link friends_base {
  2. # declare a specific title for the link
  3. annotation title := 'Close contacts';
  4. }

Declare a concrete link “friends” within a “User” type:

  1. type User {
  2. required property name -> str;
  3. property address -> str;
  4. # define a concrete link "friends"
  5. multi link friends extending friends_base-> User;
  6. index on (__subject__.name);
  7. }

Overloading​

Any time that the SDL declaration refers to an inherited link that is being overloaded (by adding more constraints or changing the target type, for example), the overloaded keyword must be used. This is to prevent unintentional overloading due to name clashes:

  1. abstract type Friendly {
  2. # this type can have "friends"
  3. link friends -> Friendly;
  4. }
  5. type User extending Friendly {
  6. # overload the link target to be User, specifically
  7. overloaded multi link friends -> User;
  8. # ... other links and properties
  9. }

Syntax​

Define a new link corresponding to the more explicit DDL commands.

  1. Concrete link form used inside type declaration:
  2. [ overloaded ] [{required | optional}] [{single | multi}]
  3. link name
  4. [ extending base [, ...] ] -> type
  5. [ "{"
  6. [ default := expression ; ]
  7. [ readonly := {true | false} ; ]
  8. [ on target delete action ; ]
  9. [ annotation-declarations ]
  10. [ property-declarations ]
  11. [ constraint-declarations ]
  12. ...
  13. "}" ]
  14. Computed link form used inside type declaration:
  15. [{required | optional}] [{single | multi}]
  16. link name := expression;
  17. Computed link form used inside type declaration (extended):
  18. [ overloaded ] [{required | optional}] [{single | multi}]
  19. link name
  20. [ extending base [, ...] ] [-> type]
  21. [ "{"
  22. using (expression) ;
  23. [ annotation-declarations ]
  24. [ constraint-declarations ]
  25. ...
  26. "}" ]
  27. Abstract link form:
  28. abstract link name [extending base [, ...]]
  29. [ "{"
  30. [ readonly := {true | false} ; ]
  31. [ annotation-declarations ]
  32. [ property-declarations ]
  33. [ constraint-declarations ]
  34. [ index-declarations ]
  35. ...
  36. "}" ]

Description​

There are several forms of link declaration, as shown in the syntax synopsis above. The first form is the canonical definition form, the second and third forms are used for defining a computed link, and the last one is a form to define an abstract link. The abstract form allows declaring the link directly inside a module. Concrete link forms are always used as sub-declarations for an object type.

The following options are available:

overloaded

If specified, indicates that the link is inherited and that some feature of it may be altered in the current object type. It is an error to declare a link as overloaded if it is not inherited.

required

If specified, the link is considered required for the parent object type. It is an error for an object to have a required link resolve to an empty value. Child links always inherit the required attribute, i.e it is not possible to make a required link non-required by extending it.

optional

This is the default qualifier assumed when no qualifier is specified, but it can also be specified explicitly. The link is considered optional for the parent object type, i.e. it is possible for the link to resolve to an empty value.

multi

Specifies that there may be more than one instance of this link in an object, in other words, Object.link may resolve to a set of a size greater than one.

single

Specifies that there may be at most one instance of this link in an object, in other words, Object.link may resolve to a set of a size not greater than one. single is assumed if nether multi nor single qualifier is specified.

extending base [, …]

Optional clause specifying the parents of the new link item.

Use of extending creates a persistent schema relationship between the new link and its parents. Schema modifications to the parent(s) propagate to the child.

If the same property name exists in more than one parent, or is explicitly defined in the new link and at least one parent, then the data types of the property targets must be compatible. If there is no conflict, the link properties are merged to form a single property in the new link item.

type

The type must be a valid type expression denoting an object type.

The valid SDL sub-declarations are listed below:

default := expression

Specifies the default value for the link as an EdgeQL expression. The default value is used in an insert statement if an explicit value for this link is not specified.

readonly := {true | false}

If true, the link is considered read-only. Modifications of this link are prohibited once an object is created. All of the derived links must preserve the original read-only value.

annotation-declarations

Set link annotation to a given value.

property-declarations

Define a concrete property on the link.

constraint-declarations

Define a concrete constraint on the link.

index-declarations

Define an index for this abstract link. Note that this index can only refer to link properties.

See also

Schema > Links

DDL > Links

Introspection > Object types