Class: GraphQL::Schema::MiddlewareChain
- Inherits:
-
Object
- Object
- GraphQL::Schema::MiddlewareChain
- 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
-
#arguments ⇒ Array
readonly
Arguments passed to steps (followed by
next_middleware
). -
#steps ⇒ Array<#call(*args)>
readonly
Steps in this chain, will be called with arguments and
next_middleware
.
Instance Method Summary collapse
-
#call(next_arguments = @arguments) ⇒ Object
Run the next step in the chain, passing in arguments and handle to the next step.
-
#initialize(steps:, arguments:) ⇒ MiddlewareChain
constructor
A new instance of MiddlewareChain.
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
#arguments ⇒ Array (readonly)
Returns Arguments passed to steps (followed by next_middleware
).
11 12 13 |
# File 'lib/graphql/schema/middleware_chain.rb', line 11 def arguments @arguments end |
#steps ⇒ Array<#call(*args)> (readonly)
Returns 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 |