class Graphiti::Types
Constants
- Bool
- Date
- Float
- Integer
- ParamDecimal
The Float() check here is to ensure we have a number Otherwise BigDecimal(‘foo’) *will return a decimal*
- PresentBool
- PresentDate
- PresentInteger
- PresentParamsDateTime
- PresentParamsHash
- REQUIRED_KEYS
- ReadDateTime
- WriteDateTime
Public Class Methods
[](key)
click to toggle source
# File lib/graphiti/types.rb, line 210 def self.[](key) map[key.to_sym] end
[]=(key, value)
click to toggle source
# File lib/graphiti/types.rb, line 214 def self.[]=(key, value) unless value.is_a?(Hash) && (REQUIRED_KEYS - value.keys).length.zero? raise Errors::InvalidType.new(key, value) end map[key.to_sym] = value end
create(primitive, &blk)
click to toggle source
# File lib/graphiti/types.rb, line 3 def self.create(primitive, &blk) definition = Dry::Types::Nominal.new(primitive) definition.constructor(&blk) end
map()
click to toggle source
# File lib/graphiti/types.rb, line 87 def self.map @map ||= begin hash = { integer_id: { canonical_name: :integer, params: Dry::Types["coercible.integer"], read: Dry::Types["coercible.string"], write: Dry::Types["coercible.integer"], kind: "scalar", description: "Base Type. Query/persist as integer, render as string." }, uuid: { params: Dry::Types["coercible.string"], read: Dry::Types["coercible.string"], write: Dry::Types["coercible.string"], kind: "scalar", description: "Base Type. Like a normal string, but by default only eq/!eq and case-sensitive." }, string_enum: { canonical_name: :enum, params: Dry::Types["coercible.string"], read: Dry::Types["coercible.string"], write: Dry::Types["coercible.string"], kind: "scalar", description: "String enum type. Like a normal string, but only eq/!eq and case-sensitive. Limited to only the allowed values." }, integer_enum: { canonical_name: :enum, params: Dry::Types["coercible.integer"], read: Dry::Types["coercible.integer"], write: Dry::Types["coercible.integer"], kind: "scalar", description: "Integer enum type. Like a normal integer, but only eq/!eq filters. Limited to only the allowed values." }, string: { params: Dry::Types["coercible.string"], read: Dry::Types["coercible.string"], write: Dry::Types["coercible.string"], kind: "scalar", description: "Base Type." }, integer: { params: PresentInteger, read: Integer, write: Integer, kind: "scalar", description: "Base Type." }, big_decimal: { params: ParamDecimal, read: Dry::Types["json.decimal"], write: Dry::Types["json.decimal"], kind: "scalar", description: "Base Type." }, float: { params: Dry::Types["coercible.float"], read: Float, write: Float, kind: "scalar", description: "Base Type." }, boolean: { params: PresentBool, read: Bool, write: Bool, kind: "scalar", description: "Base Type." }, date: { params: PresentDate, read: Date, write: Date, kind: "scalar", description: "Base Type." }, datetime: { params: PresentParamsDateTime, read: ReadDateTime, write: WriteDateTime, kind: "scalar", description: "Base Type." }, hash: { params: PresentParamsHash, read: Dry::Types["strict.hash"], write: Dry::Types["strict.hash"], kind: "record", description: "Base Type." }, array: { params: Dry::Types["strict.array"], read: Dry::Types["strict.array"], write: Dry::Types["strict.array"], kind: "array", description: "Base Type." } } hash.each_pair do |k, v| hash[k][:canonical_name] ||= k end arrays = {} hash.each_pair do |name, map| next if [:boolean, :hash, :array].include?(name) arrays[:"array_of_#{name.to_s.pluralize}"] = { canonical_name: name, params: Dry::Types["strict.array"].of(map[:params]), read: Dry::Types["strict.array"].of(map[:read]), test: Dry::Types["strict.array"].of(map[:test]), write: Dry::Types["strict.array"].of(map[:write]), kind: "array", description: "Base Type." } end hash.merge!(arrays) hash end end
name_for(key)
click to toggle source
# File lib/graphiti/types.rb, line 221 def self.name_for(key) key = key.to_sym type = map[key] type[:canonical_name] end