Object Types

This section describes the SDL declarations pertaining to object types.

Example

Consider a User type with a few properties:

  1. type User {
  2. # define some properties and a link
  3. required property name -> str;
  4. property address -> str;
  5. multi link friends -> User;
  6. # define an index for User based on name
  7. index on (__subject__.name);
  8. }

An alternative way to define the same User type could be by using abstract types. These abstract types can then be re-used in other type definitions as well:

  1. abstract type Named {
  2. required property name -> str;
  3. }
  4. abstract type HasAddress {
  5. property address -> str;
  6. }
  7. type User extending Named, HasAddress {
  8. # define some user-specific properties and a link
  9. multi link friends -> User;
  10. # define an index for User based on name
  11. index on (__subject__.name);
  12. }

Introducing abstract types opens up the possibility of polymorphic queries.

Syntax

Define a new object type corresponding to the more explicit DDL commands.

  1. [abstract] type TypeName [extending supertype [, ...] ]
  2. [ "{"
  3. [ annotation-declarations ]
  4. [ property-declarations ]
  5. [ link-declarations ]
  6. [ constraint-declarations ]
  7. [ index-declarations ]
  8. ...
  9. "}" ]

Description

This declaration defines a new object type with the following options:

abstract

If specified, the created type will be abstract.

TypeName

The name (optionally module-qualified) of the new type.

extending supertype [, …]

Optional clause specifying the supertypes of the new type.

Use of extending creates a persistent type relationship between the new subtype and its supertype(s). Schema modifications to the supertype(s) propagate to the subtype.

References to supertypes in queries will also include objects of the subtype.

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

These sub-declarations are allowed in the Type block:

annotation-declarations

Set object type annotation to a given value.

property-declarations

Define a concrete property for this object type.

link-declarations

Define a concrete link for this object type.

constraint-declarations

Define a concrete constraint for this object type.

index-declarations

Define an index for this object type.

See also

Schema > Object types

DDL > Object types

Introspection > Object types

Cheatsheets > Object types