Skip to content

Mapping Decorators

Stores a field under another name. The field is containerSectionId in your code and in queries, and container_section_id in the graph, on save, load, query and index:

@GraphProperty('container_section_id') containerSectionId?: string;

Stores a value as a JSON string, for what an engine can’t store as a property: a map, a list of maps, or a list on an engine without list properties. Packed on write and unpacked on load:

@JsonPacked() tags?: string[];

Maps an open object to a set of flat, prefixed node properties. Unlike @JsonPacked, each entry is a real property: visible, filterable and indexable.

@NodeFragment({ labels: ['Proposition'] })
export class PropositionNode {
@NodeId() id: string;
text: string;
@PropertyBag() metadata: Record<string, any> = {}; // stored as metadata.<key>
}
await gom.loadAll(PropositionNode, (q) => ({ where: q.metadata.source.eq('wiki') }));

{ source: 'wiki', score: 3 } is stored as metadata.source and metadata.score. prefix decouples the stored namespace from the field’s name, and delimiter changes the separator. A value is a primitive or a list of them; a nested object is refused. Under NullPolicy.CLEAR a save removes the keys the map no longer has; IGNORE leaves them.

A flat bag, @PropertyBag({ flat: true }), has no prefix: each entry is stored under its own key, and the bag reads back every property that no declared field accounts for. A fragment may have one.

Maps a field to the node’s labels, beyond the fragment’s own. It is filled from the labels on load and written as labels on save, so MATCH (n:Admin) finds a node whose field holds Admin:

enum Role { Admin = 'Admin', Reviewer = 'Reviewer' }
@NodeFragment({ labels: ['Person'] })
export class PersonNode {
@NodeId() id: string;
@NodeLabels(Role) roles: Role[]; // a closed set: only these labels are the field's
}
@NodeFragment({ labels: ['Thing'] })
export class ThingNode {
@NodeId() id: string;
@NodeLabels() labels: string[]; // an open set: any label
}

Under IGNORE (the default) a save adds the field’s labels. Under CLEAR it also removes the field’s labels that the field no longer holds. A closed field’s labels are its members. An open field’s are those it wrote itself, which it records on the node under __drivine.labels.<field>. A label that isn’t the field’s, such as the fragment’s own, is never removed.

A field that is neither stored nor loaded.