[Feature] Support Swift 6.2 Default Actor Isolation - MainActor
Question
Just wanted to confirm that that generated code from Apollo iOS 2.0 is not expected to support "Default Actor Isolation: MainActor" ?
I just created a brand new project and the generated code was failing with the following compile errors:
SignInMutation.graphql.swift:31:12 Main actor-isolated conformance of 'MySchema.SignInMutation.Data' to 'Hashable' cannot satisfy conformance requirement for a 'Sendable' type parameter 'Self'
SignInMutation.graphql.swift:31:12 Main actor-isolated conformance of 'MySchema.SignInMutation.Data' to 'Hashable' cannot satisfy conformance requirement for a 'Sendable' type parameter 'Self'
SignInMutation.graphql.swift:31:12 Type 'MySchema.SignInMutation.Data' does not conform to protocol 'SelectionSet'
SignInMutation.graphql.swift:31:12 Type 'MySchema.SignInMutation.Data' does not conform to protocol 'SelectionSetEntityValue'
SignInMutation.graphql.swift:52:14 Main actor-isolated conformance of 'MySchema.SignInMutation.Data.SignInWithPassword' to 'Hashable' cannot satisfy conformance requirement for a 'Sendable' type parameter 'Self'
SignInMutation.graphql.swift:52:14 Main actor-isolated conformance of 'MySchema.SignInMutation.Data.SignInWithPassword' to 'Hashable' cannot satisfy conformance requirement for a 'Sendable' type parameter 'Self'
SignInMutation.graphql.swift:52:14 Type 'MySchema.SignInMutation.Data.SignInWithPassword' does not conform to protocol 'SelectionSet'
SignInMutation.graphql.swift:52:14 Type 'MySchema.SignInMutation.Data.SignInWithPassword' does not conform to protocol 'SelectionSetEntityValue'
Changing "Default Actor Isolation" from MainActor to nonisolated fixed the issue. I couldn't find any reference to this in any of the docs. Maybe this is well understood by iOS devs but I have not done any iOS development for several years so I'm a bit out of the loop.
Hi @col. Apollo iOS 2.0 was designed to target Swift 6.1. We haven't implemented support for the Default Actor Isolation: MainActor option yet. While 2.0 should work with Swift 6.2 just fine, you will want to use nonisolated for this option for now.
Implementing this is on our radar, we just have a few other things we're trying to get added to 2.0 first! I'll leave this issue open to track the work that needs to be done here.
Thanks for confirming @AnthonyMDev. I’m using it with nonisolated now and loving the new 2.0 release. This feels like such an improvement over v1. Thanks for all the great work!
Note: We don't need to make the Apollo targets use Main Actor for default actor isolation, our libraries should still stay using nonisolated. We should only be exploring making the generated models compatible with this new option.