Realm + GraphQL relationships

I’m trying to figure out how to create a many-to-many relationship. I have two realm models, User, and Route. Routes can have many users, and Users can have many Routes. In the flow of my application I query Users and Routes separately, in that order. When I populate the User model all of the specified fields are populated, but when I query Routes and populate them with the Users relationship, the User fields that I didn’t include in my Route query are not populated and instead overwrite the User model with null values. I am using Realm.UpdatePolicy.modified in my realm.add call.

I’m sure I could add the missing fields ( for example) to the Routes query, but it seems wasteful to include unnecessary data because there other components of my application that the fields contain large pieces of data (e.g. User.avatar: base64 image). Any suggestions?


query Routes($tenantId: Int!) {
    routes(tenant_id: $tenant_id){
    users {


class User: Object, Mappable  {
    @objc var id: Int = 0
    @objc var email: String = ""
    @objc var name: String = ""
    @objc var password: String = ""


class Route: Object, Mappable {
    @objc dynamic var id: Int = 0
    @objc dynamic var name: String?

    var users = List<User>()

    required convenience init?(map: ObjectMapper.Map) {
        mapping(map: map)

    override static func primaryKey() -> String? {
        return "id"

    func mapping(map: ObjectMapper.Map) {
        id <- map["id"]
        name <- map["name"]
        users <- (map["users"], ListTransform<User>())