feat(scope): scope analytics queries to an organization

What does this MR do and why?

Adds an organization scope filter for analytics queries, so a dashboard scope picker can scope a panel to an organization. A global ID selects an exact organization, and a blank value selects the current one. Like group and project, it works in the query text and as a filter binding.

Works together with gitlab!268411 (merged), which makes descendantsScope optional at organization level. Without it, the backend rejects an organization query that lists no groups or projects.

Without organization, the root is chosen as before: a scalar group / project, the scope hint, or the path-less organization root for group in (...) / project in (...) lists.

One intended change applies without organization. A quoted in value, such as group in "a", is now read as a list of one, so it joins the other scope lists. On its own it is still the scalar form. Next to another list it is one of the sources: group in "a" and project in ("x/y", "z/w") now returns the union under the organization root instead of drilling down under the group, the same as group in ("a") already did. It also lets group = "a" and project in "x/y" and organization = "" and group in "a" compile, which both failed with "cannot be used together".

Closes #246 (closed)

Details
Value Compiles to
gid://gitlab/Organizations::Organization/1 organization(id: "gid://gitlab/Organizations::Organization/1") { … }
"" (blank) organization { … }, the current organization
anything else compile error: must be an organization global ID, or blank
  • The backend already accepts organization(id:) (Resolvers::Organizations::OrganizationResolver), and defaults to the current organization without it.
  • A blank value is not unset. Other bindings treat a blank value as a no-op. For organization a blank value selects the current organization, so a caller can scope to it without naming one. To drop the scope, omit the binding. This is documented in doc/guides/control-bindings.md.
  • It combines with group in (...) / project in (...), which become the descendantsScope of the organization, even a list of one path. It conflicts with a scalar group = ... / project = ..., which pick a different root.
  • Only sources that support scope lists (analytics mode) take it. Elsewhere it stays in the query and the analyzer reports an unknown filter, as it did before. Standard mode is covered by #205.
  • ScopeRoot::Organization now carries an optional ID. The empty-descendantsScope omission and the organization response root already existed.
  • Not verified against a running backend: cross-organization access for a user who is not a member of the organization (the backend returns null, which the transformer reports as "Organization does not exist or you do not have access to it").

Example Usage

Both examples compile through compile with mode: analytics and metrics: totalCount. The createdAtFrom date depends on the day it is compiled. Not run against gitlab.com, which doesn't have the backend change yet.

In the query text: an exact organization

mode: analytics
query: type = DuoWorkflow and organization = "gid://gitlab/Organizations::Organization/7" and created >= -30d
metrics: totalCount
Generated GraphQL
query GLQL($before: String, $after: String, $limit: Int) {
  organization(id: "gid://gitlab/Organizations::Organization/7") {
    analytics {
      duoWorkflows(createdAtFrom: "2026-10-10 00:00") {
        aggregated(before: $before, after: $after, first: $limit) {
          count
          pageInfo { startCursor endCursor hasNextPage hasPreviousPage }
          nodes { totalCount }
        }
      }
    }
  }
}

As bindings: the current organization, limited to groups

A blank organization binding selects the current organization, and the group list binding becomes its descendantsScope.

mode: analytics
query: type = DuoWorkflow and created >= -30d
metrics: totalCount
bindings:
  - target: { kind: filter, field: organization }
    value: { kind: string, value: "" }
  - target: { kind: filter, field: group }
    value: { kind: list, values: ["gitlab-org", "gitlab-com"] }
Generated GraphQL
query GLQL($before: String, $after: String, $limit: Int) {
  organization {
    analytics {
      duoWorkflows(descendantsScope: {groupFullPaths: ["gitlab-org", "gitlab-com"]}, createdAtFrom: "2026-10-10 00:00") {
        aggregated(before: $before, after: $after, first: $limit) {
          count
          pageInfo { startCursor endCursor hasNextPage hasPreviousPage }
          nodes { totalCount }
        }
      }
    }
  }
}

Passing a GID as the binding value (value: "gid://gitlab/Organizations::Organization/7") adds (id: "…") to the organization root, as in the first example. An invalid value, such as "7", fails the compile.

How to set up and validate locally

  1. cargo test
  2. With the backend MR applied in GDK, compile the examples above and run them as an administrator and as a regular user. Also run a query with a blank organization and no groups.

🤖 Generated with Claude Code

Edited by Alex Pennells

Merge request reports

Loading
Loading