Skip to content

Instantly share code, notes, and snippets.

@valikos
Created May 6, 2019 18:29
Show Gist options
  • Save valikos/9eb4be93ccd928b407453bf269a78c2e to your computer and use it in GitHub Desktop.
Save valikos/9eb4be93ccd928b407453bf269a78c2e to your computer and use it in GitHub Desktop.
gql-6
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