Class: GraphQL::Execution::LoadArgumentStep

Inherits:
Object
  • Object
show all
Defined in:
lib/graphql/execution/load_argument_step.rb

Instance Method Summary collapse

Constructor Details

#initialize(field_resolve_step:, arguments:, load_receiver:, argument_value:, argument_definition:, argument_key:) ⇒ LoadArgumentStep

Returns a new instance of LoadArgumentStep.



5
6
7
8
9
10
11
12
13
14
# File 'lib/graphql/execution/load_argument_step.rb', line 5

def initialize(field_resolve_step:, arguments:, load_receiver:, argument_value:, argument_definition:, argument_key:)
  @field_resolve_step = field_resolve_step
  @load_receiver = load_receiver
  @arguments = arguments
  @argument_value = argument_value
  @argument_definition = argument_definition
  @argument_key = argument_key
  @loaded_value = nil
  @is_authorized = true
end

Instance Method Details

#callObject



39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
# File 'lib/graphql/execution/load_argument_step.rb', line 39

def call
  context = @field_resolve_step.selections_step.query.context
  @loaded_value = begin
    @load_receiver.load_and_authorize_application_object(@argument_definition, @argument_value, context)
  rescue GraphQL::UnauthorizedError => auth_err
    @is_authorized = false
    context.schema.unauthorized_object(auth_err)
  end
  if (runner = @field_resolve_step.runner).resolves_lazies && runner.lazy?(@loaded_value)
    runner.dataloader.lazy_at_depth(@field_resolve_step.path.size, self)
  else
    assign_value
  end
rescue GraphQL::RuntimeError => err
  @loaded_value = if err.is_a?(Schema::Subscription::EarlyUnsubscribe)
    @is_authorized = false
    err.unsubscribed_result
  else
    err
  end
  assign_value
rescue StandardError => stderr
  @loaded_value = begin
    context.query.handle_or_reraise(stderr, field: @field_resolve_step.field_definition, arguments: @field_resolve_step.arguments, object: nil) # rubocop:disable Development/ContextIsPassedCop
  rescue GraphQL::ExecutionError => ex_err
    ex_err
  end
  assign_value
end

#valueObject



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

def value
  schema = @field_resolve_step.runner.schema
  @loaded_value = schema.sync_lazy(@loaded_value)
  assign_value
rescue GraphQL::UnauthorizedError => auth_err
  @is_authorized = false
  schema.unauthorized_object(auth_err)
rescue GraphQL::RuntimeError => err
  @loaded_value = if err.is_a?(Schema::Subscription::EarlyUnsubscribe)
    err.unsubscribed_result
  else
    err
  end
  assign_value
rescue StandardError => stderr
  begin
    @field_resolve_step.selections_step.query.handle_or_reraise(stderr, field: @field_definition, arguments: @arguments, object: nil)
  rescue GraphQL::ExecutionError => ex_err
    @loaded_value = ex_err
  end
  assign_value
end