apollo-ios: GraphQLEnum and test mock crash
Bug report
Creating a test mock with an enum type causes a crash:
// Could not cast value of type 'Swift.AnyHashable' to 'ApolloAPI.GraphQLEnum<MySchemaModule.MyEnum>'
Versions
Please fill in the versions you’re currently using:
apollo-ios
SDK version: 1.0.5- Xcode version: 14.1
- Swift version: 5.7
- Package manager: 5.7
Steps to reproduce
- Create a model with an enum
- Generate test mocks
- Initialize a model by using Model.from(Mock()) method
- Get the enum property from the model
- Crash in the DataDict
Further details
It’s the same crash as #2582
About this issue
- Original URL
- State: open
- Created 2 years ago
- Comments: 15 (13 by maintainers)
Yes, that looks promising. For now we decided to just use the String value of that type and map it to our own enum.
Hi @Gois, I’ve been looking into this issue this week and I don’t have any good resolution to it. I think we’re dealing with an issue in Xcode + SPM dependencies which leads to a kind of Diamond Dependency problem. Is this still an issue for you or have you found a way to resolve it?
I think the key message in the debug output is
I suspect the dependency configuration and this Xcode+SPM issue is causing the schema module to be included twice resulting in two types that are the same but different because they are defined in differently loaded modules, resulting in
When you update to use the
main
branch, which includes some unreleased fixes, the error message becomes clearer asCreating a purely SPM project and configuring the code the same does not result in this error. From what I’ve found online in the Swift Forums it looks like SPM handles this internally by using a dynamic framework and it’s able to do this because it understands the whole dependency chain when building the binaries. I haven’t build a demo of it yet but I suspect an Xcode-only project, without SPM, would also have a working test case. We tried splitting the generated schema module into two packages which didn’t resolve the issue and it still crashed. The only thing that worked for us in the Xcode + SPM project was to use dynamic packages.
We’ll keep digging to see what else we can do to try resolve but I’m at a bit of a dead end right now.
@calvincestari With the sample project it works for me as well but I’ve included another sample project. If you go to the
apollo_crashTests
class you’ll see the testtestMapGraphQLEnumProperty
that one fails for me.The only time it does work for me is when I also include AppThingMapper in the test target instead of accessing it via the testable import.
apollo-crash.zip
Thanks for creating the issue @Gois. We’ll take a closer look and see what can be done.