-
Notifications
You must be signed in to change notification settings - Fork 749
Description
Summary
We are experiencing a crash in Apollo iOS SDK when executing a query with a deeply nested input parameter ($filterGroup: FilterGroupOne).
The issue only occurs in Release builds, not in Debug.
There seems to be a mismatch between Apollo’s type expectations and Swift’s compiler optimizations (-O) when dealing with deeply nested recursive input objects.
Workarounds exist, but an official fix or guidance would be highly valuable.
Version
Reproducible in 1.21.0 and 1.23.0
Steps to reproduce the behavior
GraphQL schema:
type Query {
searchTransactions(input: TransactionsSearch): SearchTransactionsResult!
}
input TransactionsSearch {
...
filterGroup: FilterGroupOne
}
input FilterGroupOne {
conditional: String
expressions: [FilterGroupOrExpressionOne!]
}
input FilterGroupOrExpressionOne {
property: String
operator: String
values: [Any!]
conditional: String
expressions: [FilterGroupOrExpressionTwo!]
}
input FilterGroupOrExpressionTwo {
property: String
operator: String
values: [Any!]
conditional: String
expressions: [FilterGroupThree!]
}
input FilterGroupThree {
property: String
operator: String
values: [Any!]!
}
Query:
query SearchTransactions(
...
$filterGroup: FilterGroupOne
) {
searchTransactions(input: {
...
filterGroup: $filterGroup
}) {
transactions {
...
}
}
}
Investigation findings
✅ Works fine in Debug builds (-Onone)
❌ Crashes in Release builds (-O)
✅ Removing $filterGroup parameter from input prevents the crash (but it's needed for our use case)
✅ Forcing ApolloAPI target to use -Onone also prevents the crash (even in Release)
Root cause (our investigation)
Deep recursive input type structure (FilterGroupOne → FilterGroupOrExpressionOne → FilterGroupOrExpressionTwo → FilterGroupThree).
Swift compiler optimization (-O / whole-module) aggressively erases nested optionals and scalars.
Apollo’s generated code expects DataDict, but instead encounters Optional<AnyHashable>.
Crash sequence
- Query with
$filterGroupis sent successfully. - Backend returns valid data.
- Apollo tries to parse the response.
- We try to access
data.searchTransactions var searchTransactions: SearchTransactions { __data["searchTransactions"] }produces the crash - type mismatch (expectedDataDict, gotOptional<AnyHashable>) → fatal error.
Environment
Apollo iOS SDK: 1.21.0 & 1.23.0 (tried to update but the crash still persists)
iOS: 18+
Xcode: 16.4.0
Build configs:
Debug → Works (-Onone)
Release → Crashes (-O)
Logs
ApolloAPI/DataDict.swift:204: Fatal error: SearchTransactions expected DataDict for entity, got Optional<AnyHashable>.Anything else?
No response