Skip to content

Commit 35dc19b

Browse files
author
Robert Mosolgo
authored
Merge pull request rmosolgo#2543 from vaihtovirta/issue-2067/replace-not-implemented-error
Issue#2067 Replace NotImplementedError with RequiredImplementationMissingError
2 parents 1c23944 + 057feb3 commit 35dc19b

25 files changed

+51
-48
lines changed

lib/generators/graphql/templates/schema.erb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ class <%= schema_name %> < GraphQL::Schema
2424
def self.resolve_type(type, obj, ctx)
2525
# TODO: Implement this function
2626
# to return the correct type for `obj`
27-
raise(NotImplementedError)
27+
raise(GraphQL::RequiredImplementationMissingError)
2828
end
2929
<% end %><% if options[:batch] %>
3030
# GraphQL::Batch setup:

lib/graphql.rb

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,9 @@ module GraphQL
1010
class Error < StandardError
1111
end
1212

13+
class RequiredImplementationMissingError < Error
14+
end
15+
1316
# Turn a query string or schema definition into an AST
1417
# @param graphql_string [String] a GraphQL query string or schema definition
1518
# @return [GraphQL::Language::Nodes::Document]

lib/graphql/analysis/ast/analyzer.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ def analyze?
2222
# in a query error.
2323
# @return [Any] The analyzer result
2424
def result
25-
raise NotImplementedError
25+
raise GraphQL::RequiredImplementationMissingError
2626
end
2727

2828
class << self

lib/graphql/base_type.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -167,7 +167,7 @@ def coerce_input(value, ctx = nil)
167167
end
168168

169169
def coerce_result(value, ctx)
170-
raise NotImplementedError
170+
raise GraphQL::RequiredImplementationMissingError
171171
end
172172

173173
# Types with fields may override this

lib/graphql/function.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ def type
4343

4444
# @return [Object] This function's resolver
4545
def call(obj, args, ctx)
46-
raise NotImplementedError
46+
raise GraphQL::RequiredImplementationMissingError
4747
end
4848

4949
# @return [String, nil]

lib/graphql/language/document_from_schema_definition.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -207,7 +207,7 @@ def build_default_value(default_value, type)
207207
when ListType
208208
default_value.to_a.map { |v| build_default_value(v, type.of_type) }
209209
else
210-
raise NotImplementedError, "Unexpected default value type #{type.inspect}"
210+
raise GraphQL::RequiredImplementationMissingError, "Unexpected default value type #{type.inspect}"
211211
end
212212
end
213213

lib/graphql/language/nodes.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@ def initialize_copy(other)
6666

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

7272
def position

lib/graphql/relay/base_connection.rb

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -139,7 +139,7 @@ def end_cursor
139139

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

145145
def inspect
@@ -161,11 +161,11 @@ def get_limited_arg(arg_name)
161161
end
162162

163163
def paged_nodes
164-
raise NotImplementedError, "must return nodes for this connection after paging"
164+
raise GraphQL::RequiredImplementationMissingError, "must return nodes for this connection after paging"
165165
end
166166

167167
def sliced_nodes
168-
raise NotImplementedError, "must return all nodes for this connection after chopping off first and last"
168+
raise GraphQL::RequiredImplementationMissingError, "must return all nodes for this connection after chopping off first and last"
169169
end
170170
end
171171
end

lib/graphql/schema.rb

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -281,13 +281,13 @@ def define(**kwargs, &block)
281281
ensure_defined
282282
# Assert that all necessary configs are present:
283283
validation_error = Validation.validate(self)
284-
validation_error && raise(NotImplementedError, validation_error)
284+
validation_error && raise(GraphQL::RequiredImplementationMissingError, validation_error)
285285
rebuild_artifacts
286286

