自动生成
此页面描述了用于自动生成的指令
@id
此指令将字段标记为对象类型的标识符。这使得能够为字段自动生成 ID。
每个生成的 ID 的格式是由 randomUUID()
函数 生成的 UUID。该字段将不会出现在变异的输入类型中。
建议结合使用 @unique
以添加唯一的节点属性约束。
@timestamp
此指令将字段标记为时间戳字段,可用于通过 GraphQL API 存储特定事件发生的时间戳。
这些事件在 GraphQL API 层触发并存储。通过其他路由在数据库中发生的事件不会触发这些时间戳的更新。 |
定义
enum TimestampOperation {
CREATE
UPDATE
}
"""Instructs @neo4j/graphql to generate timestamps on particular events, which will be available as the value of the specified field."""
directive @timestamp(
"""Which events to generate timestamps on. Defaults to both create and update."""
operations: [TimestampOperation!]! = [CREATE, UPDATE]
) on FIELD_DEFINITION
用法
以下类型定义有两个单独的字段来存储创建和更新事件的时间戳
type User {
createdAt: DateTime! @timestamp(operations: [CREATE])
updatedAt: DateTime! @timestamp(operations: [UPDATE])
}
以下两个等效的类型定义具有一个字段,存储最后一次 create
或 update
的事件时间戳
type User {
lastModified: DateTime! @timestamp
}
type User {
lastModified: DateTime! @timestamp(operations: [CREATE, UPDATE])
}