Module: Stardust::GraphQL::Interface

Defined in:
lib/stardust/graphql/interface.rb

Class Method Summary collapse

Class Method Details

.included(base) ⇒ Object



5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
# File 'lib/stardust/graphql/interface.rb', line 5

def self.included(base)
  base.module_eval do
    include ::GraphQL::Schema::Interface

    def self.graphql_name(name = nil)
      if name
        @__graphql_name__ = name
      else
        @__graphql_name__
      end
    end

    def self.field(name, type, description = nil, **kwargs, &block)
      
      @__types_to_lookup__ ||= []
      @__types_to_lookup__ << ->(klass) {
        actual_type = Collector.lookup_type(type)

        klass
        .method(:field)
        .super_method
        .call(name, actual_type, description, **kwargs, &block)
      }
    end

    def self.replace_types!
      return unless @__types_to_lookup__
      @__types_to_lookup__.each {|lookup| lookup.(self)}
    end
  end
  base
end