Class: GraphQL::Autotest::Runner

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

Instance Method Summary collapse

Constructor Details

#initialize(schema:, context:, arguments_fetcher: ArgumentsFetcher::DEFAULT, max_depth: 10, skip_if: -> (_field, **) { false }, logger: Logger.new(nil)) ⇒ Runner



12
13
14
15
16
17
18
19
# File 'lib/graphql/autotest/runner.rb', line 12

def initialize(schema:, context:, arguments_fetcher: ArgumentsFetcher::DEFAULT, max_depth: 10, skip_if: -> (_field, **) { false }, logger: Logger.new(nil))
  @schema = schema
  @context = context
  @arguments_fetcher = arguments_fetcher
  @max_depth = max_depth
  @skip_if = skip_if
  @logger = logger
end

Instance Method Details

#report(dry_run: false) ⇒ Object



21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
# File 'lib/graphql/autotest/runner.rb', line 21

def report(dry_run: false)
  report = Report.new(executions: [])

  fields = QueryGenerator.generate(
    document: schema.to_document,
    arguments_fetcher: arguments_fetcher,
    max_depth: max_depth,
    skip_if: skip_if,
  )
  fields.each do |f|
    q = f.to_query
    
    logger.info "Running Query: #{f.name}"
    
    result = if dry_run
               {}
             else
               schema.execute(
                 document: GraphQL.parse(q),
                 variables: {},
                 operation_name: nil,
                 context: context,
               )
             end
    report.executions << Report::Execution.new(query: q, result: result)
  end

  report
end

#report!(dry_run: false) ⇒ Object



51
52
53
54
55
# File 'lib/graphql/autotest/runner.rb', line 51

def report!(dry_run: false)
  report(dry_run: dry_run).tap do |r|
    r.raise_if_error!
  end
end