287287
@definition_error = nil
288288
nil
289289
rescue StandardError => err
290-
if @raise_definition_error || err.is_a?(CyclicalDefinitionError)
290+
if @raise_definition_error || err.is_a?(CyclicalDefinitionError) || err.is_a?(GraphQL::RequiredImplementationMissingError)
291291
raise
292292
else
293293
# Raise this error _later_ to avoid messing with Rails constant loading
@@ -492,7 +492,7 @@ def execution_strategy_for_operation(operation)
492492
def resolve_type(type, object, ctx = :__undefined__)
493493
check_resolved_type(type, object, ctx) do |ok_type, ok_object, ok_ctx|
494494
if @resolve_type_proc.nil?
495-
raise(NotImplementedError, "Can't determine GraphQL type for: #{ok_object.inspect}, define `resolve_type (type, obj, ctx) -> { ... }` inside `Schema.define`.")
495+
raise(GraphQL::RequiredImplementationMissingError, "Can't determine GraphQL type for: #{ok_object.inspect}, define `resolve_type (type, obj, ctx) -> { ... }` inside `Schema.define`.")
496496
end
497497
@resolve_type_proc.call(ok_type, ok_object, ok_ctx)
498498
end
@@ -553,7 +553,7 @@ def resolve_type=(new_resolve_type_proc)
553553
# @return [Any] The application object identified by `id`
554554
def object_from_id(id, ctx)
555555
if @object_from_id_proc.nil?
556-
raise(NotImplementedError, "Can't fetch an object for id \"#{id}\" because the schema's `object_from_id (id, ctx) -> { ... }` function is not defined")
556+
raise(GraphQL::RequiredImplementationMissingError, "Can't fetch an object for id \"#{id}\" because the schema's `object_from_id (id, ctx) -> { ... }` function is not defined")
557557
else
558558
@object_from_id_proc.call(id, ctx)
559559
end
@@ -620,7 +620,7 @@ def parse_error=(new_proc)
620620
# @return [String] a unique identifier for `object` which clients can use to refetch it
621621
def id_from_object(object, type, ctx)
622622
if @id_from_object_proc.nil?
623-
raise(NotImplementedError, "Can't generate an ID for #{object.inspect} of type #{type}, schema's `id_from_object` must be defined")
623+
raise(GraphQL::RequiredImplementationMissingError, "Can't generate an ID for #{object.inspect} of type #{type}, schema's `id_from_object` must be defined")
624624
else
625625
@id_from_object_proc.call(object, type, ctx)
626626
end
@@ -956,16 +956,16 @@ def resolve_type(type, obj, ctx)
956956
if type.kind.object?
957957
type
958958
else
959-
raise NotImplementedError, "#{self.name}.resolve_type(type, obj, ctx) must be implemented to use Union types or Interface types (tried to resolve: #{type.name})"
959+
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})"
960960
end
961961
end
962962

963963
def object_from_id(node_id, ctx)
964-
raise NotImplementedError, "#{self.name}.object_from_id(node_id, ctx) must be implemented to load by ID (tried to load from id `#{node_id}`)"
964+
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}`)"
965965
end
966966

967967
def id_from_object(object, type, ctx)
968-
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}`)"
968+
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}`)"
969969
end
970970

971971
def visible?(member, context)

lib/graphql/schema/build_from_definition.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -111,7 +111,7 @@ def build(document, default_resolve: DefaultResolve)
111111
end
112112

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

117117
NullScalarCoerce = ->(val, _ctx) { val }

lib/graphql/schema/directive/feature.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ def self.include?(object, arguments, context)
5858
# @param context [GraphQL::Query::Context]
5959
# @return [Boolean] If truthy, execution will continue
6060
def self.enabled?(flag_name, object, context)
61-
raise NotImplementedError, "Implement `.enabled?(flag_name, object, context)` to return true or false for the feature flag (#{flag_name.inspect})"
61+
raise GraphQL::RequiredImplementationMissingError, "Implement `.enabled?(flag_name, object, context)` to return true or false for the feature flag (#{flag_name.inspect})"
6262
end
6363
end
6464
end

lib/graphql/schema/field.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -582,7 +582,7 @@ def fetch_extra(extra_name, ctx)
582582
elsif ctx.respond_to?(extra_name)
583583
ctx.public_send(extra_name)
584584
else
585-
raise NotImplementedError, "Unknown field extra for #{self.path}: #{extra_name.inspect}"
585+
raise GraphQL::RequiredImplementationMissingError, "Unknown field extra for #{self.path}: #{extra_name.inspect}"
586586
end
587587
end
588588

lib/graphql/schema/loader.rb

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ def load(introspection_result)
3434
end
3535

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

4040
NullScalarCoerce = ->(val, _ctx) { val }
@@ -51,7 +51,7 @@ def resolve_type(types, type)
5151
when "NON_NULL"
5252
NonNullType.new(of_type: resolve_type(types, type.fetch("ofType")))
5353
else
54-
fail NotImplementedError, "#{kind} not implemented"
54+
fail GraphQL::RequiredImplementationMissingError, "#{kind} not implemented"
5555
end
5656
end
5757

@@ -171,7 +171,7 @@ def define_type(type, type_resolver)
171171
}
172172
)
173173
else
174-
fail NotImplementedError, "#{type["kind"]} not implemented"
174+
fail GraphQL::RequiredImplementationMissingError, "#{type["kind"]} not implemented"
175175
end
176176
end
177177
end

lib/graphql/schema/member/base_dsl_methods.rb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,7 @@ def mutation(mutation_class = nil)
7474

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

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

9393
name.split("::").last.sub(/Type\Z/, "")
9494
end

lib/graphql/schema/member/type_system_helpers.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ def to_type_signature
3030

3131
# @return [GraphQL::TypeKinds::TypeKind]
3232
def kind
33-
raise NotImplementedError
33+
raise GraphQL::RequiredImplementationMissingError
3434
end
3535
end
3636
end

lib/graphql/schema/resolver.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -103,7 +103,7 @@ def resolve_with_support(**args)
103103
# Do the work. Everything happens here.
104104
# @return [Object] An object corresponding to the return type
105105
def resolve(**args)
106-
raise NotImplementedError, "#{self.class.name}#resolve should execute the field's logic"
106+
raise GraphQL::RequiredImplementationMissingError, "#{self.class.name}#resolve should execute the field's logic"
107107
end
108108

109109
# Called before arguments are prepared.

lib/graphql/schema/wrapper.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ def initialize(of_type)
1414
end
1515

1616
def to_graphql
17-
raise NotImplementedError
17+
raise GraphQL::RequiredImplementationMissingError
1818
end
1919

2020
def unwrap

lib/graphql/subscriptions.rb

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -124,15 +124,15 @@ def execute_all(event, object)
124124
# @yieldparam subscription_id [String]
125125
# @return [void]
126126
def each_subscription_id(event)
127-
raise NotImplementedError
127+
raise GraphQL::RequiredImplementationMissingError
128128
end
129129

130130
# The system wants to send an update to this subscription.
131131
# Read its data and return it.
132132
# @param subscription_id [String]
133133
# @return [Hash] Containing required keys
134134
def read_subscription(subscription_id)
135-
raise NotImplementedError
135+
raise GraphQL::RequiredImplementationMissingError
136136
end
137137

138138
# A subscription query was re-evaluated, returning `result`.
@@ -141,7 +141,7 @@ def read_subscription(subscription_id)
141141
# @param result [Hash]
142142
# @return [void]
143143
def deliver(subscription_id, result)
144-
raise NotImplementedError
144+
raise GraphQL::RequiredImplementationMissingError
145145
end
146146

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

156156
# A subscription was terminated server-side.
157157
# Clean up the database.
158158
# @param subscription_id [String]
159159
# @return void.
160160
def delete_subscription(subscription_id)
161-
raise NotImplementedError
161+
raise GraphQL::RequiredImplementationMissingError
162162
end
163163

164164
# @return [String] A new unique identifier for a subscription

lib/graphql/upgrader/member.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ class Transform
1313
# @param input_text [String] Untransformed GraphQL-Ruby code
1414
# @return [String] The input text, with a transformation applied if necessary
1515
def apply(input_text)
16-
raise NotImplementedError, "Return transformed text here"
16+
raise GraphQL::RequiredImplementationMissingError, "Return transformed text here"
1717
end
1818

1919
# Recursively transform a `.define`-DSL-based type expression into a class-ready expression, for example:

spec/graphql/authorization_spec.rb

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -491,7 +491,7 @@ def auth_execute(*args)
491491
assert_equal ["Field 'doHiddenStuff' doesn't exist on type 'Mutation'"], res["errors"].map { |e| e["message"] }
492492

493493
# `#resolve` isn't implemented, so this errors out:
494-
assert_raises NotImplementedError do
494+
assert_raises GraphQL::RequiredImplementationMissingError do
495495
auth_execute(query)
496496
end
497497

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

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

