首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >使用属性添加关系会中断其他查询。

使用属性添加关系会中断其他查询。
EN

Stack Overflow用户
提问于 2018-10-02 06:06:27
回答 1查看 537关注 0票数 0

我使用的是大堆栈启动程序,最近通过升级我的软件包和Neo4j数据库来匹配在GRAND starter工具包中识别的当前版本。

这似乎破坏了我最基本的查询。我正在创建一个相当简单的演示数据库,用于包含菜谱的探索。我有一个节点,上面有一个菜谱,包括名称、指令和时间。

这个节点也有关系,指示它是什么样的膳食和它有多难。你可以看到以下情况:

这与前端的查询或Graphql游乐场中的查询返回得很好,查询如下:

代码语言:javascript
复制
query($searchQuery: String = "baked") {
  RecipesBySubstring(searchQuery: $searchQuery) {
    name
    time
    instructions
    ingredients {
      name
      quantity
    }
    mealtype {
      type
    }
    difficulty {
      value
    }
  }
}

我的graphql-schema.js文件中的实际定义如下所示:

代码语言:javascript
复制
  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")

但是,一旦我试图创建一个具有属性的关系,它就无法使用这些精确的查询返回任何结果。我创建了一个与此查询的关系:

代码语言:javascript
复制
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中定义了我的成分如下:

代码语言:javascript
复制
type Ingredient {
  name: String!
  quantity: String @cypher(statement:"MATCH (:Recipe)-[c:Contains]-(this) RETURN q.quantity")
  recipe: Recipe
}

在我升级之前,这些东西都很好用。我有多个食谱,分享我可以查询的配料,查询一个食谱就会根据需要返回所有的配料和数量。您可以在下面的图像中看到数据库的前一次迭代,我可以确认这确实返回到graphql操场和我的前端:

所以我有点困惑到底发生了什么,或者如果有一种新的方式,我应该去做这些事情。我可以退回去,但由于这是一个学习过程,我想保持我的包和数据库的最新通过这些挑战。

当试图查询与属性有关系的节点时,来自GraphQL游乐场的全部错误如下所示:

代码语言:javascript
复制
{
  "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"
          ]
        }
      }
    }
  ]
}
EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2018-10-02 15:51:05

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

代码语言:javascript
复制
quantity: String @cypher(statement:"MATCH (:Recipe)-[c:Contains]-(this) RETURN c.quantity")

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

票数 2
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/52602827

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档