Class: ArSerializer::GraphQL::HashTypeClass

Inherits:
TypeClass
  • Object
show all
Defined in:
lib/ar_serializer/graphql/types.rb

Instance Attribute Summary

Attributes inherited from TypeClass

#except, #only, #type

Instance Method Summary collapse

Methods inherited from TypeClass

#description, #fields, from, #initialize, #of_type, #validate!

Constructor Details

This class inherits a constructor from ArSerializer::GraphQL::TypeClass

Instance Method Details

#association_typeObject



256
257
258
259
260
261
262
# File 'lib/ar_serializer/graphql/types.rb', line 256

def association_type
  type.values.each do |v|
    t = TypeClass.from(v, only, except).association_type
    return t if t
  end
  nil
end

#collect_types(types) ⇒ Object



249
250
251
252
253
254
# File 'lib/ar_serializer/graphql/types.rb', line 249

def collect_types(types)
  types[:other] = true
  type.values.map do |v|
    TypeClass.from(v, only, except).collect_types(types)
  end
end

#gql_typeObject



264
265
266
# File 'lib/ar_serializer/graphql/types.rb', line 264

def gql_type
  'OBJECT'
end

#kindObject



241
242
243
# File 'lib/ar_serializer/graphql/types.rb', line 241

def kind
  'SCALAR'
end

#nameObject



245
246
247
# File 'lib/ar_serializer/graphql/types.rb', line 245

def name
  :other
end

#sampleObject



268
269
270
271
272
# File 'lib/ar_serializer/graphql/types.rb', line 268

def sample
  type.reject { |k| k.to_s.ends_with? '?' }.transform_values do |v|
    TypeClass.from(v).sample
  end
end

#ts_typeObject



274
275
276
277
278
279
280
# File 'lib/ar_serializer/graphql/types.rb', line 274

def ts_type
  fields = type.map do |key, value|
    k = key.to_s == '*' ? '[key: string]' : key
    "#{k}: #{TypeClass.from(value, only, except).ts_type}"
  end
  "{ #{fields.join('; ')} }"
end