Stored Functions
User-defined Cypher functions with typed parameters, default values, schema namespacing, and body caching. Functions can query the graph, read/write documents, and call other functions (up to 16 levels deep with cycle detection).
CREATE FUNCTION
-- Simple expression function
CREATE FUNCTION greet(name: STRING) RETURNS STRING AS {
'Hello, ' + name + '!'
}
-- With default parameter
CREATE FUNCTION greet(name: STRING = 'World') RETURNS STRING AS {
'Hello, ' + name + '!'
}
-- Graph-reading function
CREATE FUNCTION friend_count(person: STRING) RETURNS INT AS {
MATCH (p:Person {name: person})-[:FRIEND]->(f)
RETURN count(f)
}
-- Document-reading function
CREATE FUNCTION get_email(username: STRING) RETURNS STRING AS {
MATCH DOCUMENT d IN auth.users WHERE d.username = username
RETURN d.email
}
-- Mutating function (writes data)
CREATE FUNCTION log_event(event: STRING) RETURNS VOID MUTATING AS {
CREATE DOCUMENT IN audit uuid() {
event: event,
ts: timestamp()
}
}Calling Functions
-- Inline in expressions (non-mutating only)
MATCH (n:Person)
RETURN n.name, greet(n.name)
-- In WHERE clauses
MATCH (n:Person)
WHERE friend_count(n.name) > 5
RETURN n.name
-- With CALL ... YIELD (required for mutating functions)
CALL log_event('user_login') YIELD result
-- CALL with arguments from MATCH
MATCH (n:Person)
CALL greet(n.name) YIELD result
RETURN n.name, resultManagement
-- Update existing function
CREATE OR REPLACE FUNCTION greet(name: STRING) RETURNS STRING AS {
'Hi, ' + name + '!'
}
-- Drop a function
DROP FUNCTION greet
-- List all functions
SHOW FUNCTIONS
-- List functions in a schema
SHOW FUNCTIONS IN authParameter Types
| Type | Aliases | Description |
|---|---|---|
| STRING | Text value | |
| INT | INTEGER | 64-bit integer |
| FLOAT | DOUBLE | 64-bit floating point |
| BOOL | BOOLEAN | Boolean value |
| LIST | Array / list | |
| MAP | Key-value object | |
| NODE | Graph node | |
| RELATIONSHIP | Graph relationship | |
| ANY | Any type (no validation) | |
| VOID | No return value (mutating only) |
Functions in the auth schema are protected and require admin privileges. Max nesting depth is 16 levels with automatic cycle detection.