Class: Desiru::GraphQL::BatchLoaderMiddleware
- Inherits:
-
Object
- Object
- Desiru::GraphQL::BatchLoaderMiddleware
- Defined in:
- lib/desiru/graphql/executor.rb
Overview
Middleware for automatic batch loading
Instance Method Summary collapse
- #call(env) ⇒ Object
-
#initialize(app) ⇒ BatchLoaderMiddleware
constructor
A new instance of BatchLoaderMiddleware.
Constructor Details
#initialize(app) ⇒ BatchLoaderMiddleware
Returns a new instance of BatchLoaderMiddleware.
128 129 130 |
# File 'lib/desiru/graphql/executor.rb', line 128 def initialize(app) @app = app end |
Instance Method Details
#call(env) ⇒ Object
132 133 134 135 136 137 138 139 140 141 142 143 144 145 |
# File 'lib/desiru/graphql/executor.rb', line 132 def call(env) # Extract GraphQL context context = env['graphql.context'] || {} # Ensure data loader is available context[:data_loader] ||= DataLoader.new env['graphql.context'] = context # Execute with batch loading @app.call(env) ensure # Clean up after request context[:data_loader]&.clear! end |