You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

如何为GitLab GraphQL查询添加spentAt日期过滤条件?

问题描述

通过GitLab GraphQL获取了问题列表,但无法实现按spentAt日期过滤。当前使用的查询语句及输出结果如下:

查询语句

query { 
  group(fullPath: "GROUP") {
    issues {
      nodes {
        title
        iid
        timelogs {
          nodes {
            summary
            timeSpent
            spentAt
            user {
              username
            }  
          }
        }
      }
    }
  }
}

输出结果示例

{
  "data": {
    "group": {
      "issues": {
        "nodes": [
          {
            "title": "Col Methods and UI for transaction",
            "iid": "8",
            "timelogs": {
              "nodes": [
                {
                  "summary": "works for us on the camera",
                  "timeSpent": 28800,
                  "spentAt": "2025-02-04T00:00:00-05:00",
                  "user": {
                    "username": "abc123"
                  }
                }
              ]
            }
          }
        ]
      }
    }
  }
}

需要添加过滤条件,仅显示spentAt大于2025-02-01的问题。


解决方案

要实现按spentAt过滤,需要在两个层级添加过滤参数:

  1. 在issues字段添加timelogsFilter,确保只返回包含符合日期条件工时记录的问题;
  2. 在timelogs字段添加filter,确保返回的工时记录仅包含符合日期条件的条目。

修改后的查询语句如下:

query { 
  group(fullPath: "GROUP") {
    issues(
      timelogsFilter: {
        spentAt: {
          gt: "2025-02-01T00:00:00Z"
        }
      }
    ) {
      nodes {
        title
        iid
        timelogs(
          filter: {
            spentAt: {
              gt: "2025-02-01T00:00:00Z"
            }
          }
        ) {
          nodes {
            summary
            timeSpent
            spentAt
            user {
              username
            }  
          }
        }
      }
    }
  }
}

关键说明

  • timelogsFilter(用于issues字段):过滤出至少有一条符合spentAt > 2025-02-01工时记录的问题,避免返回完全没有符合条件工时的问题;
  • filter(用于timelogs字段):确保每个问题下返回的工时记录仅包含符合日期条件的条目,不会混入不符合的记录;
  • 日期格式需使用ISO 8601格式(如2025-02-01T00:00:00Z),GitLab的GraphQL接口对日期格式有严格要求。

内容的提问来源于stack exchange,提问作者ndasusers

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.06.14 13:38:25