-
Notifications
You must be signed in to change notification settings - Fork 745
Description
Summary
Bug Report
Environment
- Apollo iOS Version: 1.23.0
- Xcode Version: 16.3
- Swift Version: 6.1
Description
After upgrading from Apollo iOS 1.(16...22).0 to 1.23.0, the generated test mocks produce compilation errors due to type naming inconsistencies.
Analysis
This issue appears to be a regression introduced by a new feature in version 1.23.0:
Added requireNonOptionalMockFields flag to ApolloCodegenConfiguration.OutputOptions. (#669): Added new flag to codegen output options to allow having non-optional fields in the test mocks if desired. Thank you to @dwroth for the contribution.
While this feature aims to improve mock generation, it seems to have introduced an unintended side
effect in the type naming logic.
What changed:
- Version 1.22.0 and earlier: Mock fields used optional types with nil defaults: Swift
Mock<Type>? = nil
- Version 1.23.0: Mock fields now use non-optional types with constructor defaults: Swift
Mock<Type> = Mock<type>()
The issue:
The new implementation has inconsistent type naming where:
- The parameter declaration uses one naming convention: Swift
Mock<Acknowledge_billboard_threadPayload>
- The default constructor uses a different convention: Swift
Mock<acknowledge_billboard_threadPayload>()
It appears that the mock object creation should use the same type as the parameter declaration (SwiftMock<Acknowledge_billboard_threadPayload>()
instead of SwiftMock<acknowledge_billboard_threadPayload>()
), but the code generation is incorrectly applying different naming strategies to the parameter type vs. the constructor type.
Since the snake_case version doesn't exist, the compiler throws a "Cannot find type in scope"
error.
This appears to be an oversight in the implementation rather than an intentional breaking change, as the same GraphQL schema that worked perfectly in 1.22.0 now fails to compile in 1.23.0 with default configurations.
Through systematic testing, we confirmed:
- 1.16.0 to 1.22.0: All work correctly
- 1.23.0: Introduces this bug
Version
1.23.0
Steps to reproduce the behavior
- Upgrade Apollo iOS from 1.(16...22).0 to 1.23.0
- Generate GraphQL code using apollo-ios-cli generate
- Try to build the project
Expected Behavior
The generated mock code should compile without errors, as it did in versions 1.(16...22).0 .
Actual Behavior
Compilation fails with errors like:
Cannot find type 'acknowledge_billboard_threadPayload' in scope
Code Examples
Generated in 1.(16...22).0 (Working):
public extension Mock where O == Mutation {
convenience init(
acknowledgeBillboardThread: Mock<Acknowledge_billboard_threadPayload>? = nil,
// ...
)
}
Generated in 1.23.0 (Broken):
public extension Mock where O == Mutation {
convenience init(
acknowledgeBillboardThread: Mock<Acknowledge_billboard_threadPayload> =
Mock<acknowledge_billboard_threadPayload>(),
// ...
)
}
Logs
Anything else?
No response