Neo4J beginner: issues with CALL apoc.create.relationship

`CALL apoc.load.xls('file:///filename.xlsx','Nodes') YIELD map as m

CALL apoc.create.node([m.fromNodeLabel], {name:m.fromNodeName,value:m.fromValue,instanceID:m.InstanceID}) YIELD node as f

CALL apoc.merge.node.eager([m.toNodeLabel], {name:m.toNodeName,instanceID:m.InstanceID}) YIELD node as t

CALL apoc.create.relationship(f,m.relship,{weight:10}, t)`

Variables YIELDed by the Create & Merge statements cannot be passed into the create.relationship statement without...something...?

warwick ,
could you please share the error you are getting .

Hi warwick,

Please mention Yield for apoc.create.relationship(f,m.relship,{weight:10}, t)
i.e.,
CALL apoc.load.xls('file:///filename.xlsx','Nodes') YIELD map as m CALL
CALL apoc.create.node([m.fromNodeLabel], {name:m.fromNodeName,value:m.fromValue,instanceID:m.InstanceID}) YIELD node as f
CALL apoc.create.node([m.toNodeLabel], {name:m.toNodeName,instanceID:m.InstanceID}) YIELD node as t
CALL apoc.create.relationship(f,m.relship,{weight:10}, t) yield rel as rel return rel,f,t

Procedure call inside a query does not support naming results implicitly (name explicitly using YIELD instead) (line 4, column 1 (offset: 294))
"CALL apoc.create.relationship(f,m.relship,{weight:10}, t)"
^

That did it - I did not realise you must include a YIELD on the APOC create.
THANK YOU!

If you are running a procedure all by itself then you don't need to do yield. If you are using somewhere in the middle of a cypher query you need to do yield.

2 Likes

This may sound like a stupid question - but how do we know exactly what is yielded by these calls? I could not find it in 11.4. Creating Data - Chapter 11. Node, Relationship and Path Functions and Procedures

Please go through this link for YIELD https://neo4j.com/docs/cypher-manual/current/clauses/call/

If you need to use the output of a procedure use Yield. This use could be in Return statement or in other query etc.

Procedure apoc.create.relationship can just give you output node or relationship and that is what I did. In the neo4j documentation details of Yield is only given for generic procedures like CALL apoc.create.uuids(count) YIELD uuid, row.

There are 2 types of extensions in apoc.

Functions and Procedures.

Please see the documentation here
https://neo4j.com/docs/labs/apoc/current/overview/

Functions - They are inline functions that can return a single value.

Ex: apoc.node.degree.in

Functions can be used in where conditions, WITH etc.

Ex:

MATCH (n) WHERE apoc.node.degree.in(n, 'NEXT') > 0 

This query returns all the nodes which has more than one incoming NEXT relationship.

Procedures:
These can return more than one values. Those values are handled using YIELD.

If you search in the doc you can find signature as

apoc.create.relationship(from :: NODE?, relType :: STRING?, props :: MAP?, to :: NODE?) :: (rel :: RELATIONSHIP?)

You can see the return value here as only one (rel :: RELATIONSHIP?)

Hope this explains it better.