Search
ctrl/
Ask AI
Light
Dark
System

Mutation Rewrites

This section describes the DDL commands pertaining to mutation rewrites.

Define a new mutation rewrite.

When creating a new property or link:

{create | alter} type type-name "{"
  create { property | link } prop-or-link-name -> type "{"
    create rewrite {insert | update} [, ...]
      using expr
  "}" ;
"}" ;

When altering an existing property or link:

{create | alter} type type-name "{"
  alter { property | link } prop-or-link-name "{"
    create rewrite {insert | update} [, ...]
      using expr
  "}" ;
"}" ;

The command create rewrite nested under create type or alter type and then under create property/link or alter property/link defines a new mutation rewrite for the given property or link on the given object.

type-name

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

prop-or-link-name

The name (optionally module-qualified) of the property or link being rewritten.

insert | update [, ...]

The query type (or types) that are rewritten. Separate multiple values with commas to invoke the same rewrite for multiple types of queries.

Declare two mutation rewrites on new properties: one that sets a created property when a new object is inserted and one that sets a modified property on each update:

Copy
alter type User {
  create property created -> datetime {
    create rewrite insert using (datetime_of_statement());
  };
  create property modified -> datetime {
    create rewrite update using (datetime_of_statement());
  };
};

Remove a mutation rewrite.

alter type type-name "{"
  alter property prop-or-link-name "{"
    drop rewrite {insert | update} ;
  "}" ;
"}" ;

The command drop rewrite inside an alter type block and further inside an alter property block removes the definition of an existing mutation rewrite on the specified property or link of the specified type.

type-name

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

prop-or-link-name

The name (optionally module-qualified) of the property or link being rewritten.

insert | update [, ...]

The query type (or types) that are rewritten. Separate multiple values with commas to invoke the same rewrite for multiple types of queries.

Remove the insert rewrite of the created property on the User type:

Copy
alter type User {
  alter property created {
    drop rewrite insert;
  };
};