-
Notifications
You must be signed in to change notification settings - Fork 730
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
Mock object with [String: AnyHashable] data doesn't compile #3264
Comments
This issue is also related to this problem #3179 |
I found out it needs to define every nested dictionary as [String: AnyHashable] so that the data can be [String: AnyHashable] let frind: [String: AnyHashable] = [
"__typename": "Human",
"id": "456",
"name": "Padme Amidala"
]
let hero: [String: AnyHashable] = [
"__typename": "Human",
"id": "123",
"name": "Obi-wan Kenobi",
"friends": [
frind
]
]
let query: [String: AnyHashable] = [
"__typename": "Query",
"hero": hero
]
let data: [String: AnyHashable] = [
"data": query
] |
This is a Swift language/compiler issue and not inherent to let data: [String: AnyHashable] = [
"data": [
"__typename": "Query",
"hero": [
"__typename": "Human",
"id": "123",
"name": "Obi-wan Kenobi",
"friends": [
[
"__typename": "Human",
"id": "456",
"name": "Padme Amidala"
],
[
"__typename": "Droid",
"id": "789",
"name": "C-3PO"
]
]
] as [String: AnyHashable]
] as [String: AnyHashable]
] Simply adding those |
We've merged in PR #102 to fix this issue. Will be pushed out in the next release! |
Summary
In the official site, the mock object can be initialized with DataDict type which receive data with type [String: AnyHashable], but it will throw compile error
Cannot convert value of type '[String : Any]' to expected dictionary value type 'String'
Version
1.6.1
Steps to reproduce the behavior
It is not related to specific version of Apollo, but maybe related to Swift language, I am testing with Swift 5.9, the snippet from documentation site can not compile correctly
the error says
Cannot convert value of type '[String : Any]' to expected dictionary value type 'String'
If you change the type from
[String: AnyHashable]
to[String: Any]
, it won't throw any issue, but the DataDict can not receive[String: Any]
Logs
No response
Anything else?
No response
The text was updated successfully, but these errors were encountered: