apollo-ios: Crash when gets new interface type from server
Version
- ApolloClient 0.14.0
Problem
when I have the following types:
interface Notification {
id: ID!
}
type NotificationArticle implements Notification {
id: ID!
article: Article!
}
type NotificationComment implements Notification {
id: ID!
comment: Comment!
}
and my app use query from this fragment.
fragment NotificationFragment on Notification {
id
... on NotificationArticle {
... ArticleFragment
}
... on NotificationComment{
... CommentFragment
}
}
Later, I add another implementation of Notification
below
type NotificationShare implements Notification {
id: ID!
share: Share!
}
Without updating app with the new schema, my app will crash when I tried to read id
from NotificationShare
. The crash happens in generated API.swift
below
public var id: GraphQLID {
get {
return resultMap["id"]! as! GraphQLID
}
set {
resultMap.updateValue(newValue, forKey: "id")
}
}
It seems that Apollo Core doesn’t read any field from response when __typename
is not exist in fragment’s possible types below (from GraphQLExecutor.swift
)
if let runtimeType = runtimeType, fragment.possibleTypes.contains(runtimeType) {
try collectFields(selections: fragment.selections, forRuntimeType: runtimeType, into: &groupedFields, info: info)
}
Expected Behavior
The app should not crash because id
is a field in Notification
interface.
About this issue
- Original URL
- State: closed
- Created 5 years ago
- Comments: 15 (10 by maintainers)
Commits related to this issue
- test: Added crashing test for #720 — committed to TizianoCoroneo/apollo-ios-mirror by TizianoCoroneo 3 years ago
- fix: removed the possibleTypes check when collecting fields from a fragment on an interface. Closes #720 — committed to TizianoCoroneo/apollo-ios-mirror by TizianoCoroneo 3 years ago
Ah, so it still happens; this is essentially a duplicate of #400 (closed).
@chalermpong Quick answers: No, and this is the ticket in the Swift Codegen Project.