如何解决在 Apollo-server
字段级别的密码指令不能用作 expected。
最小示例:
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 中看到的错误日志:
{“错误”:[
{
"message": "无效输入 '_someId': 预期\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“匹配(question
:Question
)返回question
{testing: apoc.cypher.runFirstColumn("MATCH (q:Question {id:$someId})
RETURN q.required",{this: question,cypherParams: $cypherParams,someId: $1_someId},false)} AS question
"\n
^",“地点”:[
{
“线”:2,
“列”:3
}
],“小路”: [
“问题”
],“扩展”:{
"code": "INTERNAL_SERVER_ERROR",“例外”: {
"code": "Neo.ClientError.Statement.SyntaxError","name": "Neo4jError",“堆栈跟踪”: [
"Neo4jError: 无效输入 '_someId': 预期"," "!=""," "%""," """,""+"",""," "-""," ".""," "/""," ":""," """," "=""," "=~"","">""," ">="",“ “和””,
""包含""," "结束"",“ “在””,
“ “是””,
“ “要么””,
" "开始""," "异或""," "[""," "^""," "}"(第 1 行,第 195 列(偏移量:194))",""MATCH (question
:Question
) RETURN question
{testing: apoc.cypher.runFirstColumn("MATCH (q:Question {id:$someId})
RETURN q.required",false)} AS question
"","^",": "," at 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)"," at 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)"," 在 _next (/home/m1/citizentric/grand-housing/node_modules/@babel/runtime-corejs2/helpers/asyncToGenerator/index.js:27:9)"," 在 /home/m1/citizentric/grand-housing/node_modules/@babel/runtime-corejs2/helpers/asyncToGenerator/index.js:34:7"," at new Promise()"," 在新 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 } }
我的 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",
使用密码装饰器的顶级查询(带参数)和字段级查询可以正常工作,只要它们不接受参数即可。 我的印象是这在早些时候奏效了。
解决方法
除非您创建突变,否则库 "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")
}
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。