-
Notifications
You must be signed in to change notification settings - Fork 737
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
Using a custom Date scalar #1435
Comments
How to use/implement Date type custom scalar in iOS? I'm working with GraphQL. I have successfully implement Query and Mutation in iOS app.
Code for Define Date Scalars public typealias DateTime = Date
extension DateTime: 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 date = ISO8601DateFormatter().date(from: string) else {
throw JSONDecodingError.couldNotConvert(value: value, to: Date.self)
}
self = date
}
public var jsonValue: JSONValue {
return ISO8601DateFormatter().string(from: self)
}
} I have reviewed schema JSON have a Date variable but API.swift still string type. mutation AddPeriod($uid:ID!, $start_time : Date!, $flow: PeriodFlowInput){
addPeriod(uid:$uid, start_time : $start_time, flow: $flow){
id
start_time
end_time
flow {
value
flow_time
}
}
} How can I pass date in GraphQL mutation. Please help me. Thanks in advance |
Hi @Renish-Development - I updated your comment to add some formatting. It looks like your type is called typealias Date = Swift.Date And then have your extension be on |
1. Swift Date is Not available. I'm using Xcode 12. Please look at the attached screen shot. 2. I'm also facing issue with execute --passthrough-custom-scalars. Please let me know what I missed for custom scalars |
Argh, I meant And |
--passthrough-custom-scalars
to apollo-codegen
to avoid generating a typealias
to String
for custom scalars. You can then add your own alias and conversion code, see [here](https://github.com/apollographql/apollo-ios/issues/23#issuecomment-261697349) for an example.
@designatednerd , Its' not working. Please can I do any mistake or issue due to the updated version of Xcode 12. I'm using Xcode 12. Please check with your side and let me know it's work or not. Happy top share more information |
I did notice that the param is |
Hi @Renish-Development is there anything more I can help with here or can we close this issue out? |
You're far from the only person who's asked a ton of questions about this so I've added a page to our example playground to try and clarify this. Please see #1474 for further details |
@designatednerd , Please add verify and step by step code or make tutorial as per latest version of GIT repo. Also I have not found proper documentation regarding custom scalar, pass token in API call, generate schema file with auth token and so on. I'm happy to help you anyway and if you can guide I will write tutorial for the same. Looking forward.... |
@GlobeSyncTechnologies Please see the PR I linked for an example of using a custom scalar. Please check out our full tutorial for full setup instructions. |
Sorry for comment onto closed issue, but where can I set |
Hi, normally it's better to open a new discussion to ask a new question. However since this is somewhat related, i'll answer it here: Please check out the initializer for |
@cerupcat @jzhw0130: You should be able to pass
--passthrough-custom-scalars
toapollo-codegen
to avoid generating atypealias
toString
for custom scalars. You can then add your own alias and conversion code, see here for an example.Originally posted by @martijnwalraven in #94 (comment)
The text was updated successfully, but these errors were encountered: