Add graphql base types

This commit is contained in:
Paul Chavard 2018-11-20 22:59:13 +01:00
parent d2fdaacb5d
commit 9bb52dfb8c
8 changed files with 47 additions and 0 deletions

View file

@ -0,0 +1,4 @@
module Mutations
class BaseMutation < GraphQL::Schema::Mutation
end
end

View file

@ -0,0 +1,4 @@
module Types
class BaseEnum < GraphQL::Schema::Enum
end
end

View file

@ -0,0 +1,4 @@
module Types
class BaseInputObject < GraphQL::Schema::InputObject
end
end

View file

@ -0,0 +1,5 @@
module Types
module BaseInterface
include GraphQL::Schema::Interface
end
end

View file

@ -0,0 +1,4 @@
module Types
class BaseObject < GraphQL::Schema::Object
end
end

View file

@ -0,0 +1,4 @@
module Types
class BaseScalar < GraphQL::Schema::Scalar
end
end

View file

@ -0,0 +1,4 @@
module Types
class BaseUnion < GraphQL::Schema::Union
end
end

18
app/graphql/types/url.rb Normal file
View file

@ -0,0 +1,18 @@
module Types
class 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
end