Class: GraphQL::Client::Schema::ObjectClass
- Inherits:
-
Object
- Object
- GraphQL::Client::Schema::ObjectClass
- Defined in:
- lib/graphql/client/schema/object_type.rb
Instance Attribute Summary collapse
-
#errors ⇒ Object
readonly
Public: Return errors associated with data.
Instance Method Summary collapse
-
#initialize(data = {}, errors = Errors.new) ⇒ ObjectClass
constructor
A new instance of ObjectClass.
- #inspect ⇒ Object
- #method_missing(*args) ⇒ Object
-
#to_h ⇒ Object
Public: Returns the raw response data.
Constructor Details
#initialize(data = {}, errors = Errors.new) ⇒ ObjectClass
Returns a new instance of ObjectClass.
81 82 83 84 85 |
# File 'lib/graphql/client/schema/object_type.rb', line 81 def initialize(data = {}, errors = Errors.new) @data = data @casted_data = {} @errors = errors end |
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
#method_missing(*args) ⇒ Object
99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 |
# File 'lib/graphql/client/schema/object_type.rb', line 99 def method_missing(*args) super rescue NoMethodError => e type = self.class.type if ActiveSupport::Inflector.underscore(e.name.to_s) != e.name.to_s raise e end field = type.all_fields.find do |f| f.name == e.name.to_s || ActiveSupport::Inflector.underscore(f.name) == e.name.to_s end unless field raise UnimplementedFieldError, "undefined field `#{e.name}' on #{type} type. https://git.io/v1y3m" end if @data.key?(field.name) error_class = ImplicitlyFetchedFieldError = "implicitly fetched field `#{field.name}' on #{type} type. https://git.io/v1yGL" else error_class = UnfetchedFieldError = "unfetched field `#{field.name}' on #{type} type. https://git.io/v1y3U" end raise error_class, end |
Instance Attribute Details
#errors ⇒ Object (readonly)
Public: Return errors associated with data.
Returns Errors collection.
97 98 99 |
# File 'lib/graphql/client/schema/object_type.rb', line 97 def errors @errors end |
Instance Method Details
#inspect ⇒ Object
127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 |
# File 'lib/graphql/client/schema/object_type.rb', line 127 def inspect parent = self.class.ancestors.select { |m| m.is_a?(ObjectType) }.last ivars = @data.map { |key, value| if value.is_a?(Hash) || value.is_a?(Array) "#{key}=..." else "#{key}=#{value.inspect}" end } buf = "#<#{parent.name}".dup buf << " " << ivars.join(" ") if ivars.any? buf << ">" buf end |
#to_h ⇒ Object
Public: Returns the raw response data
Returns Hash
90 91 92 |
# File 'lib/graphql/client/schema/object_type.rb', line 90 def to_h @data end |