Skip to content

Commit

Permalink
Merge pull request #2543 from vaihtovirta/issue-2067/replace-not-impl…
Browse files Browse the repository at this point in the history
…emented-error

Issue#2067 Replace NotImplementedError with RequiredImplementationMissingError
  • Loading branch information
Robert Mosolgo committed Oct 15, 2019
2 parents 1c23944 + 057feb3 commit 35dc19b
Show file tree
Hide file tree
Showing 25 changed files with 51 additions and 48 deletions.
2 changes: 1 addition & 1 deletion lib/generators/graphql/templates/schema.erb
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ class <%= schema_name %> < GraphQL::Schema
def self.resolve_type(type, obj, ctx)
# TODO: Implement this function
# to return the correct type for `obj`
raise(NotImplementedError)
raise(GraphQL::RequiredImplementationMissingError)
end
<% end %><% if options[:batch] %>
# GraphQL::Batch setup:
Expand Down
3 changes: 3 additions & 0 deletions lib/graphql.rb
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,9 @@ module GraphQL
class Error < StandardError
end

class RequiredImplementationMissingError < Error
end

# Turn a query string or schema definition into an AST
# @param graphql_string [String] a GraphQL query string or schema definition
# @return [GraphQL::Language::Nodes::Document]
Expand Down
2 changes: 1 addition & 1 deletion lib/graphql/analysis/ast/analyzer.rb
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ def analyze?
# in a query error.
# @return [Any] The analyzer result
def result
raise NotImplementedError
raise GraphQL::RequiredImplementationMissingError
end

class << self
Expand Down
2 changes: 1 addition & 1 deletion lib/graphql/base_type.rb
Original file line number Diff line number Diff line change
Expand Up @@ -167,7 +167,7 @@ def coerce_input(value, ctx = nil)
end

def coerce_result(value, ctx)
raise NotImplementedError
raise GraphQL::RequiredImplementationMissingError
end

# Types with fields may override this
Expand Down
2 changes: 1 addition & 1 deletion lib/graphql/function.rb
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ def type

# @return [Object] This function's resolver
def call(obj, args, ctx)
raise NotImplementedError
raise GraphQL::RequiredImplementationMissingError
end

# @return [String, nil]
Expand Down
2 changes: 1 addition & 1 deletion lib/graphql/language/document_from_schema_definition.rb
Original file line number Diff line number Diff line change
Expand Up @@ -207,7 +207,7 @@ def build_default_value(default_value, type)
when ListType
default_value.to_a.map { |v| build_default_value(v, type.of_type) }
else
raise NotImplementedError, "Unexpected default value type #{type.inspect}"
raise GraphQL::RequiredImplementationMissingError, "Unexpected default value type #{type.inspect}"
end
end

Expand Down
2 changes: 1 addition & 1 deletion lib/graphql/language/nodes.rb
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ def initialize_copy(other)

# @return [Symbol] the method to call on {Language::Visitor} for this node
def visit_method
raise NotImplementedError, "#{self.class.name}#visit_method shold return a symbol"
raise GraphQL::RequiredImplementationMissingError, "#{self.class.name}#visit_method shold return a symbol"
end

def position
Expand Down
6 changes: 3 additions & 3 deletions lib/graphql/relay/base_connection.rb
Original file line number Diff line number Diff line change
Expand Up @@ -139,7 +139,7 @@ def end_cursor

# An opaque operation which returns a connection-specific cursor.
def cursor_from_node(object)
raise NotImplementedError, "must return a cursor for this object/connection pair"
raise GraphQL::RequiredImplementationMissingError, "must return a cursor for this object/connection pair"
end

def inspect
Expand All @@ -161,11 +161,11 @@ def get_limited_arg(arg_name)
end

def paged_nodes
raise NotImplementedError, "must return nodes for this connection after paging"
raise GraphQL::RequiredImplementationMissingError, "must return nodes for this connection after paging"
end

def sliced_nodes
raise NotImplementedError, "must return all nodes for this connection after chopping off first and last"
raise GraphQL::RequiredImplementationMissingError, "must return all nodes for this connection after chopping off first and last"
end
end
end
Expand Down
16 changes: 8 additions & 8 deletions lib/graphql/schema.rb
Original file line number Diff line number Diff line change
Expand Up @@ -281,13 +281,13 @@ def define(**kwargs, &block)
ensure_defined
# Assert that all necessary configs are present:
validation_error = Validation.validate(self)
validation_error && raise(NotImplementedError, validation_error)
validation_error && raise(GraphQL::RequiredImplementationMissingError, validation_error)
rebuild_artifacts

