Autogeneration

1. @id

This directive marks a field as the unique identifier for an object type, and by default enables autogenerated of IDs for the field.

The format of each generated ID is a UUID generated by randomUUID() function.

If autogeneration for an ID field is enabled, the field will not be present in input types for Mutations.

1.1. Definition

"""Indicates that the field is the unique identifier for the object type, and additionally enables the autogeneration of IDs."""
directive @id(autogenerate: Boolean! = true) on FIELD_DEFINITION

1.2. Usage

The following two type definitions are equivalent in that they both specify an ID which will benefit from autogeneration:

type User {
    id: ID! @id
    username: String!
}
type User {
    id: ID! @id(autogenerate: true)
    username: String!
}

The following type definition is currently a no-op, as the @id directive only provides autogeneration as it stands:

type User {
    id: ID! @id(autogenerate: false)
    username: String!
}

2. @timestamp

2.1. Timestamps

This directive marks a field as a timestamp field, which will be used to store timestamps of when particular events happen through the GraphQL API.

These events are triggered and stored at the GraphQL API layer. Events happening in your database through other routes will not trigger updates of these timestamps.

2.2. Definition

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

2.3. Usage

The following type definition has two individual fields to store the timestamps of create and update events.

type User {
    createdAt: DateTime! @timestamp(operations: [CREATE])
    updatedAt: DateTime! @timestamp(operations: [UPDATE])
}

The following two equivalent type definitions have a single field storing the event timestamp of the last create or update:

type User {
    lastModified: DateTime! @timestamp
}
type User {
    lastModified: DateTime! @timestamp(operations: [CREATE, UPDATE])
}