graphql 1.9.1 → 1.9.2

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: 31138f73214b24b895b8717ef50dcc39c61c6e45
4
- data.tar.gz: 1c105034b3b21b0dd732e1143acbf54538fc54ef
3
+ metadata.gz: dfc72228ed2ce65697195792c7e58ff2c061435d
4
+ data.tar.gz: 2ab1fa5308bb89c21319558620a705f5e58fbbdb
5
5
  SHA512:
6
- metadata.gz: fc6e63617dc34dd096a3b279ec3f2a2f476f3a8032bfcf4008bccc9e6c3f1c3f45e23d0d43e2dc0b7798376424e2f196ee71e65cd365cb89c9384a89b6e1c39e
7
- data.tar.gz: 07cbfa84015057a980b90820470e721352db0f42f85ab985312e01787328f0fef448ac6d774e08a625c88388246f5276352da72514be18f1e24c6468f5438f9d
6
+ metadata.gz: 650ef5ae621e294c2a5242206a0158d58970d40dfe5bace0f863a15e59a533324e2b2c623b7df0b089c2ffa8ebcc0b445b43fe5e3b6c0bb018a9a5a732c74fa2
7
+ data.tar.gz: 66d3f0113edbcf6562f9a430c59ae569bff7a9f444ced9c5e6fa2eb11a9095f192d57016126c0a69334cf6c58c8f23bffa2a5bafd83214453c205876d8a8e9f9
@@ -277,15 +277,6 @@ module GraphQL
277
277
  # Read the value
278
278
  @extensions
279
279
  else
280
- if @resolve || @function
281
- raise ArgumentError, <<-MSG
282
- Extensions are not supported with resolve procs or functions,
283
- but #{owner.name}.#{name} has: #{@resolve || @function}
284
- So, it can't have extensions: #{extensions}.
285
- Use a method or a Schema::Resolver instead.
286
- MSG
287
- end
288
-
289
280
  # Normalize to a Hash of {name => options}
290
281
  extensions_with_options = if new_extensions.last.is_a?(Hash)
291
282
  new_extensions.pop
@@ -454,12 +445,16 @@ MSG
454
445
  # @see https://github.com/rmosolgo/graphql-ruby/issues/1990 before removing
455
446
  inner_obj = after_obj && after_obj.object
456
447
  if authorized?(inner_obj, query_ctx)
448
+ ruby_args = to_ruby_args(after_obj, args, ctx)
457
449
  # Then if it passed, resolve the field
458
450
  if @resolve_proc
459
451
  # Might be nil, still want to call the func in that case
460
- @resolve_proc.call(inner_obj, args, ctx)
452
+ with_extensions(inner_obj, ruby_args, query_ctx) do |extended_obj, extended_args|
453
+ # Pass the GraphQL args here for compatibility:
454
+ @resolve_proc.call(extended_obj, args, ctx)
455
+ end
461
456
  else
462
- public_send_field(after_obj, args, ctx)
457
+ public_send_field(after_obj, ruby_args, ctx)
463
458
  end
464
459
  else
465
460
  err = GraphQL::UnauthorizedFieldError.new(object: inner_obj, type: obj.class, context: ctx, field: self)
@@ -568,7 +563,13 @@ MSG
568
563
 
569
564
  NO_ARGS = {}.freeze
570
565
 
571
- def public_send_field(obj, graphql_args, field_ctx)
566
+ # Convert a GraphQL arguments instance into a Ruby-style hash.
567
+ #
568
+ # @param obj [GraphQL::Schema::Object] The object where this field is being resolved
569
+ # @param graphql_args [GraphQL::Query::Arguments]
570
+ # @param field_ctx [GraphQL::Query::Context::FieldResolutionContext]
571
+ # @return [Hash<Symbol => Any>]
572
+ def to_ruby_args(obj, graphql_args, field_ctx)
572
573
  if graphql_args.any? || @extras.any?
573
574
  # Splat the GraphQL::Arguments to Ruby keyword arguments
574
575
  ruby_kwargs = graphql_args.to_kwargs
@@ -583,10 +584,14 @@ MSG
583
584
  @extras.each do |extra_arg|
584
585
  ruby_kwargs[extra_arg] = fetch_extra(extra_arg, field_ctx)
585
586
  end
587
+
588
+ ruby_kwargs
586
589
  else
587
- ruby_kwargs = NO_ARGS
590
+ NO_ARGS
588
591
  end
592
+ end
589
593
 
594
+ def public_send_field(obj, ruby_kwargs, field_ctx)
590
595
  query_ctx = field_ctx.query.context
591
596
  with_extensions(obj, ruby_kwargs, query_ctx) do |extended_obj, extended_args|
592
597
  if @resolver_class
@@ -1,4 +1,4 @@
1
1
  # frozen_string_literal: true
2
2
  module GraphQL
3
- VERSION = "1.9.1"
3
+ VERSION = "1.9.2"
4
4
  end
@@ -10,6 +10,13 @@ describe GraphQL::Execution::Lazy do
10
10
  assert_equal 3, res["data"]["int"]
11
11
  end
12
12
 
13
+ it "Works with Query.new" do
14
+ query_str = '{ int(value: 2, plus: 1) }'
15
+ query = GraphQL::Query.new(LazyHelpers::LazySchema, query_str)
16
+ res = query.result
17
+ assert_equal 3, res["data"]["int"]
18
+ end
19
+
13
20
  it "can do nested lazy values" do
14
21
  res = run_query %|
15
22
  {
@@ -57,8 +57,17 @@ describe GraphQL::Schema::Member::Scoped do
57
57
  resolver_method: :items
58
58
  field :french_items, [FrenchItem], null: false,
59
59
  resolver_method: :items
60
- field :items_connection, Item.connection_type, null: false,
61
- resolver_method: :items
60
+ if TESTING_INTERPRETER
61
+ field :items_connection, Item.connection_type, null: false,
62
+ resolver_method: :items
63
+ else
64
+ field :items_connection, Item.connection_type, null: false, resolve: ->(obj, args, ctx) {
65
+ [
66
+ OpenStruct.new(name: "Trombone"),
67
+ OpenStruct.new(name: "Paperclip"),
68
+ ]
69
+ }
70
+ end
62
71
 
63
72
  def items
64
73
  [
@@ -67,9 +76,20 @@ describe GraphQL::Schema::Member::Scoped do
67
76
  ]
68
77
  end
69
78
 
70
- field :things, [Thing], null: false
71
- def things
72
- items + [OpenStruct.new(name: "Turbine")]
79
+ if TESTING_INTERPRETER
80
+ field :things, [Thing], null: false
81
+ def things
82
+ items + [OpenStruct.new(name: "Turbine")]
83
+ end
84
+ else
85
+ # Make sure it works with resolve procs, too
86
+ field :things, [Thing], null: false, resolve: ->(obj, args, ctx) {
87
+ [
88
+ OpenStruct.new(name: "Trombone"),
89
+ OpenStruct.new(name: "Paperclip"),
90
+ OpenStruct.new(name: "Turbine"),
91
+ ]
92
+ }
73
93
  end
74
94
  end
75
95
 
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: graphql
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.9.1
4
+ version: 1.9.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Robert Mosolgo
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2019-02-13 00:00:00.000000000 Z
11
+ date: 2019-02-15 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: benchmark-ips