651-
assert_raises NotImplementedError do
651+
assert_raises GraphQL::RequiredImplementationMissingError do
652652
auth_execute(query)
653653
end
654654
end
@@ -682,7 +682,7 @@ def auth_execute(*args)
682682
query = "mutation { doUnauthorizedStuff(input: {}) { __typename } }"
683683
res = auth_execute(query, context: { unauthorized_mutation: true })
684684
assert_nil res["data"].fetch("doUnauthorizedStuff")
685-
assert_raises NotImplementedError do
685+
assert_raises GraphQL::RequiredImplementationMissingError do
686686
auth_execute(query)
687687
end
688688
end

spec/graphql/function_spec.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ def call(o, a, c)
5454
assert_equal(nil, default_func.type)
5555
assert_equal(nil, default_func.description)
5656
assert_equal(nil, default_func.deprecation_reason)
57-
assert_raises(NotImplementedError) {
57+
assert_raises(GraphQL::RequiredImplementationMissingError) {
5858
default_func.call(nil, nil, nil)
5959
}
6060
end

spec/graphql/schema/object_spec.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@
5555

5656
it "raise on anonymous class without declared graphql name" do
5757
anonymous_class = Class.new(GraphQL::Schema::Object)
58-
assert_raises NotImplementedError do
58+
assert_raises GraphQL::RequiredImplementationMissingError do
5959
anonymous_class.graphql_name
6060
end
6161
end

spec/graphql/schema/validation_spec.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -371,7 +371,7 @@ def assert_validation_warns(object, warning)
371371
end
372372
}
373373
it "finds instrumenters missing methods" do
374-
err = assert_raises(NotImplementedError) { schema }
374+
err = assert_raises(GraphQL::RequiredImplementationMissingError) { schema }
375375
assert_includes err.message, "before_query(query)"
376376
assert_includes err.message, "instrument(type, field)"
377377
end

spec/integration/rails/generators/graphql/install_generator_spec.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -254,7 +254,7 @@ def self.object_from_id(id, query_ctx)
254254
def self.resolve_type(type, obj, ctx)
255255
# TODO: Implement this function
256256
# to return the correct type for `obj`
257-
raise(NotImplementedError)
257+
raise(GraphQL::RequiredImplementationMissingError)
258258
end
259259
260260
# GraphQL::Batch setup:

0 commit comments

Comments
 (0)