当我添加从 graphql 到 neo4j 的节点之间的关系时,为什么 "run seedDb" 会失败

Why does "run seedDb" fail when I add in relations between nodes moving from graphql to neo4j

我得到了 demo example from grand-stack 并且能够启动 graphql,启动 Neo4J 沙箱并使用

填充测试数据库
npm run seedDb 

但是,当我尝试编写自己的数据条目以填充到 neo4j 数据库中时,我根本无法使节点之间的关系发挥作用。错误消息是最无用的消息(我相信它来自 apollo 客户端,并且是状态代码 400 错误)。我将代码简化为最简单的情况以使其起作用,但它仍然不起作用。这是 schema.graphql 文件:

  type Patient {
  id: ID!
  name: String
  reviews: [Review] @relation(name:"WROTE", direction:"OUT")

}

type Review {
  id: ID!
  stars: Int
  text: String
  date: Date
  user: Patient @relation(name: "WROTE", direction: "IN")
}

这里是种子-mutation.js文件:

export default /* GraphQL */ `
  mutation {
    p1: CreatePatient(
      id: "p1", 
      name: "John Doe 1"
    ) {
      id
      name
    } 

   r1: CreateReview(id: "r1", stars: 4, text: "Great IPA selection!", date: { formatted: "2016-01-03"}) {
      id
    }

  ar1: AddUserReviews(from: { id: "p1"}, to: { id: "r1" }) { from {id}}    

  }
`;

当我执行 "npm run seedDb" 时,会产生错误消息:

{ Error: Network error: Response not successful: Received status code 400
    at new ApolloError (/Users/xxxx/Downloads/grand-stack-starter-master/api/node_modules/apollo-client/bundle.esm.js:60:28)
    at Object.error (/Users/xxxx/Downloads/grand-stack-starter-master/api/node_modules/apollo-client/bundle.esm.js:1032:48)
    at notifySubscription (/Users/xxxx/Downloads/grand-stack-starter-master/api/node_modules/zen-observable/lib/Observable.js:134:18)
    at onNotify (/Users/xxxx/Downloads/grand-stack-starter-master/api/node_modules/zen-observable/lib/Observable.js:165:3)
    at SubscriptionObserver.error (/Users/xxxx/Downloads/grand-stack-starter-master/api/node_modules/zen-observable/lib/Observable.js:224:7)
    at /Users/xxxx/Downloads/grand-stack-starter-master/api/node_modules/apollo-link-http/src/httpLink.ts:184:20
    at <anonymous>
    at process._tickDomainCallback (internal/process/next_tick.js:228:7)
  graphQLErrors: [],
  networkError: 
   { ServerError: Response not successful: Received status code 400
    at Object.exports.throwServerError (/Users/xxxx/Downloads/grand-stack-starter-master/api/node_modules/apollo-link-http-common/src/index.ts:114:17)
    at /Users/xxxx/Downloads/grand-stack-starter-master/api/node_modules/apollo-link-http-common/src/index.ts:145:11
    at <anonymous>
    at process._tickDomainCallback (internal/process/next_tick.js:228:7)
     name: 'ServerError',
     response: 
      Response {
        size: 0,
        timeout: 0,
        [Symbol(Body internals)]: [Object],
        [Symbol(Response internals)]: [Object] },
     statusCode: 400,
     result: { errors: [Array] } },
  message: 'Network error: Response not successful: Received status code 400',
  extraInfo: undefined }

我从多个复杂的代码开始,这几乎是最精简的版本。当我运行seedDB命令后seed-mutation.js文件被修改为:

export default /* GraphQL */ `
  mutation {
    p1: CreatePatient(
      id: "p1", 
      name: "John Doe 1"
    ) {
      id
      name
    } 

   r1: CreateReview(id: "r1", stars: 4, text: "Great IPA selection!", date: { formatted: "2016-01-03"}) {
      id
    }
  }
`;

数据库被填充,但是两个节点没有像预期的那样相互连接(基本上,这是删除了 AddUserReviews 的代码)。如何通过使用 graphql 和 seedDb 建立节点之间的关系?我错过了什么?

您可以使用 GraphQL Playground 检查 GraphQL API(在 "Docs" 选项卡中):

确保您调用的突变具有正确的名称和参数。从检查模式来看,您想要的不是 AddUserReviews,而是 AddPatientReviews?