Class: ArSerializer::GraphQL::HashTypeClass

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

Instance Attribute Summary

Attributes inherited from TypeClass

#type

Instance Method Summary collapse

Methods inherited from TypeClass

#description, #fields, from, #initialize, #of_type

Constructor Details

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

Instance Method Details

#association_typeObject



233
234
235
236
237
238
239
# File 'lib/ar_serializer/graphql/types.rb', line 233

def association_type
  type.values.each do |v|
    t = v.association_type
    return t if t
  end
  nil
end

#collect_types(types) ⇒ Object



226
227
228
229
230
231
# File 'lib/ar_serializer/graphql/types.rb', line 226

def collect_types(types)
  types[:other] = true
  type.values.each do |v|
    v.collect_types(types)
  end
end

#gql_typeObject



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

def gql_type = 'OBJECT'

#kindObject



222
# File 'lib/ar_serializer/graphql/types.rb', line 222

def kind = 'SCALAR'

#nameObject



224
# File 'lib/ar_serializer/graphql/types.rb', line 224

def name = :other

#to_gql_argsObject



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

def to_gql_args
  type.map do |key, type|
    ArgClass.new key, type
  end
end

#ts_typeObject



243
244
245
246
247
248
249
250
251
# File 'lib/ar_serializer/graphql/types.rb', line 243

def ts_type
  return 'Record<string, never>' if type.empty?

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