Parameters in Cypher FOREACH loop lead to error

This error occured first with @neo4j/graphql v4.4.6 and is still present in v5.1.0.

  • Up to v4.4.5 there was no problem.

I have a mutation defined like this (abbreviated):

mutate_TopicContent_Update(
    contentOid: ID!
    content: String!
    authorId: ID!
    workProject: [WorkProjectInput]
    workProjectDetails: String
    isSectionHeadline: Int
    firstMainHeading: String
    learningCardTitle: String
    updated: String
  ): TopicContent
    @cypher(
      statement: """
      MATCH ( u:User { oid: $authorId } )
      MATCH ( tc:TopicContent { oid: $contentOid } )
      OPTIONAL MATCH ( tc ) -[r:WORK_PROJECT]-> ( wp_old )
      DELETE r
      FOREACH ( elem IN $workProject |
              MERGE ( wp:WorkProject { oid: elem.oid, ref: elem.ref } )
              MERGE (wp) -[:OWNER]-> (u)
              MERGE (tc)-[:WORK_PROJECT {projectDetails: $workProjectDetails}]-> (wp) )
      SET tc.content = $content, tc.isSectionHeadline = $isSectionHeadline, tc.firstMainHeading = $firstMainHeading, tc.learningCardTitle = $learningCardTitle, tc.updated = $updated
      WITH tc
      RETURN tc as result
      """
      columnName: "result"
    )

Now I call the mutation like this:

mutation Mutate_TopicContent_Update($contentOid: ID!, $content: String!, $authorId: ID!) {
  mutate_TopicContent_Update(contentOid: $contentOid, content: $content, authorId: $authorId) {
    oid
  }
}

(There's no difference in whether I provide the optional parameter or not.)

I get an error like this:

"errors": [
    {
      "message": "Variable `NULLDetails` not defined (line 9, column 56 (offset: 355))\n\"            MERGE (tc)-[:WORK_PROJECT {projectDetails: NULLDetails}]-> (wp) )\"\n                                                        ^",
      "locations": [
        {
          "line": 2,
          "column": 3
        }
      ],
      "path": [
        "mutate_TopicContent_Update"
      ],
      "extensions": {
        "code": "INTERNAL_SERVER_ERROR",
        "stacktrace": [
          "Neo4jError: Variable `NULLDetails` not defined (line 9, column 56 (offset: 355))",
          "\"            MERGE (tc)-[:WORK_PROJECT {projectDetails: NULLDetails}]-> (wp) )\"",
          "                                                        ^",
          "",
          "    at captureStacktrace (/Users/svenho/Projekte/Meteor_2022/graphql_server_neo4j_2024/node_modules/neo4j-driver-core/lib/result.js:620:17)",
          "    at new Result (/Users/svenho/Projekte/Meteor_2022/graphql_server_neo4j_2024/node_modules/neo4j-driver-core/lib/result.js:112:23)",
          "    at newCompletedResult (/Users/svenho/Projekte/Meteor_2022/graphql_server_neo4j_2024/node_modules/neo4j-driver-core/lib/transaction.js:523:12)",
          "    at Object.run (/Users/svenho/Projekte/Meteor_2022/graphql_server_neo4j_2024/node_modules/neo4j-driver-core/lib/transaction.js:355:20)",
          "    at Transaction.run (/Users/svenho/Projekte/Meteor_2022/graphql_server_neo4j_2024/node_modules/neo4j-driver-core/lib/transaction.js:181:34)",
          "    at ManagedTransaction.run (/Users/svenho/Projekte/Meteor_2022/graphql_server_neo4j_2024/node_modules/neo4j-driver-core/lib/transaction-managed.js:54:21)",
          "    at Executor.transactionRun (/Users/svenho/Projekte/Meteor_2022/graphql_server_neo4j_2024/node_modules/@neo4j/graphql/dist/classes/Executor.js:165:28)",
          "    at /Users/svenho/Projekte/Meteor_2022/graphql_server_neo4j_2024/node_modules/@neo4j/graphql/dist/classes/Executor.js:151:33",
          "    at TransactionExecutor._safeExecuteTransactionWork (/Users/svenho/Projekte/Meteor_2022/graphql_server_neo4j_2024/node_modules/neo4j-driver-core/lib/internal/transaction-executor.js:211:26)",
          "    at TransactionExecutor.<anonymous> (/Users/svenho/Projekte/Meteor_2022/graphql_server_neo4j_2024/node_modules/neo4j-driver-core/lib/internal/transaction-executor.js:198:46)"
        ]
      }
    }
  ]

It's interesting that the parameter within the error appears as NULLDetails.

Moreover if I call the same mutation from my UI application I get an Expected parameter(s) error where the parameter now is called something like param6Details.

I would appreciate some help because I do not understand what's happening here and why it suddenly occurred with v4.4.6.

Hi svenho,

I believe this is a bug related to parameter substitutions that happen inside the @cypher statement, likely because the parameters $workProject and $workProjectDetails share the same prefix.

We are better at tracking bugs and feature requests from the GitHub page of the library Issues · neo4j/graphql · GitHub, may I ask you to open a bug report with your reproduction steps so that we can prioritize an eventual bug fix?

We are also active in the discord community https://discord.com/channels/787399249741479977/818578492723036210.

Have a lovely day!

Thank you very much for the explaination, Simone.
I will do so.

Hi @svenho ,
I just wanted to let you know that the fix for the issue you have encountered is being fixed, in the last patch release.