我使用的是 GRAND 堆栈启动器,最近升级了我的软件包和 Neo4j 数据库,以匹配 GRAND 启动器套件中确定的当前版本。
这似乎打破了我最基本的查询。我正在为包含食谱的探索创建一个相当简单的演示数据库。我有一个带有配方的节点,其中包括名称、说明和时间。
该节点还具有指示这是什么类型的膳食以及它有多难的关系。你可以在下面看到:
这与我在前端或 Graphql Playground 中的查询返回得很好,并带有以下查询:
query($searchQuery: String = "baked") {
RecipesBySubstring(searchQuery: $searchQuery) {
name
time
instructions
ingredients {
name
quantity
}
mealtype {
type
}
difficulty {
value
}
}
}
我的 graphql-schema.js 文件中的实际定义如下所示:
RecipesBySubstring(searchQuery: String): [Recipe] @cypher(statement:
"MATCH (r:Recipe) WHERE toLower(r.name) CONTAINS toLower($searchQuery) OR toLower(r.time) CONTAINS toLower($searchQuery) RETURN r ORDER BY r.name ASC")
但是,一旦我尝试创建具有属性的关系,它就无法使用这些确切的查询返回任何结果。我与此查询建立关系:
MATCH (r:Recipe{name:"baked spaghetti"}),(i:Ingredient{name:"beef"})
CREATE (r)-[c:Contains{quantity:"1 pound"}]->(i)
RETURN r,i,c
并将其添加到数据库中就好了。
我还在我的 graphql-schema.js 中定义了我的成分,如下所示:
type Ingredient {
name: String!
quantity: String @cypher(statement:"MATCH (:Recipe)-[c:Contains]-(this) RETURN q.quantity")
recipe: Recipe
}
在我升级之前,这些项目都运行良好。我有多个食谱共享我可以查询的成分,查询食谱将根据需要返回所有成分和数量。您可以在下图中看到数据库的上一次迭代,我可以确认这确实在 graphql 操场和我的前端返回:
所以我有点难过可能发生的事情,或者如果有一种新的方式我应该做这些事情。我可以回滚,但由于这是一个学习过程,我想让我的包和数据库保持最新,以应对这些挑战。
尝试查询与属性有关系的节点时,来自 GraphQL Playground 的完整错误如下:
{
"data": {
"RecipesBySubstring": null
},
"errors": [
{
"message": "Failed to invoke function `apoc.cypher.runFirstColumn`: Caused by: org.neo4j.cypher.internal.util.v3_4.SyntaxException: Variable `q` not defined (line 1, column 93 (offset: 92))",
"locations": [
{
"line": 2,
"column": 3
}
],
"path": [
"RecipesBySubstring"
],
"extensions": {
"code": "INTERNAL_SERVER_ERROR",
"exception": {
"code": "Neo.ClientError.Procedure.ProcedureCallFailed",
"name": "Neo4jError",
"stacktrace": [
"Neo4jError: Failed to invoke function `apoc.cypher.runFirstColumn`: Caused by: org.neo4j.cypher.internal.util.v3_4.SyntaxException: Variable `q` not defined (line 1, column 93 (offset: 92))",
"",
" at captureStacktrace (E:\\Recipe Snap\\grand-stack-starter\\api\\node_modules\\neo4j-driver\\lib\\v1\\result.js:200:15)",
" at new Result (E:\\Recipe Snap\\grand-stack-starter\\api\\node_modules\\neo4j-driver\\lib\\v1\\result.js:73:19)",
" at Session._run (E:\\Recipe Snap\\grand-stack-starter\\api\\node_modules\\neo4j-driver\\lib\\v1\\session.js:116:14)",
" at Session.run (E:\\Recipe Snap\\grand-stack-starter\\api\\node_modules\\neo4j-driver\\lib\\v1\\session.js:95:19)",
" at _callee$ (E:\\Recipe Snap\\grand-stack-starter\\api\\node_modules\\neo4j-graphql-js\\dist\\index.js:80:28)",
" at tryCatch (E:\\Recipe Snap\\grand-stack-starter\\api\\node_modules\\regenerator-runtime\\runtime.js:62:40)",
" at Generator.invoke [as _invoke] (E:\\Recipe Snap\\grand-stack-starter\\api\\node_modules\\regenerator-runtime\\runtime.js:296:22)",
" at Generator.prototype.(anonymous function) [as next] (E:\\Recipe Snap\\grand-stack-starter\\api\\node_modules\\regenerator-runtime\\runtime.js:114:21)",
" at step (E:\\Recipe Snap\\grand-stack-starter\\api\\node_modules\\babel-runtime\\helpers\\asyncToGenerator.js:17:30)",
" at E:\\Recipe Snap\\grand-stack-starter\\api\\node_modules\\babel-runtime\\helpers\\asyncToGenerator.js:35:14"
]
}
}
}
]
}