Class: GraphQL::Client::QueryResult::NonNullWrapper

Inherits:
Object
  • Object
show all
Defined in:
lib/graphql/client/query_result.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(type) ⇒ NonNullWrapper

Returns a new instance of NonNullWrapper.



127
128
129
# File 'lib/graphql/client/query_result.rb', line 127

def initialize(type)
  @of_klass = type
end

Instance Attribute Details

#of_klassObject (readonly)

Returns the value of attribute of_klass.



125
126
127
# File 'lib/graphql/client/query_result.rb', line 125

def of_klass
  @of_klass
end

Instance Method Details

#cast(value, errors) ⇒ Object



131
132
133
134
135
136
137
138
139
140
# File 'lib/graphql/client/query_result.rb', line 131

def cast(value, errors)
  case value
  when NilClass
    # TODO
    # raise ArgumentError, "expected non-nullable value to be present"
    nil
  else
    @of_klass.cast(value, errors)
  end
end

#|(other) ⇒ Object



142
143
144
145
146
147
148
# File 'lib/graphql/client/query_result.rb', line 142

def |(other)
  if self.class == other.class
    self.of_klass | other.of_klass
  else
    raise TypeError, "expected other to be a #{self.class}"
  end
end