class GraphQL::Client::Schema::ObjectClass

Attributes

errors[R]

Public: Return errors associated with data.

Returns Errors collection.

Public Class Methods

new(data = {}, errors = Errors.new) click to toggle source
# File lib/graphql/client/schema/object_type.rb, line 187
def initialize(data = {}, errors = Errors.new)
  @data = data
  @casted_data = {}
  @errors = errors
end

Public Instance Methods

inspect() click to toggle source
# File lib/graphql/client/schema/object_type.rb, line 234
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
method_missing(*args) click to toggle source
Calls superclass method
# File lib/graphql/client/schema/object_type.rb, line 205
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

  all_fields = type.respond_to?(:all_fields) ? type.all_fields : type.fields.values
  field = 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.graphql_name} type. https://git.io/v1y3m"
  end

  if @data.key?(field.name)
    error_class = ImplicitlyFetchedFieldError
    message = "implicitly fetched field `#{field.name}' on #{type} type. https://git.io/v1yGL"
  else
    error_class = UnfetchedFieldError
    message = "unfetched field `#{field.name}' on #{type} type. https://git.io/v1y3U"
  end

  raise error_class, message
end
to_h() click to toggle source

Public: Returns the raw response data

Returns Hash

# File lib/graphql/client/schema/object_type.rb, line 196
def to_h
  @data
end