Class: Desiru::GraphQL::BatchLoaderMiddleware

Inherits:
Object
  • Object
show all
Defined in:
lib/desiru/graphql/executor.rb

Overview

Middleware for automatic batch loading

Instance Method Summary collapse

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