Skip to content

"cannot select a non-group-by field at group-level" not enforced on relationship fields #4953

Description

@ribiza

Same setup as #4951 (and possibly related).

This query correctly errors:

{
  Book(groupBy: [genre]) {
    genre
    title
  }
}
{
  "errors": [
    {
      "message": "cannot select a non-group-by field at group-level. Field: title"
    }
  ],
  "data": null
}

However, if the non-group-by field is a relationship, the query happily goes through:

{
  Book(groupBy: [genre]) {
    genre
    author { name }
  }
}
{
  "data": {
    "Book": [
      {
        "author": {
          "name": "David Foster Wallace"
        },
        "genre": "Fiction"
      },
      {
        "author": {
          "name": "David Foster Wallace"
        },
        "genre": "Nonfiction"
      },
      {
        "author": {
          "name": "George Orwell"
        },
        "genre": "Memoir"
      }
    ]
  }
}

Version: defradb dev-develop (0e679d98 2026-06-14) built with Go 1.25.9 linux/amd64

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions