Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
86 changes: 43 additions & 43 deletions README.md

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion Rakefile
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ namespace :benchmark do
GraphQLBenchmark.benchmark_introspection
end

desc "Benchmark GraphQL Ruby resolve_batch against breadth_exec"
desc "Benchmark GraphQL Ruby resolve_batch against breadth"
task :resolve_batch do
prepare_benchmark
GraphQLBenchmark.benchmark_resolve_batch
Expand Down
38 changes: 19 additions & 19 deletions benchmark/run.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
require "debug"
require "graphql"
require "graphql/batch"
require "graphql/breadth_exec"
require "graphql/breadth"

require "benchmark/ips"
require "memory_profiler"
Expand All @@ -28,7 +28,7 @@ def analyze_query(_query, _analyzers, multiplex_analyzers: [])

DOCUMENT = GraphQL.parse(BASIC_DOCUMENT)
CARDINAL_SCHEMA = SCHEMA
CARDINAL_TRACER = GraphQL::BreadthExec::Tracer.new
CARDINAL_TRACER = GraphQL::Breadth::Tracer.new
RESOLVE_BATCH_OBJECT_COUNT = 1_000
RESOLVE_BATCH_DOCUMENT = GraphQL.parse(%|{
widgets {
Expand Down Expand Up @@ -67,18 +67,18 @@ def analyze_query(_query, _analyzers, multiplex_analyzers: [])

RESOLVE_BATCH_RESOLVERS = {
"Widget" => {
"id" => GraphQL::BreadthExec::HashKeyResolver.new("id"),
"title" => GraphQL::BreadthExec::HashKeyResolver.new("title"),
"score" => GraphQL::BreadthExec::HashKeyResolver.new("score"),
"id" => GraphQL::Breadth::HashKeyResolver.new("id"),
"title" => GraphQL::Breadth::HashKeyResolver.new("title"),
"score" => GraphQL::Breadth::HashKeyResolver.new("score"),
},
"Query" => {
"widgets" => GraphQL::BreadthExec::HashKeyResolver.new("widgets"),
"widgets" => GraphQL::Breadth::HashKeyResolver.new("widgets"),
},
}.freeze

RESOLVE_BATCH_BREADTH_SCHEMA = GraphQL::Schema.from_definition(RESOLVE_BATCH_SDL)

class NoopBreadthLazyLoader < GraphQL::BreadthExec::LazyLoader
class NoopBreadthLazyLoader < GraphQL::Breadth::LazyLoader
def map?
true
end
Expand All @@ -88,7 +88,7 @@ def perform_map(keys, _context)
end
end

class LazyHashKeyResolver < GraphQL::BreadthExec::FieldResolver
class LazyHashKeyResolver < GraphQL::Breadth::FieldResolver
def initialize(key)
@key = key
end
Expand All @@ -108,7 +108,7 @@ def resolve(exec_field, _context)
"score" => LazyHashKeyResolver.new("score"),
},
"Query" => {
"widgets" => GraphQL::BreadthExec::HashKeyResolver.new("widgets"),
"widgets" => GraphQL::Breadth::HashKeyResolver.new("widgets"),
},
}.freeze

Expand Down Expand Up @@ -357,7 +357,7 @@ def benchmark_execution
end

x.report("graphql-cardinal #{num_objects} resolvers") do
GraphQL::BreadthExec::Executor.new(
GraphQL::Breadth::Executor.new(
SCHEMA,
DOCUMENT,
resolvers: BREADTH_RESOLVERS,
Expand Down Expand Up @@ -390,7 +390,7 @@ def benchmark_lazy_execution
end

x.report("graphql-cardinal: #{num_objects} lazy resolvers") do
GraphQL::BreadthExec::Executor.new(
GraphQL::Breadth::Executor.new(
SCHEMA,
DOCUMENT,
resolvers: BREADTH_DEFERRED_RESOLVERS,
Expand All @@ -413,7 +413,7 @@ def benchmark_introspection
end

x.report("graphql-cardinal introspection") do
GraphQL::BreadthExec::Executor.new(
GraphQL::Breadth::Executor.new(
SCHEMA,
document,
resolvers: BREADTH_RESOLVERS,
Expand Down Expand Up @@ -444,8 +444,8 @@ def benchmark_resolve_batch
warn "Skipping graphql-ruby resolve_batch: GraphQL::Execution::Next#execute_next is not available in graphql #{GraphQL::VERSION}."
end

x.report("graphql-breadth_exec: #{RESOLVE_BATCH_OBJECT_COUNT} x 3 scalars") do
GraphQL::BreadthExec::Executor.new(
x.report("graphql-breadth: #{RESOLVE_BATCH_OBJECT_COUNT} x 3 scalars") do
GraphQL::Breadth::Executor.new(
RESOLVE_BATCH_BREADTH_SCHEMA,
RESOLVE_BATCH_DOCUMENT,
resolvers: RESOLVE_BATCH_RESOLVERS,
Expand All @@ -464,8 +464,8 @@ def benchmark_lazy_scalars
Benchmark.ips do |x|
x.config(time: iterations, warmup: 1)

x.report("graphql-breadth_exec lazy: #{RESOLVE_BATCH_OBJECT_COUNT} x 3 scalars") do
GraphQL::BreadthExec::Executor.new(
x.report("graphql-breadth lazy: #{RESOLVE_BATCH_OBJECT_COUNT} x 3 scalars") do
GraphQL::Breadth::Executor.new(
RESOLVE_BATCH_BREADTH_SCHEMA,
RESOLVE_BATCH_DOCUMENT,
resolvers: LAZY_SCALAR_BREADTH_RESOLVERS,
Expand Down Expand Up @@ -516,8 +516,8 @@ def benchmark_lazy_field_batch
execute_graphql_ruby(LazyScalarDataloaderSchema, document: LAZY_FIELD_BATCH_DOCUMENT, root_value: RESOLVE_BATCH_DATA)
end

x.report("graphql-breadth_exec LazyLoader: #{RESOLVE_BATCH_OBJECT_COUNT} x 1 lazy scalar") do
GraphQL::BreadthExec::Executor.new(
x.report("graphql-breadth LazyLoader: #{RESOLVE_BATCH_OBJECT_COUNT} x 1 lazy scalar") do
GraphQL::Breadth::Executor.new(
RESOLVE_BATCH_BREADTH_SCHEMA,
LAZY_FIELD_BATCH_DOCUMENT,
resolvers: LAZY_SCALAR_BREADTH_RESOLVERS,
Expand Down Expand Up @@ -546,7 +546,7 @@ def memory_profile

with_data_sizes(sizes) do |data_source, num_objects|
report = MemoryProfiler.report do
GraphQL::BreadthExec::Executor.new(
GraphQL::Breadth::Executor.new(
SCHEMA,
DOCUMENT,
resolvers: BREADTH_RESOLVERS,
Expand Down
16 changes: 8 additions & 8 deletions graphql-breadth_exec.gemspec → graphql-breadth.gemspec
Original file line number Diff line number Diff line change
@@ -1,23 +1,23 @@
# frozen_string_literal: true

require_relative 'lib/graphql/breadth_exec/version'
require_relative 'lib/graphql/breadth/version'

Gem::Specification.new do |spec|
spec.name = 'graphql-breadth_exec'
spec.version = GraphQL::BreadthExec::VERSION
spec.name = 'graphql-breadth'
spec.version = GraphQL::Breadth::VERSION
spec.authors = ['Greg MacWilliam']
spec.summary = 'A breadth-first executor for GraphQL Ruby'
spec.description = 'A breadth-first executor for GraphQL Ruby'
spec.homepage = 'https://github.com/gmac/graphql-breadth-exec'
spec.homepage = 'https://github.com/gmac/graphql-breadth'
spec.license = 'MIT'

spec.required_ruby_version = '>= 2.7.0'

spec.metadata = {
'homepage_uri' => 'https://github.com/gmac/graphql-breadth-exec',
'changelog_uri' => 'https://github.com/gmac/graphql-breadth-exec/releases',
'source_code_uri' => 'https://github.com/gmac/graphql-breadth-exec',
'bug_tracker_uri' => 'https://github.com/gmac/graphql-breadth-exec/issues',
'homepage_uri' => 'https://github.com/gmac/graphql-breadth',
'changelog_uri' => 'https://github.com/gmac/graphql-breadth/releases',
'source_code_uri' => 'https://github.com/gmac/graphql-breadth',
'bug_tracker_uri' => 'https://github.com/gmac/graphql-breadth/issues',
}

spec.files = `git ls-files -z`.split("\x0").reject do |f|
Expand Down
30 changes: 15 additions & 15 deletions lib/graphql/breadth_exec.rb → lib/graphql/breadth.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
require "set"

module GraphQL
module BreadthExec
module Breadth
class << self
#: Proc?
attr_accessor :on_report_error
Expand Down Expand Up @@ -36,17 +36,17 @@ class ExecutionField; end
end
end

require_relative "breadth_exec/util"
require_relative "breadth_exec/errors"
require_relative "breadth_exec/authorization"
require_relative "breadth_exec/executor/execution_promise"
require_relative "breadth_exec/lazy_loader"
require_relative "breadth_exec/tracer"
require_relative "breadth_exec/field_resolvers"
require_relative "breadth_exec/directive_resolvers"
require_relative "breadth_exec/subscription_response_stream"
require_relative "breadth_exec/has_breadth_resolver"
require_relative "breadth_exec/introspection"
require_relative "breadth_exec/executor"
require_relative "breadth_exec/incremental"
require_relative "breadth_exec/version"
require_relative "breadth/util"
require_relative "breadth/errors"
require_relative "breadth/authorization"
require_relative "breadth/executor/execution_promise"
require_relative "breadth/lazy_loader"
require_relative "breadth/tracer"
require_relative "breadth/field_resolvers"
require_relative "breadth/directive_resolvers"
require_relative "breadth/subscription_response_stream"
require_relative "breadth/has_breadth_resolver"
require_relative "breadth/introspection"
require_relative "breadth/executor"
require_relative "breadth/incremental"
require_relative "breadth/version"
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
require "graphql"

module GraphQL
module BreadthExec
module Breadth
class Authorization
#: (Executor::ExecutionField[untyped], GraphQL::Query::Context) -> bool
def authorized_field?(exec_field, context)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
# frozen_string_literal: true

module GraphQL
module BreadthExec
module Breadth
class DirectiveResolver
#: (?wraps: bool, ?cascades: bool) -> void
def initialize(wraps: false, cascades: false)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
require "graphql"

module GraphQL
module BreadthExec
module Breadth
class Error < StandardError; end
class ImplementationError < Error; end
class MethodNotImplementedError < Error; end
Expand All @@ -19,14 +19,14 @@ class << self

#: (
#| untyped,
#| ?exec_field: GraphQL::BreadthExec::Executor::ExecutionField[untyped]?,
#| ?exec_field: GraphQL::Breadth::Executor::ExecutionField[untyped]?,
#| ?cause: Exception?
#| ) -> ExecutionError
def from(err, exec_field: nil, cause: nil)
return err if err.equal?(UNREPORTED_ERROR)

case err
when BreadthExec::ExecutionError
when Breadth::ExecutionError
if err.exec_field != exec_field || err.cause != cause
err = err.dup
err.exec_field = exec_field if exec_field
Expand All @@ -47,7 +47,7 @@ def from(err, exec_field: nil, cause: nil)

DEFAULT_MESSAGE = "An unknown error occurred"

#: GraphQL::BreadthExec::Executor::ExecutionField[untyped]?
#: GraphQL::Breadth::Executor::ExecutionField[untyped]?
attr_accessor :exec_field

#: Exception?
Expand All @@ -61,7 +61,7 @@ def from(err, exec_field: nil, cause: nil)

#: (
#| ?String?,
#| ?exec_field: GraphQL::BreadthExec::Executor::ExecutionField[untyped]?,
#| ?exec_field: GraphQL::Breadth::Executor::ExecutionField[untyped]?,
#| ?nodes: Array[GraphQL::Language::Nodes::AbstractNode],
#| ?extensions: extensions_hash?,
#| ?cause: Exception?,
Expand Down Expand Up @@ -119,7 +119,7 @@ class ExecutionErrorSet < ExecutionError

#: (
#| ?String?,
#| ?exec_field: GraphQL::BreadthExec::Executor::ExecutionField[untyped]?,
#| ?exec_field: GraphQL::Breadth::Executor::ExecutionField[untyped]?,
#| ?errors: Array[ExecutionError],
#| ) -> void
def initialize(message = nil, exec_field: nil, errors: [])
Expand Down Expand Up @@ -153,7 +153,7 @@ class FieldAuthorizationError < ExecutionError

#: (
#| ?String?,
#| exec_field: GraphQL::BreadthExec::Executor::ExecutionField[untyped],
#| exec_field: GraphQL::Breadth::Executor::ExecutionField[untyped],
#| ?extensions: extensions_hash?,
#| ?cause: Exception?,
#| ) -> void
Expand All @@ -165,7 +165,7 @@ def initialize(message = nil, exec_field:, extensions: nil, cause: nil)
class InvalidNullError < ExecutionError
self.error_code = "INVALID_NULL".freeze

#: (?String?, exec_field: GraphQL::BreadthExec::Executor::ExecutionField[untyped], ?list_item: bool) -> void
#: (?String?, exec_field: GraphQL::Breadth::Executor::ExecutionField[untyped], ?list_item: bool) -> void
def initialize(message = nil, exec_field:, list_item: false)
message ||= if list_item
list_type = Util.unwrap_non_null(exec_field.type)
Expand Down Expand Up @@ -207,14 +207,14 @@ class InputValidatorError < InputError
class InputValidationErrorSet < ExecutionErrorSet; end

class InvalidListResultError < ImplementationError
#: GraphQL::BreadthExec::Executor::ExecutionField[untyped]
#: GraphQL::Breadth::Executor::ExecutionField[untyped]
attr_reader :exec_field

#: Class
attr_reader :result_type

#: (
#| exec_field: GraphQL::BreadthExec::Executor::ExecutionField[untyped],
#| exec_field: GraphQL::Breadth::Executor::ExecutionField[untyped],
#| result_type: Class,
#| ) -> void
def initialize(exec_field:, result_type:)
Expand All @@ -225,7 +225,7 @@ def initialize(exec_field:, result_type:)
end

class ResultCountMismatchError < ImplementationError
#: GraphQL::BreadthExec::Executor::ExecutionField[untyped]
#: GraphQL::Breadth::Executor::ExecutionField[untyped]
attr_reader :exec_field

#: Integer
Expand All @@ -236,7 +236,7 @@ class ResultCountMismatchError < ImplementationError

#: (
#| ?String?,
#| exec_field: GraphQL::BreadthExec::Executor::ExecutionField[untyped],
#| exec_field: GraphQL::Breadth::Executor::ExecutionField[untyped],
#| expected_count: Integer,
#| actual_count: Integer,
#| ) -> void
Expand All @@ -258,11 +258,11 @@ def initialize(from, to)
end

class LazySequencingError < ImplementationError
#: GraphQL::BreadthExec::Executor::LazyElement
#: GraphQL::Breadth::Executor::LazyElement
attr_reader :lazy_element

#: (
#| lazy_element: GraphQL::BreadthExec::Executor::LazyElement,
#| lazy_element: GraphQL::Breadth::Executor::LazyElement,
#| method_name: String,
#| ) -> void
def initialize(lazy_element:, method_name:)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
require_relative "./executor/path_formatter"

module GraphQL
module BreadthExec
module Breadth
class Executor
#: type type_resolver = ^(untyped, GraphQL::Query::Context) -> singleton(GraphQL::Schema::Member)?
#: type resolver = FieldResolver | DirectiveResolver | type_resolver
Expand Down Expand Up @@ -275,7 +275,7 @@ def execute
begin
@input.coerce_variable_values(operation.variables, @query.provided_variables || EMPTY_OBJECT)
rescue InputValidationErrorSet => e
GraphQL::BreadthExec.report_error(e)
GraphQL::Breadth.report_error(e)
end

execute_with_directives(@planner.root_directives_for_operation(operation)) do
Expand Down
Loading
Loading