class GraphQL::Schema::MiddlewareChain
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.
Attributes
final_step[R]
@return [Array<#call(*args)>] Steps in this chain, will be called with arguments and `next_middleware`
steps[R]
@return [Array<#call(*args)>] Steps in this chain, will be called with arguments and `next_middleware`
Public Class Methods
new(steps: [], final_step: nil)
click to toggle source
# File lib/graphql/schema/middleware_chain.rb, line 13 def initialize(steps: [], final_step: nil) @steps = steps @final_step = final_step end
Public Instance Methods
<<(callable)
click to toggle source
# File lib/graphql/schema/middleware_chain.rb, line 25 def <<(callable) add_middleware(callable) end
==(other)
click to toggle source
# File lib/graphql/schema/middleware_chain.rb, line 33 def ==(other) steps == other.steps && final_step == other.final_step end
concat(callables)
click to toggle source
# File lib/graphql/schema/middleware_chain.rb, line 41 def concat(callables) callables.each { |c| add_middleware(c) } end
initialize_copy(other)
click to toggle source
Calls superclass method
# File lib/graphql/schema/middleware_chain.rb, line 18 def initialize_copy(other) super @steps = other.steps.dup end
invoke(arguments)
click to toggle source
# File lib/graphql/schema/middleware_chain.rb, line 37 def invoke(arguments) invoke_core(0, arguments) end
push(callable)
click to toggle source
# File lib/graphql/schema/middleware_chain.rb, line 29 def push(callable) add_middleware(callable) end
Private Instance Methods
add_middleware(callable)
click to toggle source
# File lib/graphql/schema/middleware_chain.rb, line 55 def add_middleware(callable) # TODO: Stop wrapping callables once deprecated middleware becomes unsupported steps << wrap(callable) end
invoke_core(index, arguments)
click to toggle source
# File lib/graphql/schema/middleware_chain.rb, line 47 def invoke_core(index, arguments) if index >= steps.length final_step.call(*arguments) else steps[index].call(*arguments) { |next_args = arguments| invoke_core(index + 1, next_args) } end end
wrap(callable)
click to toggle source
# File lib/graphql/schema/middleware_chain.rb, line 72 def wrap(callable) if BackwardsCompatibility.get_arity(callable) == 6 warn("Middleware that takes a next_middleware parameter is deprecated (#{callable.inspect}); instead, accept a block and use yield.") MiddlewareWrapper.new(callable) else callable end end