@definition_error = nil
nil
rescue StandardError => err
if @raise_definition_error || err.is_a?(CyclicalDefinitionError)
if @raise_definition_error || err.is_a?(CyclicalDefinitionError) || err.is_a?(GraphQL::RequiredImplementationMissingError)
raise
else
# Raise this error _later_ to avoid messing with Rails constant loading
Expand Down Expand Up @@ -492,7 +492,7 @@ def execution_strategy_for_operation(operation)
def resolve_type(type, object, ctx = :__undefined__)
check_resolved_type(type, object, ctx) do |ok_type, ok_object, ok_ctx|
if @resolve_type_proc.nil?
raise(NotImplementedError, "Can't determine GraphQL type for: #{ok_object.inspect}, define `resolve_type (type, obj, ctx) -> { ... }` inside `Schema.define`.")
raise(GraphQL::RequiredImplementationMissingError, "Can't determine GraphQL type for: #{ok_object.inspect}, define `resolve_type (type, obj, ctx) -> { ... }` inside `Schema.define`.")
end
@resolve_type_proc.call(ok_type, ok_object, ok_ctx)
end
Expand Down Expand Up @@ -553,7 +553,7 @@ def resolve_type=(new_resolve_type_proc)
# @return [Any] The application object identified by `id`
def object_from_id(id, ctx)
if @object_from_id_proc.nil?
raise(NotImplementedError, "Can't fetch an object for id \"#{id}\" because the schema's `object_from_id (id, ctx) -> { ... }` function is not defined")
raise(GraphQL::RequiredImplementationMissingError, "Can't fetch an object for id \"#{id}\" because the schema's `object_from_id (id, ctx) -> { ... }` function is not defined")
else
@object_from_id_proc.call(id, ctx)
end
Expand Down Expand Up @@ -620,7 +620,7 @@ def parse_error=(new_proc)
# @return [String] a unique identifier for `object` which clients can use to refetch it
def id_from_object(object, type, ctx)
if @id_from_object_proc.nil?
raise(NotImplementedError, "Can't generate an ID for #{object.inspect} of type #{type}, schema's `id_from_object` must be defined")
raise(GraphQL::RequiredImplementationMissingError, "Can't generate an ID for #{object.inspect} of type #{type}, schema's `id_from_object` must be defined")
else
@id_from_object_proc.call(object, type, ctx)
end
Expand Down Expand Up @@ -956,16 +956,16 @@ def resolve_type(type, obj, ctx)
if type.kind.object?
type
else
raise NotImplementedError, "#{self.name}.resolve_type(type, obj, ctx) must be implemented to use Union types or Interface types (tried to resolve: #{type.name})"
raise GraphQL::RequiredImplementationMissingError, "#{self.name}.resolve_type(type, obj, ctx) must be implemented to use Union types or Interface types (tried to resolve: #{type.name})"
end
end

def object_from_id(node_id, ctx)
raise NotImplementedError, "#{self.name}.object_from_id(node_id, ctx) must be implemented to load by ID (tried to load from id `#{node_id}`)"
raise GraphQL::RequiredImplementationMissingError, "#{self.name}.object_from_id(node_id, ctx) must be implemented to load by ID (tried to load from id `#{node_id}`)"
end

def id_from_object(object, type, ctx)
raise NotImplementedError, "#{self.name}.id_from_object(object, type, ctx) must be implemented to create global ids (tried to create an id for `#{object.inspect}`)"
raise GraphQL::RequiredImplementationMissingError, "#{self.name}.id_from_object(object, type, ctx) must be implemented to create global ids (tried to create an id for `#{object.inspect}`)"
end

def visible?(member, context)
Expand Down
2 changes: 1 addition & 1 deletion lib/graphql/schema/build_from_definition.rb
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,7 @@ def build(document, default_resolve: DefaultResolve)
end

NullResolveType = ->(type, obj, ctx) {
raise(NotImplementedError, "Generated Schema cannot use Interface or Union types for execution. Implement resolve_type on your resolver.")
raise(GraphQL::RequiredImplementationMissingError, "Generated Schema cannot use Interface or Union types for execution. Implement resolve_type on your resolver.")
}

