cancel
Showing results for 
Search instead for 
Did you mean: 

Head's Up! These forums are read-only. All users and content have migrated. Please join us at community.neo4j.com.

Correct Way To Use GraphQL Input Type

MuddyBootsCode
Graph Steward

I'm trying to create a mutation that will clone a number of nodes that have a unique ID constraint on them using an array of GraphQL Input types, the type is as follows:

input CloneInput {
    nodeToClone: ID!
    nodeType: String!
    relationship: String!
}

The cypher query I'm running is:

cloneLeaseForTemplate(leaseID: ID!, newLeaseName: String, clones: [CloneInput]): Lease
@cypher(statement:
"MATCH (l:Lease {id: $leaseID})
CALL apoc.refactor.cloneNodes([l], false, ['id'])
YIELD output set output.id = randomUUID(), output.leaseName = $newLeaseName
WITH output as Lease UNWIND $clones as clone
MATCH (n:clone.nodeType {id: clone.nodeToClone}) 
CALL apoc.refactor.cloneNodes([n], false, ['id'])
YIELD output set output.id = randomUUID()
MERGE (Lease)-[:clone.relationship]->(output) return Lease"
    )

I'm getting an error:

"message": "Failed to invoke procedure `apoc.cypher.doIt`: Caused by: 
org.opencypher.v9_0.util.SyntaxException: 
Invalid input '.': expected an identifier character, whitespace,
NodeLabel, a property map, ')' or a relationship pattern (line 1, column 363 (offset: 362))"

I'm sure it's because I'm calling the input variables incorrectly I'm just not quite sure where to fix them. Any guidance would be appreciated.

Thank you.

1 REPLY 1

Cypher doesn't allow for dynamic labels nor dynamic relationship types.

MATCH (n:clone.nodeType {id: clone.nodeToClone}) needs to be changed to MATCH (n{id:clone.nodeToClone}) where clone.nodeType in labels(n) . Be aware that this will force a full node scan.