Class: GraphQL::Client::Schema::ObjectType::WithDefinition

Inherits:
Object
  • Object
show all
Includes:
BaseType, GraphQL::Client::Schema::ObjectType
Defined in:
lib/graphql/client/schema/object_type.rb

Constant Summary collapse

EMPTY_SET =
Set.new.freeze

Instance Attribute Summary collapse

Attributes included from BaseType

#schema_module

Instance Method Summary collapse

Methods included from GraphQL::Client::Schema::ObjectType

#cast, #define_class, #define_field, new

Methods included from BaseType

#cast, #to_list_type, #to_non_null_type

Constructor Details

#initialize(klass, defined_fields, definition, spreads) ⇒ WithDefinition

Returns a new instance of WithDefinition.



49
50
51
52
53
54
55
56
57
58
59
60
61
62
# File 'lib/graphql/client/schema/object_type.rb', line 49

def initialize(klass, defined_fields, definition, spreads)
  @klass = klass
  @defined_fields = defined_fields.map do |k, v|
    [-k.to_s, v]
  end.to_h
  @definition = definition
  @spreads = spreads unless spreads.empty?

  @defined_fields.keys.each do |attr|
    name = ActiveSupport::Inflector.underscore(attr)
    @klass::READERS[:"#{name}"] ||= attr
    @klass::PREDICATES[:"#{name}?"] ||= attr
  end
end

Instance Attribute Details

#defined_fieldsObject (readonly)

Returns the value of attribute defined_fields.



31
32
33
# File 'lib/graphql/client/schema/object_type.rb', line 31

def defined_fields
  @defined_fields
end

#definitionObject (readonly)

Returns the value of attribute definition.



31
32
33
# File 'lib/graphql/client/schema/object_type.rb', line 31

def definition
  @definition
end

#klassObject (readonly)

Returns the value of attribute klass.



31
32
33
# File 'lib/graphql/client/schema/object_type.rb', line 31

def klass
  @klass
end

Instance Method Details

#fieldsObject



37
38
39
# File 'lib/graphql/client/schema/object_type.rb', line 37

def fields
  @klass.fields
end

#new(data = {}, errors = Errors.new) ⇒ Object



64
65
66
# File 'lib/graphql/client/schema/object_type.rb', line 64

def new(data = {}, errors = Errors.new)
  @klass.new(data, errors, self)
end

#spreadsObject



41
42
43
44
45
46
47
# File 'lib/graphql/client/schema/object_type.rb', line 41

def spreads
  if defined?(@spreads)
    @spreads
  else
    EMPTY_SET
  end
end

#typeObject



33
34
35
# File 'lib/graphql/client/schema/object_type.rb', line 33

def type
  @klass.type
end