NullScalarCoerce = ->(val, _ctx) { val }
Expand Down
2 changes: 1 addition & 1 deletion lib/graphql/schema/directive/feature.rb
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ def self.include?(object, arguments, context)
# @param context [GraphQL::Query::Context]
# @return [Boolean] If truthy, execution will continue
def self.enabled?(flag_name, object, context)
raise NotImplementedError, "Implement `.enabled?(flag_name, object, context)` to return true or false for the feature flag (#{flag_name.inspect})"
raise GraphQL::RequiredImplementationMissingError, "Implement `.enabled?(flag_name, object, context)` to return true or false for the feature flag (#{flag_name.inspect})"
end
end
end
Expand Down
2 changes: 1 addition & 1 deletion lib/graphql/schema/field.rb
Original file line number Diff line number Diff line change
Expand Up @@ -582,7 +582,7 @@ def fetch_extra(extra_name, ctx)
elsif ctx.respond_to?(extra_name)
ctx.public_send(extra_name)
else
raise NotImplementedError, "Unknown field extra for #{self.path}: #{extra_name.inspect}"
raise GraphQL::RequiredImplementationMissingError, "Unknown field extra for #{self.path}: #{extra_name.inspect}"
end
end

Expand Down
6 changes: 3 additions & 3 deletions lib/graphql/schema/loader.rb
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ def load(introspection_result)
end

NullResolveType = ->(type, obj, ctx) {
raise(NotImplementedError, "This schema was loaded from string, so it can't resolve types for objects")
raise(GraphQL::RequiredImplementationMissingError, "This schema was loaded from string, so it can't resolve types for objects")
}

NullScalarCoerce = ->(val, _ctx) { val }
Expand All @@ -51,7 +51,7 @@ def resolve_type(types, type)
when "NON_NULL"
NonNullType.new(of_type: resolve_type(types, type.fetch("ofType")))
else
fail NotImplementedError, "#{kind} not implemented"
fail GraphQL::RequiredImplementationMissingError, "#{kind} not implemented"
end
end

Expand Down Expand Up @@ -171,7 +171,7 @@ def define_type(type, type_resolver)
}
)
else
fail NotImplementedError, "#{type["kind"]} not implemented"
fail GraphQL::RequiredImplementationMissingError, "#{type["kind"]} not implemented"
end
end
end
Expand Down
4 changes: 2 additions & 2 deletions lib/graphql/schema/member/base_dsl_methods.rb
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ def mutation(mutation_class = nil)

# @return [GraphQL::BaseType] Convert this type to a legacy-style object.
def to_graphql
raise NotImplementedError
raise GraphQL::RequiredImplementationMissingError
end

alias :unwrap :itself
Expand All @@ -88,7 +88,7 @@ def overridden_graphql_name
# without any namespaces and with any `-Type` suffix removed
def default_graphql_name
@default_graphql_name ||= begin
raise NotImplementedError, 'Anonymous class should declare a `graphql_name`' if name.nil?
raise GraphQL::RequiredImplementationMissingError, 'Anonymous class should declare a `graphql_name`' if name.nil?

name.split("::").last.sub(/Type\Z/, "")
end
Expand Down
2 changes: 1 addition & 1 deletion lib/graphql/schema/member/type_system_helpers.rb
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ def to_type_signature

# @return [GraphQL::TypeKinds::TypeKind]
def kind
raise NotImplementedError
raise GraphQL::RequiredImplementationMissingError
end
end
end
Expand Down
2 changes: 1 addition & 1 deletion lib/graphql/schema/resolver.rb
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ def resolve_with_support(**args)
# Do the work. Everything happens here.
# @return [Object] An object corresponding to the return type
def resolve(**args)
raise NotImplementedError, "#{self.class.name}#resolve should execute the field's logic"
raise GraphQL::RequiredImplementationMissingError, "#{self.class.name}#resolve should execute the field's logic"
end

# Called before arguments are prepared.
Expand Down
2 changes: 1 addition & 1 deletion lib/graphql/schema/wrapper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ def initialize(of_type)
end

def to_graphql
raise NotImplementedError
raise GraphQL::RequiredImplementationMissingError
end

def unwrap
Expand Down
10 changes: 5 additions & 5 deletions lib/graphql/subscriptions.rb
Original file line number Diff line number Diff line change
Expand Up @@ -124,15 +124,15 @@ def execute_all(event, object)
# @yieldparam subscription_id [String]
# @return [void]
def each_subscription_id(event)
raise NotImplementedError
raise GraphQL::RequiredImplementationMissingError
end

# The system wants to send an update to this subscription.
# Read its data and return it.
# @param subscription_id [String]
# @return [Hash] Containing required keys
def read_subscription(subscription_id)
raise NotImplementedError
raise GraphQL::RequiredImplementationMissingError
end

