module HQ::GraphQL::Types
Public Class Methods
[](key, is_nil = false)
click to toggle source
# File lib/hq/graphql/types.rb, line 27 def self.[](key, is_nil = false) registry[[key, is_nil]] end
[]=(key, is_nil = false, value)
click to toggle source
# File lib/hq/graphql/types.rb, line 23 def self.[]=(key, is_nil = false, value) registry[[key, is_nil]] = value end
register(k, v)
click to toggle source
# File lib/hq/graphql/types.rb, line 19 def self.register(k, v) self[k] = v end
registry()
click to toggle source
# File lib/hq/graphql/types.rb, line 12 def self.registry @registry ||= Hash.new do |hash, options| klass, nil_klass = Array(options) hash[options] = nil_klass ? nil_query_object(klass) : klass_for(klass) end end
reset!()
click to toggle source
Only being used in testing
# File lib/hq/graphql/types.rb, line 56 def self.reset! @registry = nil end
type_from_column(column)
click to toggle source
# File lib/hq/graphql/types.rb, line 31 def self.type_from_column(column) graphql_type = case column.type when :uuid ::HQ::GraphQL::Types::UUID when :json, :jsonb ::GraphQL::Types::JSON when :integer ::GraphQL::Types::Int when :decimal ::GraphQL::Types::Float when :boolean ::GraphQL::Types::Boolean when :date ::GraphQL::Types::ISO8601Date when :datetime ::GraphQL::Types::ISO8601DateTime else ::GraphQL::Types::String end column.array ? [graphql_type] : graphql_type end
Private Class Methods
find_klass(klass_or_string, method)
click to toggle source
# File lib/hq/graphql/types.rb, line 71 def find_klass(klass_or_string, method) klass = klass_or_string.is_a?(String) ? klass_or_string.constantize : klass_or_string resource = ::HQ::GraphQL.lookup_resource(klass) raise(Error, Error::MISSING_TYPE_MSG % { klass: klass.name }) if !resource resource.send(method) end
klass_for(klass_or_string)
click to toggle source
# File lib/hq/graphql/types.rb, line 67 def klass_for(klass_or_string) find_klass(klass_or_string, :query_object) end
nil_query_object(klass_or_string)
click to toggle source
# File lib/hq/graphql/types.rb, line 63 def nil_query_object(klass_or_string) find_klass(klass_or_string, :nil_query_object) end