neo4j - Custom resolver with @cypher schema directive do not accept Date as an Input - GRANDStack
问题描述
I`m trying to add custom resolvers to my grand stack app. There I get an error while passing DateInput to my mutation.
This is my schema:
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
"""
)
}
This is my mutation, I use in the GraphQL playground:
mutation CreateRegistration {
CreateRegistration(
startDate: { year: 2020, month: 3, day: 22 }
endDate: { year: 2020, month: 4, day: 12 }
) {
registrationId
startDate {
formatted
}
}
}
this is the automated generated mutation by neo4j-graphql
package:
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 | }
this is the errorresponse I get back:
{
"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",
When I just use the autogenerated Resolver without @cypher, it works perfectly.
It looks like it is a problem with the input value for my date object. When I remove the date completely, it also works.
Does anybody have a suggestion, what I am doing wrong?
THX
解决方案
当我使用“格式化”版本时它可以工作:
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
}
}
}
推荐阅读
- ansible - 如何编写回调来设置每个任务的 Ansible 日志级别?
- regex - 在 Notepad++ 中更改西里尔字符大小写
- android-studio - 错误:包android.support.v4.content不存在导入android.support.v4.content.FileProvider;
- python - 在 Bokeh 仪表板中使用 Python 进行 K-means 聚类;创建一个表来显示集群的意思
- flutter - 类型“ASN1Object”不是类型转换中“ASN1Sequence”类型的子类型
- reactjs - 功能组件中局部变量的最佳方式反应原生
- python - 使用正则表达式从 ifConfig 获取 MAC 地址
- windows - 如何让 Windows 程序监听来自 WSL 的连接而不绑定到 0.0.0.0?
- javascript - 响应式移动导航栏链接无法在移动设备上运行
- django - 在 Django 中:即使在 forms.py 中使用“queryset = objects.none()”后,我仍然可以看到包含所有选项的下拉菜单