Class: GraphQL::FancyLoader::TypeGenerator

Inherits:
Object
  • Object
show all
Defined in:
lib/graphql/fancy_loader/type_generator.rb

Instance Method Summary collapse

Constructor Details

#initialize(loader, name: loader.model.name) ⇒ TypeGenerator

Returns a new instance of TypeGenerator.



6
7
8
9
# File 'lib/graphql/fancy_loader/type_generator.rb', line 6

def initialize(loader, name: loader.model.name)
  @loader = loader
  @name = name
end

Instance Method Details

#sorts_enumObject



11
12
13
14
15
16
17
18
19
20
21
22
23
# File 'lib/graphql/fancy_loader/type_generator.rb', line 11

def sorts_enum
  @sorts_enum ||= begin
    sorts = @loader.sorts
    name = "#{@name}SortEnum"

    Class.new(GraphQL::Schema::Enum) do
      graphql_name name
      sorts.each_key do |sort_name|
        value(sort_name.to_s.underscore.upcase, value: sort_name)
      end
    end
  end
end

#sorts_listObject



37
38
39
# File 'lib/graphql/fancy_loader/type_generator.rb', line 37

def sorts_list
  @sorts_list ||= GraphQL::Schema::List.new(sorts_option)
end

#sorts_optionObject



25
26
27
28
29
30
31
32
33
34
35
# File 'lib/graphql/fancy_loader/type_generator.rb', line 25

def sorts_option
  @sorts_option ||= begin
    enum = sorts_enum
    name = "#{@name}SortOption"
    Class.new(GraphQL::Schema::InputObject) do
      graphql_name name
      argument :on, enum, required: true
      argument :direction, GraphQL::SortDirection, required: true
    end
  end
end