Kql: select id of parent, if parent exists, otherwise fallback

I can’t wrap my head around this. How to select a field with KQL on an object that might not exist?

The basic query:

"pages": {
  "query": "site.children.sortBy('date', 'desc')",
  "select": {
    "parent": "page.parent.id",
  }
}

Now the page might not have a parent, the query will fail, as it tries to select id on a non-existing page.

Is there a way to stack or() functions, so I can make this fallback to null instead of a request error?

{
  "status": "error",
  "message": "Access to method/property \"id\" on null",
  "code": 400,
  "exception": "Kirby\\Exception\\BadMethodCallException",
  "key": "error.invalidMethod",
  "file": "/kirby/src/Query/Segment.php",
  "line": 51,
  "details": [],
  "route": "query"
}

Background: I query all pages, files and fields via the API to statically generate the frontend with a static site generator. I also need hierarchical connections between pages for things like navigation and breadcrumbs.

Nevermind. A coffee influx later:

"pages": {
  "query": "site.children.sortBy('date', 'desc')",
  "select": {
    "parent": {
      "query": "page.parent",
      "select": {
        "id": true
      }
    }
  }
}