Comments (11)
@VigneshJeyarajG I was able to solve this in a couple steps:
- Add
--passthroughCustomScalars
to the build phase like below (see last line):
APOLLO_FRAMEWORK_PATH="$(eval find $FRAMEWORK_SEARCH_PATHS -name "Apollo.framework" -maxdepth 1)"
if [ -z "$APOLLO_FRAMEWORK_PATH" ]; then
echo "error: Couldn't find Apollo.framework in FRAMEWORK_SEARCH_PATHS; make sure to add the framework to your project."
exit 1
fi
cd "${SRCROOT}/${TARGET_NAME}"
$APOLLO_FRAMEWORK_PATH/check-and-run-apollo-cli.sh codegen:generate --queries="$(find . -name '*.graphql')" --passthroughCustomScalars --schema=schema.json API.swift
- Add the
typealias
like @martijnwalraven mentioned a while back, like:
public typealias CurrentMissionChallenge = [String : Any?]
extension Dictionary: JSONDecodable {
/// Custom `init` extension so Apollo can decode custom scalar type `CurrentMissionChallenge `
public init(jsonValue value: JSONValue) throws {
guard let dictionary = value as? Dictionary else {
throw JSONDecodingError.couldNotConvert(value: value, to: Dictionary.self)
}
self = dictionary
}
}
from apollo-ios.
Unfortunately, we don't have real support for custom scalars yet. But I think we should be able to get something working using the --passthrough-custom-scalars
workaround.
I haven't tested it, but something like this might be a good starting point:
typealias JSON = [String : Any?]
extension Dictionary: JSONDecodable {
public init(jsonValue value: JSONValue) throws {
guard let dictionary = value as? Dictionary else {
throw JSONDecodingError.couldNotConvert(value: value, to: Dictionary.self)
}
self = dictionary
}
}
from apollo-ios.
I am using the same solution but I am trying to use my custom object class instade of Extenstion
public class Location : JSONDecoder {
var lat : String
var lng : String
public init(jsonValue value: JSONValue) throws {
guard let locationDic = value as? NSDictionary else {
throw JSONDecodingError.couldNotConvert(value: value, to: String.self)
}
guard let lat = locationDic.value(forKey: "lat") else {
throw JSONDecodingError.couldNotConvert(value: value, to: Int64.self)
}
guard let lng = locationDic.value(forKey: "lng") else {
throw JSONDecodingError.couldNotConvert(value: value, to: Int64.self)
}
self.lat = (lat as? String)!
self.lng = (lng as? String)!
}}
but I am getting this error in API.swift file
Cannot convert value of type 'Json.Type' (aka 'Location.Type') to expected argument type 'JSONDecodable.Type'
public struct AllPointOfInterest: GraphQLSelectionSet {
public static let possibleTypes = ["PointOfInterest"]
public static let selections: [GraphQLSelection] = [
GraphQLField("__typename", type: .nonNull(.scalar(String.self))),
GraphQLField("name", type: .nonNull(.scalar(String.self))),
GraphQLField("type", type: .nonNull(.list(.nonNull(.scalar(PointOfInterestType.self))))),
GraphQLField("location", type: .nonNull(.scalar(Json.self))), // error in this line
]
Any thing is missing ?
from apollo-ios.
Any update on this? I have a field which is the type of scalar JSON. Apollo throws the error
Optional(Apollo.GraphQLResultError(path:` ["stage", "0", "parent", "0", "venue"], underlying: Apollo.JSONDecodingError.couldNotConvert(value: {
city = Monza;
coordinates = "45.615899,9.279499";
country = Italia;
"country_code" = ITA;
"curves_left" = 4;
"curves_right" = 7;
debut = 1950;
id = "sr:venue:1024";
laps = 53;
length = 5793;
name = "Autodromo Nazionale Monza";
"url_official" = "http://www.monzanet.it/";
}, to: Swift.String)))
from apollo-ios.
I got same Error. But i know the reason of error. Our Schema.json and mutation or query generate the API.swift. Schema.json have a JSON response. This response is treated as String. So Api.swift create [String] type. Please check your API.swift. your response is [JSON] type. But your API.swift file automatically generate the [String] for your [JSON]. During fetching the data from endpoint response [JSON]. So [JSON] couldNotConvert String error will be Occurred.
Solution is during create a Backend using MUTATION RESPONSE instead of [JSON] type Response.
from apollo-ios.
This is sample response for [JSON].
https://i.stack.imgur.com/zxXiz.png
My sample response is CurrentMissionChallenge is [JSON] type
from apollo-ios.
Closing this out with @rickycpadilla's solution as the present recommended one.
from apollo-ios.
Hey In Swift 5...there is no JSONDecodable/JSONDecodingError. Is there anything you guys are using for this fix.
from apollo-ios.
@aroraenterprise This is a custom error, not anything thrown by the system. Can you open a new issue with details of the problem you're running into, please?
from apollo-ios.
Cannot find 'JSON' in scope
from apollo-ios.
I'm using Apollo 1.9.3
So there are no run script needed to be set in build phase
I'm not able to set passThroughCustomScalars in run script as it is not needed while using local package.
Can anyone please help me to solve
ApolloAPI.JSONDecodingError.couldNotConvert(value: AnyHashable
to: Swift.String)
public typealias JSON = String
from apollo-ios.
Related Issues (20)
- Circular reference Build Error HOT 6
- Invalid redeclaration of synthesized property '_id' HOT 7
- Split/Hybrid Caching between InMemory and SQL review and thoughts HOT 2
- ID as a custom scalar HOT 6
- Bug: Cache writes of incremental responses uses incorrect parent key (custom cache keys)
- Incorrect PR link in release notes for version 1.11.0 HOT 2
- apollo-ios-cli deprecated --schema-name HOT 2
- Confused about cache behavior HOT 2
- CLI fails to run with 1.12.0 HOT 4
- Response value getting nil HOT 2
- Version mismatch between package and CLI HOT 3
- Pagination: Pager does not provide updates during a refresh HOT 6
- Slow compilation speed when migrating from 0.x to 1.12.2 HOT 4
- clearCache for SQLiteNormalizedCache doesn't clear the sqlite file HOT 3
- Crash on com.apollographql.websocket on _inputStreamCallbackFunc HOT 2
- Naming conflict with Foundation in Xcode 16 HOT 2
- Xcode 15 Beta "Expression" name collision HOT 4
- ApolloSQLite doesn't compile on Xcode 16 due to `Expression` symbol clash with new `Foundation.Expression` HOT 3
- Request to clear derived data when switch from build for test to build for run HOT 5
- Adding in mocks is causing our tests to fail. HOT 3
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from apollo-ios.