0

字段级别的 cypher 指令无法按预期工作。

最小的例子:

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

运行以下查询时,出现错误。

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

这是在 Apollo Playground 中看到的错误日志:

{ "errors": [ { "message": "无效输入 '_someId': 预期\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 "}"(第 1 行,第 195 列(偏移量:194))\n"MATCH ( question: Question) RETURN question {testing: apoc.cypher.runFirstColumn("MATCH (q:Question {id:$someId})返回 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""、""[""、""^""、""}"(第 1 行,第 195 列(偏移量: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)}作为"ENDS""、""IN""、""IS""、""OR""、""STARTS""、""XOR""、""[""、""^""、""} " (line 1, column 195 (offset: 194))", ""MATCH ( : ) RETURN {testing: apoc.cypher.runFirstColumn("MATCH (q:Question {id:$someId}) RETURN q.required", {this: question, cypherParams: $cypherParams, someId: $1_someId}, false)} AS"ENDS""、""IN""、""IS""、""OR""、""STARTS""、""XOR""、""[""、""^""、""} " (line 1, column 195 (offset: 194))", ""MATCH ( : ) RETURN {testing: apoc.cypher.runFirstColumn("MATCH (q:Question {id:$someId}) RETURN q.required", {this: question, cypherParams: $cypherParams, someId: $1_someId}, false)} ASMATCH ( : ) RETURN {testing: apoc.cypher.runFirstColumn("MATCH (q:Question {id:$someId}) RETURN q.required", {this: question, cypherParams: $cypherParams, someId: $1_someId}, false )} 作为MATCH ( : ) RETURN {testing: apoc.cypher.runFirstColumn("MATCH (q:Question {id:$someId}) RETURN q.required", {this: question, cypherParams: $cypherParams, someId: $1_someId}, false )} 作为question""、"^"、":"、" 在 captureStacktrace (/home/m1/citizentric/grand-housing/node_modules/neo4j-driver-core/lib/result.js:239:17)"、" 在新结果(/home/m1/citizentric/grand-housing/node_modules/neo4j-driver-core/lib/result.js:59:23)", "在 newCompletedResult (/home/m1/citizentric/grand-housing/node_modules/neo4j -driver-core/lib/transaction.js:372:12)", "在 Object.run (/home/m1/citizentric/grand-housing/node_modules/neo4j-driver-core/lib/transaction.js:226: 20)", "在 Transaction.run (/home/m1/citizentric/grand-housing/node_modules/neo4j-driver-core/lib/transaction.js:98:34)", "在 _callee3$ (/home/m1/citizentric/grand-housing/node_modules/neo4j-graphql-js/dist/index.js:226:35)", "在 tryCatch (/home/m1 /citizentric/grand-housing/node_modules/regenerator-runtime/runtime.js:63:40)", "在 Generator.invoke [as _invoke] (/home/m1/citizentric/grand-housing/node_modules/regenerator-runtime/ runtime.js:293:22)", "在 Generator.next (/home/m1/citizentric/grand-housing/node_modules/regenerator-runtime/runtime.js:118:21)", "在 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)", "在 /home/m1/citizentric/grand-housing/ node_modules/@babel/runtime-corejs2/helpers/asyncToGenerator/index.js:23:12", "在 /home/m1/citizentric/grand-housing/node_modules/neo4j-graphql-js/dist/index.js:241 :30" ] } } } ], "数据": { "问题": null } }28)", " 在 /home/m1/citizentric/grand-housing/node_modules/@babel/runtime-corejs2/helpers/asyncToGenerator/index.js:23:12", " 在 /home/m1/citizentric/grand-住房/node_modules/neo4j-graphql-js/dist/index.js:241:30" ] } } } ], "data": { "Question": null } }28)", " 在 /home/m1/citizentric/grand-housing/node_modules/@babel/runtime-corejs2/helpers/asyncToGenerator/index.js:23:12", " 在 /home/m1/citizentric/grand-住房/node_modules/neo4j-graphql-js/dist/index.js:241:30" ] } } } ], "data": { "Question": null } }

我的 package.json 包括这些版本:

"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",

只要不接受参数,顶级查询(带参数)和带有密码装饰器的字段级查询就可以正常工作。我的印象是这在早些时候就已经奏效了。

4

1 回答 1

0

除非您创建突变,否则该库"neo4j-graphql-js": "^2.19.2"似乎不会传递自定义参数。试试下面的方法:

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") 
}
于 2021-07-31T21:22:59.793 回答