Skip to content

Crash in Apollo iOS SDK (1.21.0 & 1.23.0) when using deeply nested input objects in Release builds #3582

@robertcnst

Description

@robertcnst

Summary

Image

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

  1. Query with $filterGroup is sent successfully.
  2. Backend returns valid data.
  3. Apollo tries to parse the response.
  4. We try to access data.searchTransactions
  5. var searchTransactions: SearchTransactions { __data["searchTransactions"] } produces the crash - type mismatch (expected DataDict, got Optional<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

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions