-
Notifications
You must be signed in to change notification settings - Fork 18
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
Passthrough Custom Scalars? #40
Comments
Hi! Yes it is supported to some extent. It's not been tested very heavily though. If you want to use a custom type for it there's a GraphQLScalar protocol you can use. But make sure to make the Here's for example how it works with extension URL: GraphQLScalar {
typealias Scalar = String
static let placeholder: URL = URL(string: "https://graphaello.dev/assets/logo.png")!
private struct URLScalarDecodingError: Error {
let string: String
}
init(from string: Scalar) throws {
guard let url = URL(string: string) else {
throw URLScalarDecodingError(string: string)
}
self = url
}
} And in your structs you will have to specify that it's the type that you want: struct MyStuct {
@GraphQL(MyAPI.path.to.url)
var url: URL
} If you try this out, please let me know how it goes. I would love to improve this feature. I have considered having some config files (yaml or json) to make this work better, but it felt like a weird addition that didn't fit in with the rest. It would make it easier to enforce that all urls are treated equally, though |
Alright. So this Scalar is definitely not encoded as a string. Not to worry. I'll come up with something for it ;) I think the best way to configure this is to include the scalar mappings in the API.json and use the CLI to configure it. Something like:
|
Sounds good :) |
Is it possible to use custom scalars for Graphql?
Is it activated in the project
The text was updated successfully, but these errors were encountered: