自动生成
这是 GraphQL 库版本 7 的文档。对于长期支持 (LTS) 版本 5,请参考 GraphQL 库版本 5 LTS。 |
此页面描述了用于自动生成的指令
@id
此指令将字段标记为对象类型的标识符。这使得该字段能够自动生成 ID。
每个生成的 ID 格式是 randomUUID()
函数生成的 UUID。该字段不会出现在变更的输入类型中。
@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 @node {
createdAt: DateTime! @timestamp(operations: [CREATE])
updatedAt: DateTime! @timestamp(operations: [UPDATE])
}
以下两个等效的类型定义只有一个字段,用于存储最后一次 create
或 update
事件的时间戳
type User @node {
lastModified: DateTime! @timestamp
}
type User @node {
lastModified: DateTime! @timestamp(operations: [CREATE, UPDATE])
}