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
30
31
# File 'lib/ar_serializer/graphql/types.rb', line 24

def args
  arguments = field.arguments_type
  return [] unless arguments.is_a?(HashTypeClass)

  arguments.type.map do |key, type|
    ArgClass.new key, type
  end
end

#args_required?Boolean

Returns:

  • (Boolean)


42
43
44
45
46
47
48
49
50
51
52
53
54
# File 'lib/ar_serializer/graphql/types.rb', line 42

def args_required?
  arguments_type = field.arguments_type
  case arguments_type
  when TSTypeClass
    true
  when HashTypeClass
    arguments_type.type.any? do |k, v|
      !k.end_with?('?') && !v.is_a?(OptionalTypeClass)
    end
  else
    false
  end
end

#args_ts_typeObject



56
57
58
# File 'lib/ar_serializer/graphql/types.rb', line 56

def args_ts_type
  field.arguments_type.ts_type
end

#collect_types(types) ⇒ Object



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

def collect_types(types)
  field.arguments_type.collect_types types
  type.collect_types types
end

#typeObject



33
34
35
# File 'lib/ar_serializer/graphql/types.rb', line 33

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