Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

MutableSelectionSet child objects missing selections #3437

Open
pixelmatrix opened this issue Sep 5, 2024 · 12 comments
Open

MutableSelectionSet child objects missing selections #3437

pixelmatrix opened this issue Sep 5, 2024 · 12 comments
Labels

Comments

@pixelmatrix
Copy link

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 pixelmatrix added bug Generally incorrect behavior needs investigation labels Sep 5, 2024
@AnthonyMDev
Copy link
Contributor

No your code looks correct, and this should be supported. It seems like it's a bug that the MutableIssueFields.State has an empty __selections. That shouldn't be.

We'll need to see if we can reproduce this.

@AnthonyMDev AnthonyMDev added the planned-next Slated to be included in the next release label Nov 8, 2024
@AnthonyMDev AnthonyMDev removed the planned-next Slated to be included in the next release label Feb 14, 2025
@calvincestari
Copy link
Member

@pixelmatrix can you please share the generated code for MutableIssueFields so I can take a look at the whole thing.

Attached is my attempted reproduction case but I get a populated __selections property in MutableIssueFields.State out of codegen. I didn't try the actual cache update because I have no reason to believe it wouldn't work with __selections being correctly generated. If you can manipulate the reproduction sample so that it generates the same output as you get that would certainly help to debug. Thanks.

issue3437.zip

@pixelmatrix
Copy link
Author

Here's what I have:

MutableIssueFields.graphql.swift.zip

@calvincestari
Copy link
Member

@pixelmatrix I think I've managed to replicate the missing _selections in the WorkflowState fragment with the 1.14.1 version you specified. That behaviour changed from 1.15.0 though and I can no longer replicate it with any version since then.

Have you executed codegen with a version 1.15.0, or greater, to see if it resolves the issue?

@pixelmatrix
Copy link
Author

We're using Apollo 1.17.0 currently, which I assumed includes codegen too, but maybe it's not getting updated automatically in my setup. I'll dig into this more and report back.

@calvincestari
Copy link
Member

If you're executing codegen using the CLI then it is included with apollo-ios as we distribute a codegen binary with each version. However, if you're generating through code and depending on the apollo-ios-codegen package directly then you will need to be updating that dependency too.

@pixelmatrix
Copy link
Author

It's done via the CLI, but for some reason my apollo-ios-codegen is a binary and not a link as the docs suggest. I set it up by running the Xcode Install CLI action a while back. Do I need to be running that action every time I update the SDK as well?

@calvincestari
Copy link
Member

You can check the version of the binary with the command ./apollo-ios-cli --version.

@pixelmatrix
Copy link
Author

Okay, I updated codegen to match our current version of the library and while it did make a ton of changes to the generated models, I still don't see __selections for MutableIssueFields.

Image

@calvincestari
Copy link
Member

Can you share your fragment definitions for this please. Are they defined exactly like you have in the description or is it multiple fragments within each other?

This is what gave me a shape similar to the MutableIssueFields.graphql.swift file you shared last week:

fragment MutableIssueFields on Issue @apollo_client_ios_localCacheMutation {
  ...IssueDetailFields
}

fragment IssueDetailFields on Issue {
  id
  state {
    ...WorkflowStateFields
  }
}

fragment WorkflowStateFields on WorkflowState {
  id
  name
}

@pixelmatrix
Copy link
Author

Yeah, it's actually composed of many fragments. The shape is essentially what you described above, but it goes through one more fragment (partialIssueFields):

fragment issueDetailFields on Issue {
  id
  # etc...
  ...partialIssueFields
}

fragment partialIssueFields on Issue {
  id
  # etc...
  state {
    ...workflowStateFields
  }

fragment workflowStateFields on WorkflowState {
  id
  type
  name
  color
  position
  description
  team {
    id
  }
}

fragment MutableIssueFields on Issue @apollo_client_ios_localCacheMutation {
  ...issueDetailFields
}

@calvincestari
Copy link
Member

Ok, that'll help. I'll have another go at this in the morning.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

3 participants