How to filter a nested relationship with Vapor Fluent

I have a relationship that is structured like:

Book {
   id: UUID
   author: Author
}

Author {
   id: UUID
   genre: Genre
}

Genre {
   id: UUID
   name: String
}

I want to be able to query for books that have authors that have a specialize in a specific genre.

I want to do something like:

let query = Book.query(on: db)
    .with(\.$author) { author in
        author.with(\Author.$genre)
    }
    .filter(\Book.$author.$genre.$name, .equal, "Mystery")

But I am getting issues with accessing the genre field from the author.

If I change it to:

.filter(\Book.author.$genre.$name, .equal, "Mystery")

I get an error where it says author wasn't eager loaded.

If you want to do this with Fluent you need to use a join instead to bridge the tables. The other option is to do the filtering in Swift but that isn't as efficient

Can you provide an example of how to do this using joins, I can seem to figure it out.

Author {
id: UUID
genre: Genre
name: String
books: [Book]
}

Book {
id: UUID
author: Author
published: Date
}

How would one query for all authors with name = 'XXX' AND all books published after 'YYYY' ?

I can figure out how you filter both authors and books.

What have you tried?

The docs for joins are here Vapor: Fluent → Query