reym
CRUD/Schema

Introduction

Documentation of the CRUD service schema definition.

A CRUD Type can be defined by a GraphQL schema:

user.graphql
type User @crudType {
    name: String!
}

This CRUD type will create several projections in the database, accessible via the GraphQL API: The name of the projection equals the name of the type in the schema. The name will be part of the corresponding queries and subscriptions in the GraphQL API, too.

Object Directives

The following directives can be applied to the whole CRUD type:

DirectiveDescription
@crudTypeAn object type on which data can be created, read, updated, deleted
@expiresAutomatically remove data after expiration
@filterByJwtDataFilter data based on a field in the JWT
@globalCrud types over all tenants
@permissionRestrict access permissions on the crud type
@renamedRename a crud type
@uniqueUnique constraints on multiple fields

Fields

Supported field types:

  • String
  • ID
  • Boolean
  • Int
  • Float
  • DateTime (unix timestamp, milliseconds)
  • Enums
  • Objects / references to other crud or CRUD types
  • Arrays of all types listed above
  • All types listed above in their required form
  • [EventEnvelope!]!

Event Envelope

The field type [EventEnvelope!]! is a special field type that can only be used in this form at the root level of a projection (not in a nested object). It will automatically aggregate all events that are applied on the projection entry into an array. Use the type in conjunction with the @aggregateEvents directive. This is very useful for debugging.

Every projection will automatically get three fields:

FieldTypeDescription
idID!The identifier of the projection
createdAtDateTime!The creation time of the entry
changedAtDateTime!The time of the last change of the entry

By default the value of a field equals the value of the event payload field that has the exact same name. Required fields are marked by an !, e.g. String!. Fields with the ! flag will default to their zero value ("" for strings, 0 for numbers, false for booleans, [] for arrays).

Field Directives

By default the value of a field equals the value of the event payload field that has the exact same name. This behavior can be changed by using directives on a field level:

DirectiveDescription
@changedByReflects the user that has last changed the entry
@cloneFieldClone a field to another field
@createdByReflects the user that has created the entry
@defaultSet a default value
@gdprApply GDPR logic on a field
@indexMake a field filterable ans sortable
@immutableMark a field as immutable
@permissionRestrict access permissions on the field
@readonlyMake a field read-only
@renamedRename a crud type field
@safeHtmlSanitize html strings
@sequenceAutomated sequence generator
@uniqueMake a field unique
@validateValidate field data