Class: GraphQL::Doctor::Runner

Inherits:
Object
  • Object
show all
Defined in:
lib/graphql/doctor/runner.rb

Defined Under Namespace

Classes: Result

Instance Method Summary collapse

Constructor Details

#initialize(config:, root: Dir.pwd, cache: true, jobs: 1, boot: true, schema_dump: nil) ⇒ Runner

Returns a new instance of Runner.



8
9
10
11
12
13
14
15
# File 'lib/graphql/doctor/runner.rb', line 8

def initialize(config:, root: Dir.pwd, cache: true, jobs: 1, boot: true, schema_dump: nil)
  @config = config
  @root = root
  @cache = cache
  @jobs = jobs
  @boot = boot
  @schema_dump = schema_dump
end

Instance Method Details

#check(paths = []) ⇒ Object



17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
# File 'lib/graphql/doctor/runner.rb', line 17

def check(paths = [])
  source = Source::Loader.new(root: @root, config: @config, cache: @cache).load(paths, jobs: @jobs)
  runtime = load_runtime(source)
  return Result.new(diagnostics: static_diagnostics(source), runtime_error: false) unless runtime

  correlation = Correlation::Correlator.new(source, runtime)
  diagnostics = Checks::Engine.new(source, runtime, correlation, @config).call
  diagnostics = Suppression.filter(
    source.diagnostics + diagnostics,
    source.comments,
    require_reason: @config["require_suppression_reason"]
  )
  Result.new(diagnostics: diagnostics, runtime_error: false)
rescue Error => e
  location = Location.new(
    path: @config["require"].to_s, start_line: 1, end_line: 1,
    start_column: 0, end_column: 1, start_offset: 0, end_offset: 1
  )
  message = e.message.sub(/\AGQLD101:\s*/, "")
  diagnostic = Diagnostic.new(code: "GQLD101", severity: "error", message: message, location: location)
  diagnostics = defined?(source) && source ? static_diagnostics(source) : []
  Result.new(diagnostics: diagnostics + [diagnostic], runtime_error: true)
end