Class: GraphQL::Batch::Setup
- Inherits:
-
Object
- Object
- GraphQL::Batch::Setup
- Defined in:
- lib/graphql/batch/setup.rb
Class Method Summary collapse
- .end_batching ⇒ Object
- .instrument_field(schema, type, field) ⇒ Object
- .start_batching(executor_class) ⇒ Object
Instance Method Summary collapse
- #after_query(query) ⇒ Object
- #before_query(query) ⇒ Object
-
#initialize(schema, executor_class:) ⇒ Setup
constructor
A new instance of Setup.
- #instrument(type, field) ⇒ Object
Constructor Details
#initialize(schema, executor_class:) ⇒ Setup
Returns a new instance of Setup.
28 29 30 31 |
# File 'lib/graphql/batch/setup.rb', line 28 def initialize(schema, executor_class:) @schema = schema @executor_class = executor_class end |
Class Method Details
.end_batching ⇒ Object
8 9 10 |
# File 'lib/graphql/batch/setup.rb', line 8 def end_batching GraphQL::Batch::Executor.end_batch end |
.instrument_field(schema, type, field) ⇒ Object
12 13 14 15 16 17 18 19 20 21 22 23 24 25 |
# File 'lib/graphql/batch/setup.rb', line 12 def instrument_field(schema, type, field) return field unless type == schema.mutation old_resolve_proc = field.resolve_proc field.redefine do resolve ->(obj, args, ctx) { GraphQL::Batch::Executor.current.clear begin ::Promise.sync(old_resolve_proc.call(obj, args, ctx)) ensure GraphQL::Batch::Executor.current.clear end } end end |
.start_batching(executor_class) ⇒ Object
4 5 6 |
# File 'lib/graphql/batch/setup.rb', line 4 def start_batching(executor_class) GraphQL::Batch::Executor.start_batch(executor_class) end |
Instance Method Details
#after_query(query) ⇒ Object
37 38 39 |
# File 'lib/graphql/batch/setup.rb', line 37 def after_query(query) Setup.end_batching end |
#before_query(query) ⇒ Object
33 34 35 |
# File 'lib/graphql/batch/setup.rb', line 33 def before_query(query) Setup.start_batching(@executor_class) end |
#instrument(type, field) ⇒ Object
41 42 43 |
# File 'lib/graphql/batch/setup.rb', line 41 def instrument(type, field) Setup.instrument_field(@schema, type, field) end |