# A subscription query was re-evaluated, returning `result`.
Expand All @@ -141,7 +141,7 @@ def read_subscription(subscription_id)
# @param result [Hash]
# @return [void]
def deliver(subscription_id, result)
raise NotImplementedError
raise GraphQL::RequiredImplementationMissingError
end

# `query` was executed and found subscriptions to `events`.
Expand All @@ -150,15 +150,15 @@ def deliver(subscription_id, result)
# @param events [Array<GraphQL::Subscriptions::Event>]
# @return [void]
def write_subscription(query, events)
raise NotImplementedError
raise GraphQL::RequiredImplementationMissingError
end

# A subscription was terminated server-side.
# Clean up the database.
# @param subscription_id [String]
# @return void.
def delete_subscription(subscription_id)
raise NotImplementedError
raise GraphQL::RequiredImplementationMissingError
end

# @return [String] A new unique identifier for a subscription
Expand Down
2 changes: 1 addition & 1 deletion lib/graphql/upgrader/member.rb
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ class Transform
# @param input_text [String] Untransformed GraphQL-Ruby code
# @return [String] The input text, with a transformation applied if necessary
def apply(input_text)
raise NotImplementedError, "Return transformed text here"
raise GraphQL::RequiredImplementationMissingError, "Return transformed text here"
end

# Recursively transform a `.define`-DSL-based type expression into a class-ready expression, for example:
Expand Down
8 changes: 4 additions & 4 deletions spec/graphql/authorization_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -491,7 +491,7 @@ def auth_execute(*args)
assert_equal ["Field 'doHiddenStuff' doesn't exist on type 'Mutation'"], res["errors"].map { |e| e["message"] }

# `#resolve` isn't implemented, so this errors out:
assert_raises NotImplementedError do
assert_raises GraphQL::RequiredImplementationMissingError do
auth_execute(query)
end

Expand All @@ -516,7 +516,7 @@ def auth_execute(*args)
assert_equal ["Field 'doHiddenStuff2' doesn't exist on type 'Mutation'"], res["errors"].map { |e| e["message"] }

# `#resolve` isn't implemented, so this errors out:
assert_raises NotImplementedError do
assert_raises GraphQL::RequiredImplementationMissingError do
auth_execute(query)
end
end
Expand Down Expand Up @@ -648,7 +648,7 @@ def auth_execute(*args)
res = auth_execute(query, context: { inaccessible_mutation: true })
assert_equal ["Some fields in this query are not accessible: doInaccessibleStuff"], res["errors"].map { |e| e["message"] }

assert_raises NotImplementedError do
assert_raises GraphQL::RequiredImplementationMissingError do
auth_execute(query)
end
end
Expand Down Expand Up @@ -682,7 +682,7 @@ def auth_execute(*args)
query = "mutation { doUnauthorizedStuff(input: {}) { __typename } }"
res = auth_execute(query, context: { unauthorized_mutation: true })
assert_nil res["data"].fetch("doUnauthorizedStuff")
assert_raises NotImplementedError do
assert_raises GraphQL::RequiredImplementationMissingError do
auth_execute(query)
end
end
Expand Down
2 changes: 1 addition & 1 deletion spec/graphql/function_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ def call(o, a, c)
assert_equal(nil, default_func.type)
assert_equal(nil, default_func.description)
assert_equal(nil, default_func.deprecation_reason)
assert_raises(NotImplementedError) {
assert_raises(GraphQL::RequiredImplementationMissingError) {
default_func.call(nil, nil, nil)
}
end
Expand Down
2 changes: 1 addition & 1 deletion spec/graphql/schema/object_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@

it "raise on anonymous class without declared graphql name" do
anonymous_class = Class.new(GraphQL::Schema::Object)
assert_raises NotImplementedError do
assert_raises GraphQL::RequiredImplementationMissingError do
anonymous_class.graphql_name
end
end
Expand Down
2 changes: 1 addition & 1 deletion spec/graphql/schema/validation_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -371,7 +371,7 @@ def assert_validation_warns(object, warning)
end
}
it "finds instrumenters missing methods" do
err = assert_raises(NotImplementedError) { schema }
err = assert_raises(GraphQL::RequiredImplementationMissingError) { schema }
assert_includes err.message, "before_query(query)"
assert_includes err.message, "instrument(type, field)"
end
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -254,7 +254,7 @@ def self.object_from_id(id, query_ctx)
def self.resolve_type(type, obj, ctx)
# TODO: Implement this function
# to return the correct type for `obj`
raise(NotImplementedError)
raise(GraphQL::RequiredImplementationMissingError)
end
# GraphQL::Batch setup:
Expand Down
Loading

0 comments on commit 35dc19b

Please sign in to comment.