Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Crash in Mock when mocking a type with property that is an array of optional values #2593

Closed
bdunay3 opened this issue Oct 19, 2022 · 3 comments

Comments

@bdunay3
Copy link

bdunay3 commented Oct 19, 2022

Bug report

We have a query in our graph that can return an array of optional values. When we generate the Swift code from this query we get a property like this:

var blocks: [Block?] { __data["blocks"] }

In our unit tests when we use the Mock type to mock the graph data and we put a nil in the that array we get a crash in SelectionSet.

Versions

Please fill in the versions you're currently using:

  • apollo-ios SDK version: 1.0.0
  • Xcode version: 14.0.1
  • Swift version: 5.7
  • Package manager: 5.7

Steps to reproduce

Here's a snippet of our unit test code that reproduces the issue:

We define the following mock instance:

let mockCategoryExperience = Mock<BlockContainer>(blocks: [
    mockBlockDataa,
    nil
])

Then when we run the unit test we get a crash in this code from TestMock.swift in the ApolloTestSupport library:

// MARK: - Selection Set Conversion

public extension SelectionSet {
  static func from(
    _ mock: any AnyMock,
    withVariables variables: GraphQLOperation.Variables? = nil
  ) -> Self {
    Self.init(data: DataDict(mock._jsonObject, variables: variables))
  }
}
@calvincestari
Copy link
Member

Hi @bdunay3, I think your issue is resolved by #2591. It hasn't gone out in a release yet, it will be included in 1.0.2. So if you target main for your dependency you should get the fix in the interim.

@AnthonyMDev
Copy link
Contributor

Please let us know if this is not fixed in main ASAP! I've got a unit test that verifies that this should work right now, but if we're missing something, we'd love to know before the patch release goes out.

@bdunay3
Copy link
Author

bdunay3 commented Oct 23, 2022

Apologies I couldn't try this before you all shipped the update. But I did just try this with the official 1.0.2 release and it's not crashing any more. Thank you for the quick turn around!!

@bdunay3 bdunay3 closed this as completed Oct 23, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants