Can we use an apoc procedure within a custom user defined procedure?

hey community,
I wanted to ask that can we use apoc procedures inside a custom defined procedure.

I have the following situation :

CALL apoc.custom.declareProcedure('familyTree(app_num::STRING) :: (tree::ANY)',
  ' MATCH (p:PATENT {app_num : $app_num})
    CALL apoc.path.subgraphNodes(p, {
        relationshipFilter: "IS_PARENT_OF",
        labelFilter : "PATENT" ,
        uniqueness : "NODE_GLOBAL"
    })
    YIELD node
    With node.app_num as application
    optional MATCH (parent:PATENT)-[:IS_PARENT_OF]->(:PATENT {app_num : application} )
    optional Match (:PATENT {app_num : application} )-[:IS_PARENT_OF]->(child:PATENT)
    WITH collect(distinct child.app_num) as children, collect(distinct parent.app_num) as parents, application
    return  application,  children ,  parents'
)

and for this query i get the following error :

Failed to invoke procedure `apoc.custom.declareProcedure`: Caused by: java.lang.RuntimeException: Query results do not match requested output.

As far as I can understand there is a mismatch in return type of expectation and the actual return type.
For that I changed the return type from MAP to ANY as you can see in the above query but still I got the same error.

Or that we can not use apoc procedures inside the custom ones ?

I am using neo4j v 5.6.0

Regards,
Aman

I think your procedure definition needs three output parameters, not just one. Looks like an integer, and two lists of integers.

Hey @glilienfield

Thanks for the quick help. It worked.
I thought if we gave MAP as output then it would map those output variables into a single map and return that.

You get what you returned. If you ever want a map, you can return a map as follows:

return  {application: application,  children: children ,  parents: parents} as resultsAsMap

Then your procedure would return a single value of type map.

1 Like