Sha256: 00bb17a51673d2f024727600997ce67b1b7b04f77ff122261e69cf3996482eec

Contents?: true

Size: 1.06 KB

Versions: 4

Compression:

Stored size: 1.06 KB

Contents

require "graphql"
require "promise.rb"

module GraphQL
  module Batch
    BrokenPromiseError = ::Promise::BrokenError
    class NoExecutorError < StandardError; end

    def self.batch(executor_class: GraphQL::Batch::Executor)
      begin
        GraphQL::Batch::Executor.start_batch(executor_class)
        ::Promise.sync(yield)
      ensure
        GraphQL::Batch::Executor.end_batch
      end
    end

    def self.use(schema_defn, executor_class: GraphQL::Batch::Executor)
      instrumentation = GraphQL::Batch::SetupMultiplex.new(schema_defn, executor_class: executor_class)
      schema_defn.instrument(:multiplex, instrumentation)

      if schema_defn.mutation
        require_relative "batch/mutation_field_extension"

        schema_defn.mutation.fields.each do |name, field|
          field.extension(GraphQL::Batch::MutationFieldExtension)
        end
      end

      schema_defn.lazy_resolve(::Promise, :sync)
    end
  end
end

require_relative "batch/version"
require_relative "batch/loader"
require_relative "batch/executor"
require_relative "batch/setup_multiplex"

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
graphql-batch-0.5.3 lib/graphql/batch.rb
graphql-batch-0.5.2 lib/graphql/batch.rb
graphql-batch-0.5.1 lib/graphql/batch.rb
graphql-batch-0.5.0 lib/graphql/batch.rb