apoc.custom.asProcedure

Procedure APOC Full Deprecated

apoc.custom.asProcedure(name, statement, mode, outputs, inputs, description) - register a custom cypher procedure

Signature

apoc.custom.asProcedure(name :: STRING?, statement :: STRING?, mode = read :: STRING?, outputs = null :: LIST? OF LIST? OF STRING?, inputs = null :: LIST? OF LIST? OF STRING?, description =  :: STRING?) :: VOID

Input parameters

Name Type Default

name

STRING?

null

statement

STRING?

null

mode

STRING?

read

outputs

LIST? OF LIST? OF STRING?

null

inputs

LIST? OF LIST? OF STRING?

null

description

STRING?

Usage Examples

Please note that apoc.custom.asFunction and apoc.custom.asProcedure are deprecated in favor of apoc.custom.declareFunction and apoc.custom.declareProcedure. See here for more info.

This is the list of input parameters, name and statement are mandatory fields:

Table 1. Parameters
name default description

name

none

dot-separated name, will be prefixed with custom

statement

none

cypher statement to run, can use $parameters

mode

read

execution mode of the procedure: read, write, or schema

outputs

[["row","MAP"]]

List of pairs of name-type to be used as output columns, need to be in-order with the cypher statement, the default is a special case, that will collect all columns of the statement result into a map

inputs

[["params","MAP","{}"]]

Pairs or triples of name-type-default, to be used as input parameters. The default just takes an optional map, otherwise they will become proper paramters in order

description

""

A general description about the business rules implemented into the procedure

Given statement will be registered as a procedure, the results will be turned into a stream of records. The type names can be the same as apoc.custom.declare* analogues.

Here is a simple example:

CALL apoc.custom.asProcedure('answer','RETURN 42 as answer')

This registers the statement as procedure custom.answer that you then can call. As no information on a parameter and return types is given, it just returns a stream of columns of maps called row.

CALL custom.answer() YIELD row
RETURN row.answer
Find neighbours of a node by name
CALL apoc.custom.asProcedure('neighbours',
  'MATCH (n:Person {name:$name})-->(nb) RETURN nb as neighbour','read',
  [['neighbour','NODE']],[['name','STRING']], 'get neighbours of a person');

CALL custom.neighbours('Keanu Reeves') YIELD neighbour;

We can create the function custom.powers that returns a stream of the powers of the first parameter, up to and including the power provided by the second parameter:

CALL apoc.custom.asProcedure(
  'powers',
  'UNWIND range(0, $power) AS power
   RETURN $input ^ power AS answer',
  'read',
  [['answer', 'long']],
  [['input','long'],  ['power', 'long']]
);

We can use this function, to return 9°, 9¹, 9², and 9³, as shown in the query below:

CALL custom.powers(9, 3);
Table 2. Results
answer

1.0

9.0

81.0

729.0