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")