Autogeneration

This is the documentation of the GraphQL Library version 6. For the long-term support (LTS) version 5, refer to GraphQL Library version 5 LTS.

This page describes directives used for autogeneration:

@id

This directive marks a field as an identifier for an object type. This enables autogeneration of IDs for the field.

The format of each generated ID is a UUID generated by the randomUUID() function. The field will not be present in input types for mutations.

It is recommended to use @unique in conjunction with this to add a unique node property constraint.

Definition

"""Indicates that the field is an identifier for the object type."""
directive @id on FIELD_DEFINITION

Usage

The following type definition specifies the id field as an autogenerated value:

type User @node {
    id: ID! @id
    username: String!
}

@timestamp

This directive marks a field as a timestamp field, which can 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 do not trigger updates of these timestamps.

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

Usage

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

type User @node {
    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 @node {
    lastModified: DateTime! @timestamp
}
type User @node {
    lastModified: DateTime! @timestamp(operations: [CREATE, UPDATE])
}