Answer:
query getCategoriesWithPosts {
categories(filters: {posts: {id: {null: false}}}) {
data {
id
attributes {
title
slug
posts(sort: "publishedAt:desc") {
data {
id
attributes {
title
}
}
}
}
}
}
}