-
Notifications
You must be signed in to change notification settings - Fork 736
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
Incorrect code generation: String instead of Int #23
Comments
According to the GraphQL spec, I would definitely like to add better support for custom scalars, which should give you the opportunity to define your own mapping. But in this case, do you really need |
I hope to add better support for custom scalars soon, but in the meantime there is a temporary I haven't tested it, but something like this should work: typealias Long = Int64
extension Int64: JSONDecodable, JSONEncodable {
public init(jsonValue value: JSONValue) throws {
guard let string = value as? String else {
throw JSONDecodingError.couldNotConvert(value: value, to: String.self)
}
guard let number = Int64(string) else {
throw JSONDecodingError.couldNotConvert(value: value, to: Int64.self)
}
self = number
}
public var jsonValue: JSONValue {
return String(self)
}
} |
Hi @martijnwalraven Error System Info
What I tried Please let me know if I am going wrong somewhere |
@AnandWalvekar: Does the generated API code reference |
@martijnwalraven But still getting the same error |
@AnandWalvekar: That is surprising. Can you check if the generated API code includes a |
@martijnwalraven Is this the solution? |
@AnandWalvekar: Ah, so you're encoding Note that numbers in JavaScript can't represent 64-bit integers however, so unless you're sure the value will never exceed |
@martijnwalraven |
@martijnwalraven suggestion worked fine for me originally, but the latest Apollo code generation script installation changes does not accept the |
@NiltiakSivad same problem here.. :( |
@szantogab I re-read martijnwalraven's post and he does mention it's a "temporary" flag. I'm not sure if anything is mentioned about its removal and future plans in another issue/merge request, I need to investigate more, if I find anything I'll post here. |
@NiltiakSivad I dug a little deeper, and I found that Apollo CLI now expects the parameter this way: You can check out Apollo CLI's other parameters here: Hope this helps you :) |
Hi @martijnwalraven I am using Apollo through Cocoapods and the Apollo cli (not apollo-codegen) as well as the script provided in the installation process of the apollo ios website. This error is in the API.swift file. No typealias is declared in the generated file. Since API.swift should not be modified, any idea on how this can be resolved. EDIT: Solved :) |
I copy the code into Long.swift and then changed the line to read |
Is there a workaround to use "Any" as custom type? I tried the following but it will not work.
Any help is appreciated Thanks! |
Remember to import Apollo and conform "JSONDecodable", not inherit "JSONDecoder"... |
I am getting an error on iOS client. Incorrect code generation: String instead of Array. The resulting API.swift that was generated using apollo-ios
The actual type from the schema file:
If I am try with --passthroughCustomScalars Also I am geting error. The resulting API.swift that was generated with --passthroughCustomScalars
Please let me know if I am going wrong somewhere |
@niraj1991 The type in the schema you posted seems to be a custom scalar called |
@martijnwalraven Thanks for writing to me. |
@niraj1991 You'll have to change |
@martijnwalraven I changed the schema file like below.
But I am Getting below error.
The resulting API.swift that was generated like below.
Also I am creating typealias like below.
Let me know if you need any other details, I would be happy to share you. Please let me know if I am going wrong somewhere. Thanks in advance. |
@niraj1991 It seems you're returning an array from the server and trying to map this to a Swift |
@martijnwalraven if I am writing public typealias Json = Any Then I get the below error. Here is schema file.
Please let me know if I need to change anything. |
@niraj1991 Ah, my mistake, I don't think |
Sript phase: SCRIPT_PATH="${PODS_ROOT}/Apollo/scripts" I do it in: JSONStandardTypeConversions
} but run API.Swift get an error: Use of unresolved identifier 'Long' who can tell me what wrong with that? |
@JakeTorres Can you please take your question to our Spectrum chat? it's not quite related to this issue. Thank you! |
git-subtree-dir: apollo-ios-codegen git-subtree-mainline: 97618d5 git-subtree-split: 48b6461c7a4868c960fd82d4935327361b4350f4
Steps to reproduce:
The resulting
API.swift
that was generated usingapollo-ios
version 0.4 andapollo-codegen
version 0.9 contains:public let centAmount: String
(MoneyDetails
struct property). The actual type from the schema:The text was updated successfully, but these errors were encountered: