Module: GraphQL::PersistedQueries::ErrorHandlers

Defined in:
lib/graphql/persisted_queries/error_handlers.rb,
lib/graphql/persisted_queries/error_handlers/base_error_handler.rb,
lib/graphql/persisted_queries/error_handlers/default_error_handler.rb

Overview

Contains factory methods for error handlers

Defined Under Namespace

Classes: BaseErrorHandler, DefaultErrorHandler

Class Method Summary collapse

Class Method Details

.build(handler, **options) ⇒ Object



10
11
12
13
14
15
16
17
18
# File 'lib/graphql/persisted_queries/error_handlers.rb', line 10

def self.build(handler, **options)
  if handler.is_a?(ErrorHandlers::BaseErrorHandler)
    handler
  elsif handler.is_a?(Proc)
    build_from_proc(handler)
  else
    build_by_name(handler, **options)
  end
end

.build_by_name(name, **options) ⇒ Object



28
29
30
31
32
# File 'lib/graphql/persisted_queries/error_handlers.rb', line 28

def self.build_by_name(name, **options)
  const_get("#{BuilderHelpers.camelize(name)}ErrorHandler").new(**options)
rescue NameError => e
  raise e.class, "Persisted query error handler for :#{name} haven't been found", e.backtrace
end

.build_from_proc(proc) ⇒ Object



20
21
22
23
24
25
26
# File 'lib/graphql/persisted_queries/error_handlers.rb', line 20

def self.build_from_proc(proc)
  if proc.arity != 1
    raise ArgumentError, "proc passed to :error_handler should have exactly one argument"
  end

  proc
end