Class: ElasticGraph::GraphQL::Config

Inherits:
Object
  • Object
show all
Defined in:
lib/elastic_graph/graphql/config.rb

Constant Summary collapse

EXPECTED_KEYS =

The keys we expect under ‘graphql`.

members.map(&:to_s)
ELASTICGRAPH_CONFIG_KEYS =

The standard ElasticGraph root config setting keys; anything else is assumed to be extension settings.

%w[graphql indexer logger datastore schema_artifacts]

Class Method Summary collapse

Class Method Details

.from_parsed_yaml(entire_parsed_yaml) ⇒ Object



31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
# File 'lib/elastic_graph/graphql/config.rb', line 31

def self.from_parsed_yaml(entire_parsed_yaml)
  parsed_yaml = entire_parsed_yaml.fetch("graphql")
  extra_keys = parsed_yaml.keys - EXPECTED_KEYS

  unless extra_keys.empty?
    raise ConfigError, "Unknown `graphql` config settings: #{extra_keys.join(", ")}"
  end

  extension_loader = SchemaArtifacts::::ExtensionLoader.new(::Module.new)
  extension_mods = parsed_yaml.fetch("extension_modules", []).map do |mod_hash|
    extension_loader.load(mod_hash.fetch("extension_name"), from: mod_hash.fetch("require_path"), config: {}).extension_class.tap do |mod|
      unless mod.instance_of?(::Module)
        raise ConfigError, "`#{mod_hash.fetch("extension_name")}` is not a module, but all application extension modules must be modules."
      end
    end
  end

  new(
    default_page_size: parsed_yaml.fetch("default_page_size"),
    max_page_size: parsed_yaml.fetch("max_page_size"),
    slow_query_latency_warning_threshold_in_ms: parsed_yaml["slow_query_latency_warning_threshold_in_ms"] || 5000,
    client_resolver: load_client_resolver(parsed_yaml),
    extension_modules: extension_mods,
    extension_settings: entire_parsed_yaml.except(*ELASTICGRAPH_CONFIG_KEYS)
  )
end