[iOS] Cannot assign to property: 'x' is a get-only property

Since migrating to the new codegen I can’t seem to change the values in my array.

In the old version I could do
array[index].progress = 5
but in the new version it gives me this error.

Looking into the generated Swift code and I can see the old codegen had getters and setters, but the new one looks like they’re all computed vars. Is there something I’m missing?

Hi @PaulDoesDev :wave:

The gist of what you’re experiencing is that the 0.x generated models were mutable whereas the new 1.x generated models are immutable. This is by design and representative that the generated models are only used in and initialized by GraphQL responses.

If you were mutating the models to do some cache manipulation there is another API to do the same. If not, I’d love to learn more about your use case.

I recommend you read through the 1.0 migration guide, which guides you through moving from 0.x to 1.x.

Hi @calvincestari,

Thanks for the prompt response.

Essentially, I’m building an anime/manga tracking app using AniList’s API.

This particular use case depends on them being mutable, since I:

  1. Fetch ‘MediaEntry’ data from the API
  2. Present this in my app
  3. The user taps + or - on a stepper to add or remove an episode
  4. I update the ‘progress’ value of that MediaEntry. This then updates my view.
  5. I send a request using the id of that MediaEntry and the new count to the server

Is it expected we create our own models and hydrate them using the data from the generated models now?

  1. I update the ‘progress’ value of that MediaEntry. This then updates my view.

Is progress a value that you fetch from the server in your query?

  • If it is then a cache mutation to affect the underlying data in the cache is advised rather than just mutating the query response. Part of the design change to make response types immutable is to remove the perception that updating a response value would somehow have it sent back to the server or into the cache.
  • If it’s a local client-side only property (i.e.: not part of the query response) then yes it sounds like you will need to wrap the response type in your own type to augment it with progress. One day we will support client-side properties that could behave this way automatically.