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.



132
133
134
# File 'lib/graphql/client/query_result.rb', line 132

def initialize(type)
  @of_klass = type
end

Instance Attribute Details

#of_klassObject (readonly)

Returns the value of attribute of_klass.



130
131
132
# File 'lib/graphql/client/query_result.rb', line 130

def of_klass
  @of_klass
end

Instance Method Details

#cast(value, errors) ⇒ Object



136
137
138
139
140
141
142
143
144
145
# File 'lib/graphql/client/query_result.rb', line 136

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



147
148
149
150
151
152
153
# File 'lib/graphql/client/query_result.rb', line 147

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