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



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

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



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

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

#gql_typeObject



266
267
268
# File 'lib/ar_serializer/graphql/types.rb', line 266

def gql_type
  'OBJECT'
end

#kindObject



243
244
245
# File 'lib/ar_serializer/graphql/types.rb', line 243

def kind
  'SCALAR'
end

#nameObject



247
248
249
# File 'lib/ar_serializer/graphql/types.rb', line 247

def name
  :other
end

#sampleObject



270
271
272
273
274
# File 'lib/ar_serializer/graphql/types.rb', line 270

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

#ts_typeObject



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

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