【问题标题】:Field-level cypher statements do not work when accepting parameters in Apollo-server在 Apollo-server 中接受参数时,字段级密码语句不起作用
【发布时间】:2021-10-04 15:54:36
【问题描述】:

字段级别的 cypher 指令不能用作 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 {测试:apoc.cypher.runFirstColumn("MATCH (q:Question {id:$someId}) 返回 q.required", {this: question, cypherParams: $cypherParams, someId: $1_someId}, false)} AS question"\n
^", “地点”:[ { “线”:2, “列”:3 } ], “小路”: [ “题” ], “扩展”:{ “代码”:“INTERNAL_SERVER_ERROR”, “例外”: { "code": "Neo.ClientError.Statement.SyntaxError", "name": "Neo4jError", “堆栈跟踪”: [ "Neo4jError: 无效输入 '_someId': 预期", " "!="", " "%"", " "
"", " "+"", " ","", " "-"", " "."", " "/"", " ":"", " """, " "="", " "=~"", " ">"", " ">="", “ “和””, " "包含"", " "结束"", “ “在””, “ “是””, “ “要么””, " "开始"", " "异或"", " "["", " "^"", “”}“(第 1 行,第 195 列(偏移量:194))”, ""MATCH (question:Question) 返回question {测试:apoc.cypher.runFirstColumn("MATCH (q:Question {id:$someId}) 返回 q.required", {this: question, cypherParams: $cypherParams, someId: $1_someId}, false)} AS 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)", “在_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", “在新的承诺()”, " 在新 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 cypher apollo-server grandstack


    【解决方案1】:

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

    【讨论】:

    • 我们使用带有自定义参数的顶级查询就好了。它只是不适用于类型的字段级别。
    • 我猜这不是 neo4j-graphql-js 在其最新版本中的功能。这是一个正在快速发展的图书馆,因此可能会有许多重大变化。但是我相信你可以用不同的方式完成很多事情,即使当前的功能不允许优雅地完成它。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2014-02-07
    • 2015-10-04
    • 2012-02-17
    • 2020-05-05
    • 1970-01-01
    • 2023-03-30
    • 1970-01-01
    相关资源
    最近更新 更多