refactor

package
v1.5.2 Latest Latest
Warning

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

Go to latest
Published: Nov 23, 2026 License: MIT Imports: 3 Imported by: 1 module, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

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

This section is empty.

Functions

This section is empty.

Types

type Functions

type Functions struct {
	// contains filtered or unexported fields
}

Functions binds this package's storage-dependent helpers to one storage backend. The backend is fixed when the instance is created, so a handler an already-admitted caller holds keeps the backend it was built for.

func New

func New(backend storage.Storage) *Functions

New returns this package's helpers bound to backend. One instance serves one backend; a reconfiguration builds a new instance instead of rebinding this one.

func (*Functions) CloneNodes

func (f *Functions) CloneNodes(ctx context.Context, nodes []*Node) ([]*Node, error)

CloneNodes clones nodes with new IDs.

Example:

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

func (*Functions) CloneSubgraph

func (f *Functions) CloneSubgraph(ctx context.Context, nodes []*Node, rels []*Relationship) (map[string]interface{}, error)

CloneSubgraph clones a subgraph.

Example:

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

func (*Functions) CloneSubgraphFromPaths

func (f *Functions) CloneSubgraphFromPaths(ctx context.Context, paths []map[string]interface{}) (map[string]interface{}, error)

CloneSubgraphFromPaths clones subgraph from paths.

Example:

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

func (*Functions) CollapseNode

func (f *Functions) CollapseNode(ctx context.Context, node *Node, relType string) ([]*Relationship, error)

CollapseNode collapses a node by connecting its neighbors.

Example:

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

func (*Functions) DeleteAndReconnect

func (f *Functions) DeleteAndReconnect(ctx context.Context, nodes []*Node, relType string) (int, error)

DeleteAndReconnect deletes nodes and reconnects neighbors.

Example:

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

func (*Functions) Denormalize

func (f *Functions) Denormalize(ctx context.Context, node *Node, relType, property string) (*Node, error)

Denormalize denormalizes graph structure.

Example:

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

func (*Functions) ExtractNode

func (f *Functions) ExtractNode(ctx context.Context, rel *Relationship, labels []string, props map[string]interface{}) (*Node, error)

ExtractNode extracts a node from a relationship.

Example:

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

func (*Functions) Normalize

func (f *Functions) Normalize(ctx context.Context, node *Node, property, newLabel, relType string) (map[string]interface{}, error)

Normalize normalizes graph structure.

Example:

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

func (*Functions) RenameLabel

func (f *Functions) RenameLabel(ctx context.Context, oldLabel, newLabel string) (int, error)

RenameLabel renames a label on all nodes that have it.

Example:

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

func (*Functions) RenameProperty

func (f *Functions) RenameProperty(ctx context.Context, oldName, newName string) (int, error)

RenameProperty renames a property on all nodes that have it.

Example:

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

func (*Functions) RenameRelProperty

func (f *Functions) RenameRelProperty(ctx context.Context, oldName, newName string) (int, error)

RenameRelProperty renames a property on all relationships that have it.

Example:

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

func (*Functions) RenameType

func (f *Functions) RenameType(ctx context.Context, oldType, newType string) (int, error)

RenameType renames a relationship type on all relationships.

Example:

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

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 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 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