在Apollo服务器中接受参数时,字段级密码语句不起作用



字段级的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")
}
}

这是阿波罗游乐场的错误日志:

{"错误":[{"消息":"无效的输入'_someId':应为\n"\n〃%"\n〃";\n〃+"\n〃"\n〃-"\n〃"\n〃/"\n〃:"\n"lt"\n〃<"\n〃<gt"\n〃="\n〃=~"\n〃>quot;\n〃>"\n"与";\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:问题{id:$someId})RETURN q.requested";,{this:question,cypherParams:$cypherParams,someId:$1_someId},false)}ASquestion〃;\n
^〃;,"位置":[{"行":2."列":3.}],"路径":["问题";],"扩展":{"代码":"INTERNAL_SERVER_ERROR";,"异常":{"代码":"尼奥。ClientError。陈述SyntaxError";,"name":"Neo4jError";,"stacktrace":["Neo4j错误:输入"_someId"无效:应为";,"";,"quot;%";,"quot
"&";,"quot+";,"";,"quot-";,"";,"quot/";,"quot;:";,"quot<quot&";,"quot<";,"quot<gt";,"quot=";,"quot=~";,"quot>quot&";,"quot>";,"quot;"与"&";,"quot;CONTAINS"&";,"quot;ENDS"&";,"quot;IN"&";,"quot;IS"&";,"quot;OR"&";,"quot;STARTS"&";,"quot;XOR"&";,"quot;[";,"quot^";,"quot;}"(第1行第195列(偏移量:194))";,"quot;MATCH(question:Question)RETURNquestion{testing:apoc.cypher.runFirstColumn("MATCH(q:问题{id:$someId})RETURN q.requested";,{this:question,cypherParams:$cypherParams,someId:$1_someId},false)}ASquestion〃&";,"&";,":&";,"在captureStacktrace(/home/m1/citizentic/grand-housing/nod_modules/neo4j-driver-core/lib/result.js:239:17)";,"在新的Result(/home/m1/citizentic/grand-housing/nod_modules/neo4j-driver-core/lib/Result.js:59:23)";,"在newCompletedResult(/home/m1/citizentic/grand-housing/nod_modules/neo4j driver-core/lib/transaction.js:372:12)";,"在Object.run(/home/m1/citizentic/grand-housing/nod_modules/neo4j-driver-core/lib/transaction.js:226:20)";,"在Transaction.run(/home/m1/citizentic/grand-housing/nod_modules/neo4j-driver-core/lib/Transaction.js:98:34)";,"at_callee3$(/home/m1/citizentic/grand-housing/nod_modules/neo4j graphql-js/dist/index.js:226:35)";,"在tryCatch(/home/m1/citizentic/grand-housing/nod_modules/regenerator runtime/runtime.js:63:40)";,"在Generator.invoke[as_invoke](/home/m1/citizentic/grand-housing/node_modules/regenerator runtime/runtime.js:293:22)";,"在Generator.next(/home/m1/citizentic/grand-housing/nod_modules/regenerator runtime/runtime.js:118:21)";,"在asyncGeneratorStep(/home/m1/citizentic/grand-housing/nod_module/@babel/runtime-corejs2/helpers/asyncToGenerator/index.js:5:24)";,"在_next(/home/m1/citizentic/grand-housing/nod_module/@babel/runtime-corejs2/helpers/asyncToGenerator/index.js:27:9)";,"在/home/m1/citizentic/grand-house/node_modules/@babel/runtime-corejs2/helpers/asyncToGenerator/index.js:34:7";,"在new Promise()";,"在新的F(/home/m1/citizentic/grand-housing/node_modules/@babel/runtime-corejs2/node_modules/core js/library/modules_export.js:36:28)";,"在/home/m1/citizentic/grand-house/node_modules/@babel/runtime-corejs2/helpers/asyncToGenerator/index.js:23:12";,"在/home/m1/citizentic/grand-house/node_modules/neo4j graphql-js/dist/index.js:241:30";]}}}],";数据":{"问题":null}}

My 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") 
}

最新更新