Class: GraphQL::Schema::MiddlewareChain

Inherits:
Object
  • Object
show all
Defined in:
lib/graphql/schema/middleware_chain.rb

Overview

Given #steps and #arguments, call steps in order, passing ‘(*arguments, next_step)`.

Steps should call ‘next_step.call` to continue the chain, or not call it to stop the chain.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(steps:, arguments:) ⇒ MiddlewareChain

Returns a new instance of MiddlewareChain.



13
14
15
16
17
# File 'lib/graphql/schema/middleware_chain.rb', line 13

def initialize(steps:, arguments:)
  # We're gonna destroy this array, so copy it:
  @steps = steps.dup
  @arguments = arguments
end

Instance Attribute Details

#argumentsArray (readonly)

Returns Arguments passed to steps (followed by ‘next_middleware`).

Returns:

  • (Array)

    Arguments passed to steps (followed by ‘next_middleware`)



11
12
13
# File 'lib/graphql/schema/middleware_chain.rb', line 11

def arguments
  @arguments
end

#stepsArray<#call(*args)> (readonly)

Returns Steps in this chain, will be called with arguments and ‘next_middleware`.

Returns:

  • (Array<#call(*args)>)

    Steps in this chain, will be called with arguments and ‘next_middleware`



8
9
10
# File 'lib/graphql/schema/middleware_chain.rb', line 8

def steps
  @steps
end

Instance Method Details

#call(next_arguments = @arguments) ⇒ Object

Run the next step in the chain, passing in arguments and handle to the next step



20
21
22
23
24
25
# File 'lib/graphql/schema/middleware_chain.rb', line 20

def call(next_arguments = @arguments)
  @arguments = next_arguments
  next_step = steps.shift
  next_middleware = self
  next_step.call(*arguments, next_middleware)
end