Warm tip: This article is reproduced from serverfault.com, please click

neo4j-具有@cypher模式指令的自定义解析器不接受Date作为输入

(neo4j - Custom resolver with @cypher schema directive do not accept Date as an Input)

发布于 2020-11-29 22:32:30

我正在尝试将自定义解析器添加到我的大堆栈应用程序中。将DateInput传递给我的突变体时出现错误。

这是我的架构:

type Registration @hasRole(roles: [admin]) {
  registrationId: ID!
  startDate: Date!
  endDate: Date
}
type Mutation {
CreateRegistration(startDate: Date!, endDate: Date): Registration
    @cypher(
      statement: """
      CREATE (registration: Registration {
                              registrationId: apoc.create.uuid(),
                              startDate: $startDate,
                              endDate: $endDate
                            })
      RETURN registration
      """
    )
}

这是我的变异,我在GraphQL游乐场中使用:

mutation CreateRegistration {
  CreateRegistration(
    startDate: { year: 2020, month: 3, day: 22 }
    endDate: { year: 2020, month: 4, day: 12 }
  ) {
    registrationId
    startDate {
      formatted
    }
  }
}

这是按neo4j-graphql自动生成的突变

20:49:51 api | 2020-11-29T19:49:51.949Z neo4j-graphql-js CALL apoc.cypher.doIt("CREATE (registration: Registration {registrationId: apoc.create.uuid(), startDate: $startDate, endDate: $endDate})
20:49:51 api | RETURN registration", {startDate:$startDate, endDate:$endDate, first:$first, offset:$offset}) YIELD value
20:49:51 api |     WITH apoc.map.values(value, [keys(value)[0]])[0] AS `registration`
20:49:51 api |     RETURN `registration` { .registrationId ,startDate: { formatted: toString(`registration`.startDate) }} AS `registration`
20:49:51 api | 2020-11-29T19:49:51.949Z neo4j-graphql-js {
20:49:51 api |   "startDate": {
20:49:51 api |     "year": 2020,
20:49:51 api |     "month": 3,
20:49:51 api |     "day": 22
20:49:51 api |   },
20:49:51 api |   "endDate": {
20:49:51 api |     "year": 2020,
20:49:51 api |     "month": 4,
20:49:51 api |     "day": 12
20:49:51 api |   },
20:49:51 api |   "first": -1,
20:49:51 api |   "offset": 0
20:49:51 api | }

这是我得到的错误响应:

{
  "errors": [
    {
      "message": "Failed to invoke procedure `apoc.cypher.doIt`: Caused by: org.neo4j.exceptions.CypherTypeException: Property values can only be of primitive types or arrays thereof",

当我只使用不带@cypher的自动生成的解析器时,它可以完美运行。

看来我的日期对象的输入值有问题。当我完全删除日期时,它也可以使用。

有人有建议吗,我做错了什么?

谢谢

Questioner
cloudyguy
Viewed
11
cloudyguy 2020-12-31 05:43:53

当我使用“格式化”版本时,它可以工作:

type Mutation {
CreateRegistration(startDate: Date!, endDate: Date): Registration
    @cypher(
      statement: """
      CREATE (registration: Registration {
                              registrationId: apoc.create.uuid(),
                              startDate: date($startDate.formatted),
                              endDate: date($endDate.formatted)
                            })
      RETURN registration
      """
    )
}

突变必须在哪里:

mutation CreateRegistration {
  CreateRegistration(
    startDate: { formatted: "2020-3-22" }
    endDate: { formatted: "2020-6-22" }
  ) {
    registrationId
    startDate {
      formatted
    }
  }
}