Class: ArSerializer::GraphQL::FieldClass

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(name, field) ⇒ FieldClass

Returns a new instance of FieldClass.



19
20
21
22
# File 'lib/ar_serializer/graphql/types.rb', line 19

def initialize(name, field)
  @name = name
  @field = field
end

Instance Attribute Details

#fieldObject (readonly)

Returns the value of attribute field.



18
19
20
# File 'lib/ar_serializer/graphql/types.rb', line 18

def field
  @field
end

#nameObject (readonly)

Returns the value of attribute name.



18
19
20
# File 'lib/ar_serializer/graphql/types.rb', line 18

def name
  @name
end

Instance Method Details

#argsObject



24
25
26
27
28
29
# File 'lib/ar_serializer/graphql/types.rb', line 24

def args
  return [] if field.arguments == :any
  field.arguments.map do |key, type|
    ArgClass.new key, type
  end
end

#args_ts_typeObject



41
42
43
44
45
46
# File 'lib/ar_serializer/graphql/types.rb', line 41

def args_ts_type
  arg_types = field.arguments.map do |key, type|
    "#{key}: #{TypeClass.from(type).ts_type}"
  end
  "{ #{arg_types.join '; '} }"
end

#collect_types(types) ⇒ Object



35
36
37
38
39
# File 'lib/ar_serializer/graphql/types.rb', line 35

def collect_types(types)
  types[:any] = true if field.arguments == :any
  args.each { |arg| arg.type.collect_types types }
  type.collect_types types
end

#typeObject



31
32
33
# File 'lib/ar_serializer/graphql/types.rb', line 31

def type
  TypeClass.from field.type, field.only, field.except
end