graphql 1.9.0 → 1.9.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: fb79bf185d3d89d53f50ad5f0ae1cc93e3480acb
4
- data.tar.gz: 46c04d4e296ea2b3b520d6df50f82d76da5ec641
3
+ metadata.gz: 31138f73214b24b895b8717ef50dcc39c61c6e45
4
+ data.tar.gz: 1c105034b3b21b0dd732e1143acbf54538fc54ef
5
5
  SHA512:
6
- metadata.gz: 78e070c3df4abd9e2d649ba0e5f1e7fdcef9b0241572a30bf233d516fa28b7eee9afa0fd2d650db835556dff87f4eddb344aefce8825019569aa7e55ff28f780
7
- data.tar.gz: eb138cb5d2274c815ea42ec2eff4371cf34023ad817e4009302cb6de6da7deea213ccfaa2169d86a6a8c2b684f9e4fc8bd0780060163a764960d22af1a48bb25
6
+ metadata.gz: fc6e63617dc34dd096a3b279ec3f2a2f476f3a8032bfcf4008bccc9e6c3f1c3f45e23d0d43e2dc0b7798376424e2f196ee71e65cd365cb89c9384a89b6e1c39e
7
+ data.tar.gz: 07cbfa84015057a980b90820470e721352db0f42f85ab985312e01787328f0fef448ac6d774e08a625c88388246f5276352da72514be18f1e24c6468f5438f9d
@@ -201,7 +201,8 @@ module GraphQL
201
201
  loaded_application_object = object_from_id(lookup_as_type, id, context)
202
202
  context.schema.after_lazy(loaded_application_object) do |application_object|
203
203
  if application_object.nil?
204
- raise LoadApplicationObjectFailedError.new(argument: argument, id: id, object: application_object)
204
+ err = LoadApplicationObjectFailedError.new(argument: argument, id: id, object: application_object)
205
+ load_application_object_failed(err)
205
206
  end
206
207
  # Double-check that the located object is actually of this type
207
208
  # (Don't want to allow arbitrary access to objects this way)
@@ -209,7 +210,8 @@ module GraphQL
209
210
  context.schema.after_lazy(resolved_application_object_type) do |application_object_type|
210
211
  possible_object_types = context.schema.possible_types(lookup_as_type)
211
212
  if !possible_object_types.include?(application_object_type)
212
- raise LoadApplicationObjectFailedError.new(argument: argument, id: id, object: application_object)
213
+ err = LoadApplicationObjectFailedError.new(argument: argument, id: id, object: application_object)
214
+ load_application_object_failed(err)
213
215
  else
214
216
  # This object was loaded successfully
215
217
  # and resolved to the right type,
@@ -232,9 +234,6 @@ module GraphQL
232
234
  end
233
235
  end
234
236
  end
235
- rescue LoadApplicationObjectFailedError => err
236
- # pass it to a handler
237
- load_application_object_failed(err)
238
237
  end
239
238
 
240
239
  def load_application_object_failed(err)
@@ -1,4 +1,4 @@
1
1
  # frozen_string_literal: true
2
2
  module GraphQL
3
- VERSION = "1.9.0"
3
+ VERSION = "1.9.1"
4
4
  end
@@ -171,11 +171,15 @@ describe GraphQL::Schema::Resolver do
171
171
  include GraphQL::Schema::Interface
172
172
  field :value, Integer, null: false
173
173
  def self.resolve_type(obj, ctx)
174
- if obj.is_a?(Integer)
175
- IntegerWrapper
176
- else
177
- raise "Unexpected: #{obj.inspect}"
178
- end
174
+ LazyBlock.new {
175
+ if obj.is_a?(Integer)
176
+ IntegerWrapper
177
+ elsif obj == :resolve_type_as_wrong_type
178
+ GraphQL::Types::String
179
+ else
180
+ raise "Unexpected: #{obj.inspect}"
181
+ end
182
+ }
179
183
  end
180
184
  end
181
185
 
