0

我使用的是 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"
          ]
        }
      }
    }
  ]
}
4

1 回答 1

2

该错误是 Cypher 语法错误。@cypher在 GraphQL 模式定义中的指令中使用的查询Ingredient.quantity不正确,它指的是q尚未定义的变量。由于quantity是关系上的一个属性,Contains并且您的查询绑定c到该关系,因此您的@cypher指令查询应该是

quantity: String @cypher(statement:"MATCH (:Recipe)-[c:Contains]-(this) RETURN c.quantity")

此外,neo4j-graphql-js 的v1.0.1引入了更好的关系类型支持,因此您不必使用@cypher指令来访问关系属性,而只需定义一个关系类型:https ://grandstack.io/docs/neo4j -graphql-js.html#relationships-with-properties

于 2018-10-02T15:51:05.207 回答