apollo-ios icon indicating copy to clipboard operation
apollo-ios copied to clipboard

MutableSelectionSet child objects missing selections

Open pixelmatrix opened this issue 5 months ago • 1 comments

Summary

I have a mutable fragment that has relationships to other objects, like this:

fragment MutableIssueFields on Issue @apollo_client_ios_localCacheMutation {
  id
  state {
    id
    name
  }
}

Codegen ends up creating MutableIssueFields and MutableIssueFields.State. The parent object MutableIssueFields has a __selections property as you'd expect, but MutableIssueFields.State does not.

I'm trying to change the value from one "state" to another using a local cache mutation. However, when I try to load the MutableIssueFields.State object from the cache, I get an empty object because the __selections field is empty.

I'm calling it like this:

store.withinReadWriteTransaction { tx in
  let newState = try tx.readObject(ofType: MutableIssueFields.State.self, withKey: "State:\(id)")
  try tx.updateObject(ofType: MutableIssueFields.self) { obj in
    obj.state = newState
  }
}

Is this something that should be supported? If not, is there a preferred way to update this relationship to another existing object in the cache?

Version

1.14.1

Steps to reproduce the behavior

  1. Create a fragment marked with @apollo_client_ios_localCacheMutation, that references some child object
  2. Populate cache with data that will fulfill the fragment
  3. Use a read write transaction to try to fetch the child object using readObject
  4. Observe the child object is returned with empty data

Logs

No response

Anything else?

No response

pixelmatrix avatar Sep 05 '24 22:09 pixelmatrix