Created
May 6, 2019 18:29
-
-
Save valikos/9eb4be93ccd928b407453bf269a78c2e to your computer and use it in GitHub Desktop.
gql-6
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class Types::Url < Types::BaseScalar | |
description "A valid URL, transported as a string" | |
def self.coerce_input(input_value, context) | |
url = URI.parse(input_value) | |
if url.is_a?(URI::HTTP) || url.is_a?(URI::HTTPS) | |
url | |
else | |
raise GraphQL::CoercionError, "#{input_value.inspect} is not a valid URL" | |
end | |
end | |
def self.coerce_result(ruby_value, context) | |
ruby_value.to_s | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment