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.



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

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.



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

def defined_fields
  @defined_fields
end

#definitionObject (readonly)

Returns the value of attribute definition.



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

def definition
  @definition
end

#klassObject (readonly)

Returns the value of attribute klass.



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

def klass
  @klass
end

Instance Method Details

#fieldsObject



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

def fields
  @klass.fields
end

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



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

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

#spreadsObject



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

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

#typeObject



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

def type
  @klass.type
end