Module: HQ::GraphQL::Ext::SchemaExtensions

Defined in:
lib/hq/graphql/ext/schema_extensions.rb

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.prepended(klass) ⇒ Object



7
8
9
10
# File 'lib/hq/graphql/ext/schema_extensions.rb', line 7

def self.prepended(klass)
  klass.alias_method :add_type_and_traverse_without_types, :add_type_and_traverse
  klass.alias_method :add_type_and_traverse, :add_type_and_traverse_with_types
end

Instance Method Details

#add_type_and_traverse_with_types(*args, **options) ⇒ Object



41
42
43
44
# File 'lib/hq/graphql/ext/schema_extensions.rb', line 41

def add_type_and_traverse_with_types(*args, **options)
  @add_type_and_traverse_with_types ||= []
  @add_type_and_traverse_with_types.push([args, options])
end

#dumpObject



25
26
27
28
29
# File 'lib/hq/graphql/ext/schema_extensions.rb', line 25

def dump
  load_types!
  ::FileUtils.mkdir_p(dump_directory)
  ::File.open(::File.join(dump_directory, dump_filename), "w") { |file| file.write(self.to_definition) }
end

#dump_directory(directory = Rails.root.join("app/graphql")) ⇒ Object



17
18
19
# File 'lib/hq/graphql/ext/schema_extensions.rb', line 17

def dump_directory(directory = Rails.root.join("app/graphql"))
  @dump_directory ||= directory
end

#dump_filename(filename = "#{self.name.underscore}.graphql") ⇒ Object



21
22
23
# File 'lib/hq/graphql/ext/schema_extensions.rb', line 21

def dump_filename(filename = "#{self.name.underscore}.graphql")
  @dump_filename ||= filename
end

#execute(*args, **options) ⇒ Object



12
13
14
15
# File 'lib/hq/graphql/ext/schema_extensions.rb', line 12

def execute(*args, **options)
  load_types!
  super
end

#load_types!Object



31
32
33
34
35
36
37
# File 'lib/hq/graphql/ext/schema_extensions.rb', line 31

def load_types!
  ::HQ::GraphQL.load_types!
  return if @add_type_and_traverse_with_types.blank?
  while (args, options = @add_type_and_traverse_with_types.shift)
    add_type_and_traverse_without_types(*args, **options)
  end
end