Supported directives
Directives provide extra metadata when declaring scalars, lists and shapes.
Model identification
@createModel
The @createModel directive applies to shapes and interfaces, indicating they
need to be created as a Model. A Composite must contain at least one Model to
be valid, otherwise there would be nothing to interact with.
When using the @createModel directive, two parameters must be provided:
accountRelation: the type of relation between documents created using the Model and the account controlling the document, which can beSINGLEfor a single document of the given Model (for example profile information), orLIST(default) for a potentially infinite list of documents. When creating interfaces, theaccountRelationis ignored if provided.description: a string describing the Model, to help with discovery.
Example:
type Post @createModel(accountRelation: LIST, description: "A simple text post") {
author: DID! @documentAccount
title: String! @string(minLength: 10, maxLength: 100)
text: String! @string(maxLength: 500)
}
@loadModel
The @loadModel directive can be used to identify pre-existing models and use
them in a schema, by providing the model stream ID with the id argument of the
directive.
When loading models, it is not possible to add extra content fields, but it is possible to add extra views.
The GraphQL parser used by schemas does not allow empty types to be created. If
needed, an id: ID field can be added, as shown in the examples below.
# ❌ the following declaration will NOT work:
type MyModel @loadModel(id: "<existing model stream ID>") {}
# ✅ the following declaration will work:
type MyModel @loadModel(id: "<existing model stream ID>") {
id: ID
}
# ✅ the following declaration will also work:
type MyModel @loadModel(id: "<existing model stream ID>") {
owner: DID! @documentAccount
}
Indexing
The indexing directive can only be set on types defined as model,
identified using the @createModel or
@loadModel directive.
The indexing directive cannot be used when defining interfaces, as interfaces
themselves are not indexed, only the models implementing them.
@createIndex
The @createIndex directive ensures content fields in a model are indexed in the underlying database and can be used for filtering and ordering.
Example:
type Post
@createModel(accountRelation: LIST, description: "A simple text post")
@createIndex(fields: [{ path: ["title"] }]) {
author: DID! @documentAccount
title: String! @string(minLength: 10, maxLength: 100)
publishedAt: DateTime
text: String! @string(maxLength: 500)
}
The @createIndex directive can be used multiple times:
type Post
@createModel(accountRelation: LIST, description: "A simple text post")
@createIndex(fields: [{ path: ["title"] }])
@createIndex(fields: [{ path: ["publishedAt"] }]) {
author: DID! @documentAccount
title: String! @string(minLength: 10, maxLength: 100)
publishedAt: DateTime
text: String! @string(maxLength: 500)
}
Type validation
The following directives provide validation information on primitive scalars and lists:
@int
Defines the optional max: Int and min: Int value for
Int scalars.