【发布时间】:2019-06-22 20:43:02
【问题描述】:
我很难理解为什么我尝试执行的查询总是返回 0 个结果。基本上我试图只返回一个日期范围内的结果。在给定的表上,我有一个 createdAt,它是一个 DateTime 标量。这基本上是从 prisma (或 graphql,不确定是哪个设置的)自动填充的。所以在任何表上,我都有 createdAt,它是一个 DateTime 字符串,表示创建时的 DateTime。
这是给定表的架构:
type Audit {
id: ID! @unique
user: User!
code: AuditCode!
createdAt: DateTime!
updatedAt: DateTime!
message: String
}
我查询了这张表,得到了一些结果,我会在这里分享:
"getAuditLogsForUser": [
{
"id": "cjrgleyvtorqi0b67jnhod8ee",
"code": {
"action": "login"
},
"createdAt": "2019-01-28T17:14:30.047Z"
},
{
"id": "cjrgn99m9osjz0b67568u9415",
"code": {
"action": "adminLogin"
},
"createdAt": "2019-01-28T18:06:03.254Z"
},
{
"id": "cjrgnhoddosnv0b67kqefm0sb",
"code": {
"action": "adminLogin"
},
"createdAt": "2019-01-28T18:12:35.631Z"
},
{
"id": "cjrgnn6ufosqo0b67r2tlo1e2",
"code": {
"action": "login"
},
"createdAt": "2019-01-28T18:16:52.850Z"
},
{
"id": "cjrgq8wwdotwy0b67ydi6bg01",
"code": {
"action": "adminLogin"
},
"createdAt": "2019-01-28T19:29:45.616Z"
},
{
"id": "cjrgqaoreoty50b67ksd04s2h",
"code": {
"action": "adminLogin"
},
"createdAt": "2019-01-28T19:31:08.382Z"
}]
这是我的getAuditLogsForUser 架构定义
getAuditLogsForUser(userId: String!, before: DateTime, after: DateTime): [Audit!]!
所以为了测试,我希望得到最后一个和第一个之间的所有结果。
2019-01-28T19:31:08.382Z 是最后一个
2019-01-28T17:14:30.047Z 是第一位的。
这是我将注入查询语句的代码:
if (args.after && args.before) {
where['createdAt_lte'] = args.after;
where['createdAt_gte'] = args.before;
}
console.log(where)
return await context.db.query.audits({ where }, info);
在操场上我执行这个语句
getAuditLogsForUser(before: "2019-01-28T19:31:08.382Z" after: "2019-01-28T17:14:30.047Z") { id code { action } createdAt }
所以我想要将 createdAt_lte(小于或等于)设置为 2019-01-28T17:14:30.047Z 并且将 createdAt_gte(大于或等于)设置为 2019-01-28T19:31:08.382Z 的任何内容
但是,即使我们知道有结果,我实际上也没有得到任何结果。
我试图在 graphql 网站上查找有关 DateTime scalar 的一些文档。我实际上在上面找不到任何东西,但我在生成的 prisma 模式中看到了它。它只是定义为标量。没什么特别的。我认为我也没有在其他地方定义它。如果这有什么不同,我正在使用 Graphql-yoga。
(生成的棱镜文件)scalar DateTime
我想知道它是否真的将其视为真正的日期时间?一定是这样,因为它是作为 UTC 格式的 DateTime ISO 字符串生成的。
现在很难理解我的问题可能是什么,也许我需要以其他方式定义它?任何帮助表示赞赏
【问题讨论】: