Class: GraphitiGql::Schema::PolymorphicBelongsToInterface

Inherits:
Object
  • Object
show all
Defined in:
lib/graphiti_gql/schema/polymorphic_belongs_to_interface.rb

Instance Method Summary collapse

Constructor Details

#initialize(resource, sideload) ⇒ PolymorphicBelongsToInterface

Returns a new instance of PolymorphicBelongsToInterface.



4
5
6
7
# File 'lib/graphiti_gql/schema/polymorphic_belongs_to_interface.rb', line 4

def initialize(resource, sideload)
  @resource = resource
  @sideload = sideload
end

Instance Method Details

#buildObject



9
10
11
12
13
14
15
16
17
18
19
20
21
22
# File 'lib/graphiti_gql/schema/polymorphic_belongs_to_interface.rb', line 9

def build
  return registry[name][:type] if registry[name]

  klass = Module.new
  klass.send :include, ResourceType::BaseInterface
  klass.field :id, String, null: false
  klass.field :_type, String, null: false
  klass.graphql_name(name)
  @sideload.children.values.each do |child|
    registry.get(child.resource.class)[:type].implements(klass)
  end
  registry[name] = { type: klass }
  registry[name]
end