首页 > 解决方案 > GraphQL Mutation 使用 neo4j-graphql-js 从 Neo4j 数据库返回 Null

问题描述

我有一个突变,旨在创建汽车并将汽车分配给所有者。我使用 Neo4j 作为底层数据库,所以我cypher像这样在我的 Graphql 模式文件中扩展指令

    CreateCar(data: CarInput!): Car!
        @cypher(
            statement: """
            MERGE(s:Car {name: $data.name})
               ON CREATE
                SET s.id = apoc.create.uuid(), s.name = $data.name, s.description = $data.description, s.category = $data.category,
                 WITH s
                 MATCH(o:Owner {id: $cypherParams.currentUserId})
                 MERGE(o)-[:OWNS]->(s)
            RETURN s
            """
        )

当我在我的 Graphql Playground 中运行上述突变时,当数据插入数据库时​​,突变成功运行,但我从 Playground 得到回复,说"message": "Cannot return null for non-nullable field Mutation.CreateCar."我也使用 Neo4J Browser 尝试了相同的查询并且它可以工作,但是运行突变,数据不会返回。任何帮助将不胜感激,非常感谢。

标签: node.jsneo4jgraphql

解决方案


推荐阅读