我正在尝试在我的大堆栈应用程序中添加自定义解析器。在那里,当我将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的自动生成的Resolver时,它工作得非常完美。
它看起来是my date对象的输入值出现了问题。当我完全删除日期时,它也能工作。
有人有什么建议吗,我做错了什么?
THX
发布于 2020-12-30 21: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
}
}
}发布于 2020-12-01 09:05:55
问题是,您将对象作为startDate和endDate属性的值传递,neo4j不支持这些属性。
例如,可以使用date函数将对象转换为合适的类型:
type Mutation {
CreateRegistration(startDate: Date!, endDate: Date): Registration
@cypher(
statement: """
CREATE (registration: Registration {
registrationId: apoc.create.uuid(),
startDate: date($startDate),
endDate: date($endDate)
})
RETURN registration
"""
)
}https://stackoverflow.com/questions/65065930
复制相似问题