Class: Stardust::GraphQL::Union

Inherits:
GraphQL::Schema::Union
  • Object
show all
Defined in:
lib/stardust/graphql/union.rb

Class Method Summary collapse

Class Method Details

.possible_type(type, klass) ⇒ Object



6
7
8
9
# File 'lib/stardust/graphql/union.rb', line 6

def self.possible_type(type, klass)
  @__possible_types__ ||= {}
  @__possible_types__[type] = klass
end

.replace_types!Object



11
12
13
14
15
16
17
18
19
# File 'lib/stardust/graphql/union.rb', line 11

def self.replace_types!
  return unless @__possible_types__
  @__possible_types__ = @__possible_types__.reduce({}) do |accu, (type, klass)|
    lu_type = Collector.lookup_type(type)
    accu[lu_type] = klass
    accu
  end
  self.send(:possible_types, *@__possible_types__.keys)
end

.resolve_type(obj, ctx) ⇒ Object



21
22
23
# File 'lib/stardust/graphql/union.rb', line 21

def self.resolve_type(obj, ctx)
  @__possible_types__.invert[obj.class]
end