MCPcopy Create free account
hub / github.com/codemix/graph / addVertex

Method addVertex

packages/graph/src/Graph.ts:513–550  ·  view source on GitHub ↗
(...args: any[])

Source from the content-addressed store, hash-verified

511 properties: VertexProperties<TSchema, TVertexLabel>,
512 ): Vertex<TSchema, TVertexLabel>;
513 public addVertex(...args: any[]) {
514 let label: string;
515 let properties: Record<string, unknown>;
516 if (args.length === 1 && typeof args[0] === "object" && args[0] !== null) {
517 label = args[0].label;
518 properties = args[0].properties;
519 } else {
520 label = args[0];
521 properties = args[1];
522 }
523
524 // Validate and transform properties when validation is enabled
525 const validateProperties = this.#config.validateProperties ?? true;
526 if (validateProperties) {
527 const schemaProperties = this.#config.schema.vertices[label]?.properties;
528 properties = parseProperties(label, properties, schemaProperties);
529 }
530
531 const data: StoredVertex = {
532 "@type": "Vertex",
533 id: this.generateElementId(label),
534 properties,
535 };
536
537 // Ensure unique indexes are built before checking constraints
538 this.#indexManager.ensureUniqueIndexesBuilt(label, this.#config.storage.getVertices([label]));
539
540 // Check unique constraints before adding (throws if violated)
541 this.#indexManager.checkAllUniqueConstraints(label, data.properties as Record<string, unknown>);
542
543 // Add to storage
544 this.#config.storage.addVertex(data);
545
546 // Add to indexes
547 this.#indexManager.onElementAdd(data);
548
549 return this.instantiateVertex(data);
550 }
551
552 /**
553 * Delete a vertex from the graph.

Callers 10

createGraphFunction · 0.95
createGraphFunction · 0.95
createTestGraphFunction · 0.95
setupQueryExecutionGraphFunction · 0.95
setupMultiLabelGraphFunction · 0.95
createWeightedEdgeGraphFunction · 0.95
createTestGraphFunction · 0.95
createGraphFunction · 0.95
setupOrderByGraphFunction · 0.95
setupSetClauseGraphFunction · 0.95

Calls 8

generateElementIdMethod · 0.95
instantiateVertexMethod · 0.95
parsePropertiesFunction · 0.85
onElementAddMethod · 0.80
getVerticesMethod · 0.65
addVertexMethod · 0.65

Tested by 10

createGraphFunction · 0.76
createGraphFunction · 0.76
createTestGraphFunction · 0.76
setupQueryExecutionGraphFunction · 0.76
setupMultiLabelGraphFunction · 0.76
createWeightedEdgeGraphFunction · 0.76
createTestGraphFunction · 0.76
createGraphFunction · 0.76
setupOrderByGraphFunction · 0.76
setupSetClauseGraphFunction · 0.76