refactor

package
v1.2.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jul 27, 2026 License: MIT Imports: 1 Imported by: 0

Documentation

Overview

Package refactor provides APOC graph refactoring functions.

This package implements all apoc.refactor.* functions for restructuring and transforming graph data.

Index

Constants

This section is empty.

Variables

Storage is the interface for database operations.

Functions

func CloneSubgraph

func CloneSubgraph(nodes []*Node, rels []*Relationship) map[string]interface{}

CloneSubgraph clones a subgraph.

Example:

apoc.refactor.cloneSubgraph([node1, node2], [rel1]) => {nodes: [...], rels: [...]}

func CloneSubgraphFromPaths

func CloneSubgraphFromPaths(paths []map[string]interface{}) map[string]interface{}

CloneSubgraphFromPaths clones subgraph from paths.

Example:

apoc.refactor.cloneSubgraphFromPaths(paths) => {nodes: [...], rels: [...]}

func DeleteAndReconnect

func DeleteAndReconnect(nodes []*Node, relType string) int

DeleteAndReconnect deletes nodes and reconnects neighbors.

Example:

apoc.refactor.deleteAndReconnect([node1, node2], 'CONNECTED') => count

func Normalize

func Normalize(node *Node, property, newLabel, relType string) map[string]interface{}

Normalize normalizes graph structure.

Example:

apoc.refactor.normalize(node, 'property', 'NewLabel', 'HAS') => normalized

func RenameLabel

func RenameLabel(oldLabel, newLabel string) int

RenameLabel renames a label on all nodes that have it.

Example:

apoc.refactor.rename.label('OldLabel', 'NewLabel') => count

func RenameProperty

func RenameProperty(oldName, newName string) int

RenameProperty renames a property on all nodes that have it.

Example:

apoc.refactor.rename.nodeProperty('oldName', 'newName') => count

func RenameRelProperty

func RenameRelProperty(oldName, newName string) int

RenameRelProperty renames a property on all relationships that have it.

Example:

apoc.refactor.rename.relProperty('oldName', 'newName') => count

func RenameType

func RenameType(oldType, newType string) int

RenameType renames a relationship type on all relationships.

Example:

apoc.refactor.rename.type('OLD_TYPE', 'NEW_TYPE') => count

Types

type Node

type Node = storage.Node

Node represents a graph node.

func CategorizeProperty

func CategorizeProperty(node *Node, property, newProperty string, categories [][]interface{}) *Node

CategorizeProperty categorizes a property value.

Example:

apoc.refactor.categorize(node, 'age', 'ageGroup', [[0,18,'child'], [18,65,'adult']])

func CloneNodes

func CloneNodes(nodes []*Node) []*Node

CloneNodes clones nodes with new IDs.

Example:

apoc.refactor.cloneNodes([node1, node2]) => cloned nodes

func Denormalize

func Denormalize(node *Node, relType, property string) *Node

Denormalize denormalizes graph structure.

Example:

apoc.refactor.denormalize(node, 'HAS', 'property') => denormalized

func ExtractNode

func ExtractNode(rel *Relationship, labels []string, props map[string]interface{}) *Node

ExtractNode extracts a node from a relationship.

Example:

apoc.refactor.extractNode(rel, ['Person'], {name: 'Intermediate'}) => node

func MergeNodes

func MergeNodes(nodes []*Node, config map[string]interface{}) *Node

MergeNodes merges multiple nodes into one.

Example:

apoc.refactor.mergeNodes([node1, node2], {properties: 'combine'}) => merged node

func NormalizeAsBoolean

func NormalizeAsBoolean(node *Node, property string, trueValues, falseValues []string) *Node

NormalizeAsBoolean normalizes property to boolean.

Example:

apoc.refactor.normalizeAsBoolean(node, 'active', ['yes', 'true'], ['no', 'false'])

type Relationship

type Relationship = storage.Relationship

Relationship represents a graph relationship.

func ChangeType

func ChangeType(rel *Relationship, newType string, config map[string]interface{}) *Relationship

ChangeType changes relationship type with properties.

Example:

apoc.refactor.changeType(rel, 'NEW_TYPE', {keepProps: true})

func CollapseNode

func CollapseNode(node *Node, relType string) []*Relationship

CollapseNode collapses a node by connecting its neighbors.

Example:

apoc.refactor.collapseNode(node, 'CONNECTED') => relationships created

func From

func From(rel *Relationship, newStart *Node) *Relationship

From redirects relationship from a new node.

Example:

apoc.refactor.from(rel, newStartNode) => relationship

func InvertRelationship

func InvertRelationship(rel *Relationship) *Relationship

InvertRelationship inverts relationship direction.

Example:

apoc.refactor.invert(rel) => inverted relationship

func MergeRelationships

func MergeRelationships(rels []*Relationship, config map[string]interface{}) *Relationship

MergeRelationships merges multiple relationships into one.

Example:

apoc.refactor.mergeRelationships([rel1, rel2]) => merged relationship

func RedirectRelationship

func RedirectRelationship(rel *Relationship, newEnd *Node) *Relationship

RedirectRelationship redirects a relationship to a new node.

Example:

apoc.refactor.to(rel, newEndNode) => relationship

func SetType

func SetType(rel *Relationship, newType string) *Relationship

SetType changes relationship type.

Example:

apoc.refactor.setType(rel, 'NEW_TYPE') => relationship

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL