Apollo iOS: GraphQLQuery.Data created from mock object crashes when attempting to access data's properties

I’m using Apollo 1.3.x-generated mocks for the first time, and I’m stuck when trying to use a GraphQLQuery.Data object that was created from a mock object.

I’m using a query that returns a single Bool, and creating the mock object and query data like this:

let deliveryFailed = Mock<MessageDelivery>(success: false)
let deliveryData =  ConfirmMessageDeliveryQuery.Data.from(deliveryFailed)

When I then try to use this data object (let success = deliveryData.messageData.success) in my tests, the test crashes with

2023-08-06 00:20:43.547962-0400 ... ApolloAPI/DataDict.swift:149: Fatal error: MessageDelivery expected DataDict for entity, got Optional<AnyHashable>.

As far as I can tell, this is just like the example given at Test mocks - Apollo GraphQL Docs

let mock = Mock<Query>(...)
let model = HeroAndFriendsQuery.Data.from(mock)
XCTAssertEqual(model.hero.friends[1].name, "C-3PO")

Hi @jrtibbetts - I know this is a very late reply to your question but I recommend trying the latest release to check if your issue is resolved. Each of the 1.3.x releases fixed a test mock related bug.

I’ve got the same issue on the latest 1.7.1, is there a workaround for this?
If i try to evaluate the guard with the debugger, where that check is executed, it’s correcty casted to DataDict, however at runtime it always falls in the fatalError.
I tried with Mocks, but also to init the Query.Data from a Dictionary. Same result.

Hi @Gabriele_Pavanello, can you please share the code that’s failing for you. Thanks.