apollographql / apollo-ios

📱  A strongly-typed, caching GraphQL client for iOS, written in Swift.
https://www.apollographql.com/docs/ios/
MIT License
3.89k stars 730 forks source link

Codegen requires all objects to implement equatable. #442

Closed jimisaacs closed 2 years ago

jimisaacs commented 5 years ago

I'm pretty sure it's because of public typealias ResultMap = [String : Any?]. Because Any? is not Equatable. If it was [String : AnyHashable?], this wouldn't be a problem. In reality, the objects should already be generated with equatable.

I'm generally concerned about the code quality codegen provides and would greatly appreciate an alternative solution.

jimisaacs commented 5 years ago

An alternative solution would be, only use codegen for the queries, not the responses.

koenpunt commented 5 years ago

In reality, the objects should already be generated with equatable.

I definitely agree, would make usage with IGListKit a lot more convenient.

SirensOfTitan commented 5 years ago

I definitely agree, would make usage with IGListKit a lot more convenient.

We make very heavy usage of IGListKit in our app, so had to have this. I ended up using a little Sourcery template to codegen Equatable for Apollo's entire generated API. See below: https://gist.github.com/SirensOfTitan/5f9feb2dca067e4b4152609e1851c028

... I am not sure if my work is 100% correct, but it works in practice pretty well. I'd be willing to setup a PR for the official codegen client once the Meteor folks hire their fulltime iOS engineer.

designatednerd commented 5 years ago

@SirensOfTitan Hi I'm the fulltime iOS engineer who was (finally) hired, let me know if I can be of help here!

jimisaacs commented 5 years ago

Hello @designatednerd! I haven't looked at what is being generated in a while, but if it's still the same, then I'd assume what I put in the issue description is still relevant. There's some higher level difficulties I have had with the codegen, but those would be off topic here, as this issue is pretty explicit.

designatednerd commented 5 years ago

We are going to have a few changes landing soonish, but I'll put this in to take a look at when we're dealing with that.

kimdv commented 5 years ago

I think we also should consider autogenerate the Hashable interface as the new Diffable in iOS 13 requires that 🚀

designatednerd commented 5 years ago

Yes Hashable is definitely happening in addition to equatable - I've been doing that in some behind the scenes stuff prepping for updated codegen

kevinmbeaulieu commented 5 years ago

@designatednerd Is this still coming or do we need someone to pick up the work for this?

designatednerd commented 5 years ago

Yes! Please follow along with the Codegen Project to see where things are at - working on that at the same time as a few other things though.

ts95 commented 4 years ago

What's the status on this? 🙂

designatednerd commented 4 years ago

Coming along! Codegen itself got blocked for a bit so I shifted to working on the networking stack, but once that's out I'll be back on Codegen and auto-Equatable conformance is definitely a big goal.

ts95 commented 4 years ago

Awesome 🙌 With auto Equatable and Hashable conformance it would be a lot easier to implement diffing for table views and collection views

designatednerd commented 4 years ago

Yes, aboslutely!

alizx commented 4 years ago

looking forward to it

pavm035 commented 3 years ago

Any updates when this will be released?

alizx commented 3 years ago

This simple thing basically makes working with apollo codegen pain in the neck!

calvincestari commented 2 years ago

Hi 👋🏻 - this issue should be resolved in 1.0. 1.0 is currently in alpha releases with a full 1.0 release in H2 2022. Please take a look at the latest alpha and let us know if this is still an issue for you.

jimisaacs commented 2 years ago

Happy to see this issue resolved 👍