0

The cypher directive on a field-level does not work as expected.

Minimal example:

type Question {
  id: ID! @id
  required: Boolean
  testing(someId: ID!): Boolean
    @cypher(statement: """
      MATCH (q:Question {id:$someId}) RETURN q.required
    """)
}

When running the below query, I'm getting an error.

{
  Question {
    testing(someId: "12345678-1234-1234-1234-0123456789ab")
  }
}

This is the error log as seen in the Apollo Playground:

{ "errors": [ { "message": "Invalid input '_someId': expected\n "!="\n "%"\n ""\n "+"\n ","\n "-"\n "."\n "/"\n ":"\n "<"\n "<="\n "<>"\n "="\n "=~"\n ">"\n ">="\n "AND"\n "CONTAINS"\n "ENDS"\n "IN"\n "IS"\n "OR"\n "STARTS"\n "XOR"\n "["\n "^"\n "}" (line 1, column 195 (offset: 194))\n"MATCH (question:Question) RETURN question {testing: apoc.cypher.runFirstColumn("MATCH (q:Question {id:$someId}) RETURN q.required", {this: question, cypherParams: $cypherParams, someId: $1_someId}, false)} AS question"\n
^", "locations": [ { "line": 2, "column": 3 } ], "path": [ "Question" ], "extensions": { "code": "INTERNAL_SERVER_ERROR", "exception": { "code": "Neo.ClientError.Statement.SyntaxError", "name": "Neo4jError", "stacktrace": [ "Neo4jError: Invalid input '_someId': expected", " "!="", " "%"", " "
"", " "+"", " ","", " "-"", " "."", " "/"", " ":"", " "<"", " "<="", " "<>"", " "="", " "=~"", " ">"", " ">="", " "AND"", " "CONTAINS"", " "ENDS"", " "IN"", " "IS"", " "OR"", " "STARTS"", " "XOR"", " "["", " "^"", " "}" (line 1, column 195 (offset: 194))", ""MATCH (question:Question) RETURN question {testing: apoc.cypher.runFirstColumn("MATCH (q:Question {id:$someId}) RETURN q.required", {this: question, cypherParams: $cypherParams, someId: $1_someId}, false)} AS question"", " ^", ": ", " at captureStacktrace (/home/m1/citizentric/grand-housing/node_modules/neo4j-driver-core/lib/result.js:239:17)", " at new Result (/home/m1/citizentric/grand-housing/node_modules/neo4j-driver-core/lib/result.js:59:23)", " at newCompletedResult (/home/m1/citizentric/grand-housing/node_modules/neo4j-driver-core/lib/transaction.js:372:12)", " at Object.run (/home/m1/citizentric/grand-housing/node_modules/neo4j-driver-core/lib/transaction.js:226:20)", " at Transaction.run (/home/m1/citizentric/grand-housing/node_modules/neo4j-driver-core/lib/transaction.js:98:34)", " at _callee3$ (/home/m1/citizentric/grand-housing/node_modules/neo4j-graphql-js/dist/index.js:226:35)", " at tryCatch (/home/m1/citizentric/grand-housing/node_modules/regenerator-runtime/runtime.js:63:40)", " at Generator.invoke [as _invoke] (/home/m1/citizentric/grand-housing/node_modules/regenerator-runtime/runtime.js:293:22)", " at Generator.next (/home/m1/citizentric/grand-housing/node_modules/regenerator-runtime/runtime.js:118:21)", " at asyncGeneratorStep (/home/m1/citizentric/grand-housing/node_modules/@babel/runtime-corejs2/helpers/asyncToGenerator/index.js:5:24)", " at _next (/home/m1/citizentric/grand-housing/node_modules/@babel/runtime-corejs2/helpers/asyncToGenerator/index.js:27:9)", " at /home/m1/citizentric/grand-housing/node_modules/@babel/runtime-corejs2/helpers/asyncToGenerator/index.js:34:7", " at new Promise ()", " at new F (/home/m1/citizentric/grand-housing/node_modules/@babel/runtime-corejs2/node_modules/core-js/library/modules/_export.js:36:28)", " at /home/m1/citizentric/grand-housing/node_modules/@babel/runtime-corejs2/helpers/asyncToGenerator/index.js:23:12", " at /home/m1/citizentric/grand-housing/node_modules/neo4j-graphql-js/dist/index.js:241:30" ] } } } ], "data": { "Question": null } }

My package.json includes these versions:

"apollo-server": "^2.25.0",
"apollo-server-core": "^2.25.0",
"graphql-tag": "^2.12.5",
"neo4j-driver": "^4.3.1",
"neo4j-graphql-js": "^2.19.2",

Top-level queries (with arguments) and field-level queries with the cypher decorator work fine as long as these do not accept parameters. I was under the impression that this has worked earlier.

manonthemat
  • 6,101
  • 1
  • 24
  • 49

1 Answers1

0

The library "neo4j-graphql-js": "^2.19.2" does not seem to pass on custom parameters unless you create a mutation. Try the following way:

type Question {
  id: ID! @id
  required: Boolean
}

extend type Mutation {
  testing(someId: ID!): Boolean
    @cypher(
      statement: """
      MATCH (q:Question {id: $someId}) RETURN q.required
      """
    )
}
mutation {
  testing (someId: "12345678-1234-1234-1234-0123456789ab") 
}
Rikku
  • 428
  • 6
  • 14
  • We're using top-level queries with custom parameters just fine. It's just not working on a type's field-level. – manonthemat Aug 02 '21 at 16:00
  • I guess it wasn't a feature in in neo4j-graphql-js in its last versions. It's a library under rapid development so there can be many breaking changes. However I believe you can accomplish many things in a different way, even if the current features do not allow to do it as elegantly. – Rikku Aug 02 '21 at 17:23