Sha256: 9c85ff0928632cb17fad18a88a0496d4fc2db2711df7d2158091c8b06cd8abf2

Contents?: true

Size: 1.24 KB

Versions: 1

Compression:

Stored size: 1.24 KB

Contents

require "graphql"
if Gem::Version.new(GraphQL::VERSION) < Gem::Version.new("1.3")
  warn "graphql gem versions less than 1.3 are deprecated for use with graphql-batch, upgrade so lazy_resolve can be used"
end
require "promise.rb"

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

    def self.batch
      raise NestedError if GraphQL::Batch::Executor.current
      begin
        GraphQL::Batch::Executor.current = GraphQL::Batch::Executor.new
        Promise.sync(yield)
      ensure
        GraphQL::Batch::Executor.current = nil
      end
    end

    def self.use(schema_defn)
      if GraphQL::VERSION >= "1.6.0"
        schema_defn.instrument(:multiplex, GraphQL::Batch::SetupMultiplex)
      else
        schema_defn.instrument(:query, GraphQL::Batch::Setup)
      end
      schema_defn.lazy_resolve(::Promise, :sync)
    end

    autoload :ExecutionStrategy, 'graphql/batch/execution_strategy'
    autoload :MutationExecutionStrategy, 'graphql/batch/mutation_execution_strategy'
  end
end

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

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
graphql-batch-0.3.4 lib/graphql/batch.rb