Sha256: ce0752a78c826ad5f410f3d7147e5b4d1f6a7e928b1d6728203c844c0ed8e2c0
Contents?: true
Size: 1.66 KB
Versions: 1
Compression:
Stored size: 1.66 KB
Contents
require "graphql" module Kanji class Graph class CoerceType def self.call(type) if array_type?(type) member_type = get_member_type(type) graphql_type = get_graphql_type(member_type) graphql_type.to_list_type else get_graphql_type(type) end end private TYPE_MAP = { "String" => "String", "NilClass | String" => "String", "Integer" => "Int", "NilClass | Integer" => "Int", "Float" => "Float", "NilClass | Float" => "Float", "FalseClass" => "Boolean", "TrueClass | FalseClass" => "Boolean", "FalseClass | TrueClass" => "Boolean", "NilClass | TrueClass | FalseClass" => "Boolean" } def self.get_graphql_type(type) return type if type.is_a?(GraphQL::ObjectType) type_string = TYPE_MAP[type.name] if type.optional? GraphQL::Define::TypeDefiner.instance.send(type_string) else !GraphQL::Define::TypeDefiner.instance.send(type_string) end end def self.get_member_type(type) member_type = type.options[:member] || type.type.options[:member] if has_ancestor?(member_type, Kanji::Type) member_type[:graphql_type] else member_type end end def self.array_type?(type) return type.primitive == Array if defined?(type.primitive) defined?(type.type) && type.type.primitive == Array end def self.has_ancestor?(type, ancestor) return false unless type.respond_to?(:ancestors) type.ancestors.include?(ancestor) end end end end
Version data entries
1 entries across 1 versions & 1 rubygems
Version | Path |
---|---|
kanji-web-0.3.1 | lib/kanji/graph/coerce_type.rb |