EntityPropertyQuery with property from related entity

Hi, I am working on creating a EntityPropertyQuery for my App entity. I want the user to be able to use Shortcuts to search by a property in a related entity, but I'm struggling with how the syntax for that looks.

I know the documentation for 'EntityPropertyQuery' suggests that this should be possible with a different initializer for the 'QueryProperty' that takes in a 'entityProvider' but I can't figure out how it works.

For e.g. my CJPersonAppEntity has 'emails', which is of type CJEmailAppEntity, which has a property 'emailAddress'. I want the user to be able to find the 'person' by looking up an email address.

When I try to provide this as a Property to filter by, inside CJPersonAppEntityQuery, but I get a syntax error:

static var properties = QueryProperties {
Property(\CJPersonEmailAppEntity.$emailAddress, entityProvider: { person in
                person.emails  // error
            }) {
                EqualToComparator { NSPredicate(format: "emailAddress == %@", $0) }
                ContainsComparator { NSPredicate(format: "emailAddress CONTAINS %@", $0) }
            }
}

The error says "Cannot convert value of type '[CJPersonEmailAppEntity]' to closure result type 'CJPersonEmailAppEntity'"

So it's not expecting an array, but an individual email item. But how do I provide that without running the predicate query that's specified in the closure?

So I tried something like this , just returning something without worrying about correctness:

            Property(\CJPersonEmailAppEntity.$emailAddress, entityProvider: { person in
                person.emails.first ?? CJPersonEmailAppEntity() // satisfy compiler
            }) {
                EqualToComparator { NSPredicate(format: "emailAddress == %@", $0) }
                ContainsComparator { NSPredicate(format: "emailAddress CONTAINS %@", $0) }
            }

and it built the app, but failed on another the step 'Extracting app intents metadata':

error: Entity CJPersonAppEntity does not contain a property named emailAddress. Ensure that the property is wrapped with an @Property property wrapper

So I'm not sure what the correct syntax for handling this case is, and I can't find any other examples of how it's done. Would love some feedback for this.

EntityPropertyQuery with property from related entity
 
 
Q