@@ -218,6 +222,30 @@ describe GraphQL::Schema::Resolver do
218
222
  end
219
223
  end
220
224
 
225
+ class ResolverWithErrorHandler < BaseResolver
226
+ argument :int, ID, required: true, loads: HasValue
227
+ type HasValue, null: true
228
+ def object_from_id(type, id, ctx)
229
+ LazyBlock.new {
230
+ if id == "failed_to_find"
231
+ nil
232
+ elsif id == "resolve_type_as_wrong_type"
233
+ :resolve_type_as_wrong_type
234
+ else
235
+ id.length
236
+ end
237
+ }
238
+ end
239
+
240
+ def resolve(int:)
241
+ int * 4
242
+ end
243
+
244
+ def load_application_object_failed(err)
245
+ raise GraphQL::ExecutionError.new("ResolverWithErrorHandler failed for id: #{err.id.inspect} (#{err.object.inspect}) (#{err.class.name})")
246
+ end
247
+ end
248
+
221
249
  class PrepResolver10 < BaseResolver
222
250
  argument :int1, Integer, required: true
223
251
  argument :int2, Integer, required: true, as: :integer_2
@@ -356,6 +384,7 @@ describe GraphQL::Schema::Resolver do
356
384
  field :prep_resolver_12, resolver: PrepResolver12
357
385
  field :prep_resolver_13, resolver: PrepResolver13
358
386
  field :prep_resolver_14, resolver: PrepResolver14
387
+ field :resolver_with_error_handler, resolver: ResolverWithErrorHandler
359
388
  end
360
389
 
361
390
  class Schema < GraphQL::Schema
@@ -433,6 +462,51 @@ describe GraphQL::Schema::Resolver do
433
462
  end
434
463
  end
435
464
 
465
+ describe "load_application_object_failed hook" do
466
+ it "isn't called for successful queries" do
467
+ query_str = <<-GRAPHQL
468
+ {
469
+ resolverWithErrorHandler(int: "abcd") { value }
470
+ }
471
+ GRAPHQL
472
+
473
+ res = exec_query(query_str)
474
+ assert_equal 16, res["data"]["resolverWithErrorHandler"]["value"]
475
+ refute res.key?("errors")
476
+ end
477
+
478
+ describe "when the id doesn't find anything" do
479
+ it "passes an error to the handler" do
480
+ query_str = <<-GRAPHQL
481
+ {
482
+ resolverWithErrorHandler(int: "failed_to_find") { value }
483
+ }
484
+ GRAPHQL
485
+
486
+ res = exec_query(query_str)
487
+ assert_nil res["data"].fetch("resolverWithErrorHandler")
488
+ expected_err = "ResolverWithErrorHandler failed for id: \"failed_to_find\" (nil) (GraphQL::Schema::Resolver::LoadApplicationObjectFailedError)"
489
+ assert_equal [expected_err], res["errors"].map { |e| e["message"] }
490
+ end
491
+ end
492
+
493
+ describe "when resolve_type returns a no-good type" do
494
+ it "calls the handler" do
495
+ query_str = <<-GRAPHQL
496
+ {
497
+ resolverWithErrorHandler(int: "resolve_type_as_wrong_type") { value }
498
+ }
499
+ GRAPHQL
500
+
501
+ res = exec_query(query_str)
502
+ assert_nil res["data"].fetch("resolverWithErrorHandler")
503
+ expected_err = "ResolverWithErrorHandler failed for id: \"resolve_type_as_wrong_type\" (:resolve_type_as_wrong_type) (GraphQL::Schema::Resolver::LoadApplicationObjectFailedError)"
504
+ assert_equal [expected_err], res["errors"].map { |e| e["message"] }
505
+ end
506
+ end
507
+ end
508
+
509
+
436
510
  describe "extras" do
437
511
  it "is inherited" do
438
512
  res = exec_query " { resolver4 resolver5 } ", root_value: OpenStruct.new(value: 0)
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: graphql
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.9.0
4
+ version: 1.9.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Robert Mosolgo