graphql 1.7.14 → 1.8.0.pre1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (149) hide show
  1. checksums.yaml +5 -5
  2. data/lib/generators/graphql/function_generator.rb +1 -1
  3. data/lib/generators/graphql/loader_generator.rb +1 -1
  4. data/lib/generators/graphql/mutation_generator.rb +1 -6
  5. data/lib/generators/graphql/templates/function.erb +2 -2
  6. data/lib/generators/graphql/templates/loader.erb +2 -2
  7. data/lib/graphql.rb +2 -0
  8. data/lib/graphql/argument.rb +0 -1
  9. data/lib/graphql/backwards_compatibility.rb +2 -3
  10. data/lib/graphql/base_type.rb +18 -16
  11. data/lib/graphql/compatibility/query_parser_specification.rb +0 -117
  12. data/lib/graphql/compatibility/query_parser_specification/parse_error_specification.rb +0 -14
  13. data/lib/graphql/define/assign_object_field.rb +5 -12
  14. data/lib/graphql/deprecated_dsl.rb +28 -0
  15. data/lib/graphql/directive.rb +0 -1
  16. data/lib/graphql/enum_type.rb +1 -3
  17. data/lib/graphql/execution.rb +0 -1
  18. data/lib/graphql/execution/multiplex.rb +29 -12
  19. data/lib/graphql/field.rb +5 -20
  20. data/lib/graphql/function.rb +12 -0
  21. data/lib/graphql/input_object_type.rb +1 -3
  22. data/lib/graphql/internal_representation/node.rb +14 -26
  23. data/lib/graphql/internal_representation/visit.rb +6 -3
  24. data/lib/graphql/introspection/arguments_field.rb +0 -1
  25. data/lib/graphql/introspection/enum_values_field.rb +0 -1
  26. data/lib/graphql/introspection/fields_field.rb +0 -1
  27. data/lib/graphql/introspection/input_fields_field.rb +0 -1
  28. data/lib/graphql/introspection/interfaces_field.rb +0 -1
  29. data/lib/graphql/introspection/of_type_field.rb +0 -1
  30. data/lib/graphql/introspection/possible_types_field.rb +0 -1
  31. data/lib/graphql/introspection/schema_field.rb +0 -1
  32. data/lib/graphql/introspection/type_by_name_field.rb +0 -1
  33. data/lib/graphql/introspection/typename_field.rb +0 -1
  34. data/lib/graphql/language.rb +0 -3
  35. data/lib/graphql/language/generation.rb +182 -3
  36. data/lib/graphql/language/lexer.rb +69 -144
  37. data/lib/graphql/language/lexer.rl +4 -15
  38. data/lib/graphql/language/nodes.rb +76 -136
  39. data/lib/graphql/language/parser.rb +621 -668
  40. data/lib/graphql/language/parser.y +11 -17
  41. data/lib/graphql/language/token.rb +3 -10
  42. data/lib/graphql/object_type.rb +6 -1
  43. data/lib/graphql/query.rb +13 -8
  44. data/lib/graphql/query/arguments.rb +33 -48
  45. data/lib/graphql/query/context.rb +1 -0
  46. data/lib/graphql/query/literal_input.rb +1 -4
  47. data/lib/graphql/relay/connection_resolve.rb +3 -0
  48. data/lib/graphql/relay/global_id_resolve.rb +5 -1
  49. data/lib/graphql/relay/relation_connection.rb +19 -14
  50. data/lib/graphql/schema.rb +219 -12
  51. data/lib/graphql/schema/argument.rb +33 -0
  52. data/lib/graphql/schema/build_from_definition.rb +18 -64
  53. data/lib/graphql/schema/enum.rb +76 -0
  54. data/lib/graphql/schema/field.rb +127 -0
  55. data/lib/graphql/schema/field/dynamic_resolve.rb +63 -0
  56. data/lib/graphql/schema/field/unwrapped_resolve.rb +20 -0
  57. data/lib/graphql/schema/input_object.rb +61 -0
  58. data/lib/graphql/schema/interface.rb +32 -0
  59. data/lib/graphql/schema/loader.rb +2 -2
  60. data/lib/graphql/schema/member.rb +97 -0
  61. data/lib/graphql/schema/member/build_type.rb +106 -0
  62. data/lib/graphql/schema/member/has_fields.rb +56 -0
  63. data/lib/graphql/schema/member/instrumentation.rb +113 -0
  64. data/lib/graphql/schema/member/list_type_proxy.rb +21 -0
  65. data/lib/graphql/schema/member/non_null_type_proxy.rb +21 -0
  66. data/lib/graphql/schema/object.rb +65 -0
  67. data/lib/graphql/schema/printer.rb +266 -33
  68. data/lib/graphql/schema/scalar.rb +25 -0
  69. data/lib/graphql/schema/traversal.rb +26 -17
  70. data/lib/graphql/schema/union.rb +48 -0
  71. data/lib/graphql/static_validation/rules/fields_have_appropriate_selections.rb +1 -5
  72. data/lib/graphql/static_validation/rules/fields_will_merge.rb +8 -15
  73. data/lib/graphql/static_validation/rules/variables_are_used_and_defined.rb +1 -11
  74. data/lib/graphql/subscriptions/action_cable_subscriptions.rb +5 -7
  75. data/lib/graphql/tracing.rb +0 -1
  76. data/lib/graphql/tracing/platform_tracing.rb +7 -20
  77. data/lib/graphql/tracing/scout_tracing.rb +2 -2
  78. data/lib/graphql/unresolved_type_error.rb +2 -3
  79. data/lib/graphql/version.rb +1 -1
  80. data/readme.md +1 -1
  81. data/spec/dummy/app/channels/graphql_channel.rb +1 -22
  82. data/spec/dummy/log/development.log +0 -239
  83. data/spec/dummy/log/test.log +0 -204
  84. data/spec/dummy/test/system/action_cable_subscription_test.rb +0 -4
  85. data/spec/dummy/tmp/screenshots/failures_test_it_handles_subscriptions.png +0 -0
  86. data/spec/generators/graphql/function_generator_spec.rb +0 -26
  87. data/spec/generators/graphql/loader_generator_spec.rb +0 -24
  88. data/spec/graphql/analysis/max_query_complexity_spec.rb +3 -3
  89. data/spec/graphql/analysis/max_query_depth_spec.rb +3 -3
  90. data/spec/graphql/backtrace_spec.rb +0 -10
  91. data/spec/graphql/base_type_spec.rb +5 -19
  92. data/spec/graphql/boolean_type_spec.rb +3 -3
  93. data/spec/graphql/directive_spec.rb +1 -3
  94. data/spec/graphql/enum_type_spec.rb +5 -18
  95. data/spec/graphql/execution/execute_spec.rb +1 -1
  96. data/spec/graphql/execution/multiplex_spec.rb +2 -2
  97. data/spec/graphql/float_type_spec.rb +2 -2
  98. data/spec/graphql/id_type_spec.rb +1 -1
  99. data/spec/graphql/input_object_type_spec.rb +2 -15
  100. data/spec/graphql/int_type_spec.rb +2 -2
  101. data/spec/graphql/internal_representation/rewrite_spec.rb +2 -2
  102. data/spec/graphql/introspection/schema_type_spec.rb +0 -1
  103. data/spec/graphql/language/generation_spec.rb +186 -21
  104. data/spec/graphql/language/lexer_spec.rb +1 -21
  105. data/spec/graphql/language/nodes_spec.rb +12 -21
  106. data/spec/graphql/language/parser_spec.rb +1 -1
  107. data/spec/graphql/query/arguments_spec.rb +15 -37
  108. data/spec/graphql/query/serial_execution/value_resolution_spec.rb +2 -2
  109. data/spec/graphql/query/variables_spec.rb +1 -1
  110. data/spec/graphql/query_spec.rb +5 -31
  111. data/spec/graphql/rake_task_spec.rb +1 -3
  112. data/spec/graphql/relay/base_connection_spec.rb +1 -1
  113. data/spec/graphql/relay/connection_instrumentation_spec.rb +2 -2
  114. data/spec/graphql/relay/connection_resolve_spec.rb +1 -1
  115. data/spec/graphql/relay/connection_type_spec.rb +1 -1
  116. data/spec/graphql/relay/mutation_spec.rb +3 -3
  117. data/spec/graphql/relay/relation_connection_spec.rb +1 -65
  118. data/spec/graphql/schema/build_from_definition_spec.rb +4 -86
  119. data/spec/graphql/schema/enum_spec.rb +60 -0
  120. data/spec/graphql/schema/field_spec.rb +14 -0
  121. data/spec/graphql/schema/input_object_spec.rb +43 -0
  122. data/spec/graphql/schema/interface_spec.rb +98 -0
  123. data/spec/graphql/schema/object_spec.rb +119 -0
  124. data/spec/graphql/schema/printer_spec.rb +15 -92
  125. data/spec/graphql/schema/scalar_spec.rb +40 -0
  126. data/spec/graphql/schema/union_spec.rb +35 -0
  127. data/spec/graphql/schema/validation_spec.rb +1 -1
  128. data/spec/graphql/schema/warden_spec.rb +11 -11
  129. data/spec/graphql/schema_spec.rb +25 -23
  130. data/spec/graphql/static_validation/rules/fields_have_appropriate_selections_spec.rb +2 -10
  131. data/spec/graphql/static_validation/rules/fields_will_merge_spec.rb +2 -2
  132. data/spec/graphql/string_type_spec.rb +3 -3
  133. data/spec/graphql/subscriptions_spec.rb +1 -1
  134. data/spec/graphql/tracing/platform_tracing_spec.rb +1 -60
  135. data/spec/support/dummy/schema.rb +25 -39
  136. data/spec/support/jazz.rb +334 -0
  137. data/spec/support/lazy_helpers.rb +21 -23
  138. data/spec/support/star_wars/data.rb +7 -6
  139. data/spec/support/star_wars/schema.rb +109 -142
  140. metadata +39 -33
  141. data/lib/graphql/execution/instrumentation.rb +0 -82
  142. data/lib/graphql/language/block_string.rb +0 -47
  143. data/lib/graphql/language/document_from_schema_definition.rb +0 -277
  144. data/lib/graphql/language/printer.rb +0 -351
  145. data/lib/graphql/tracing/data_dog_tracing.rb +0 -49
  146. data/spec/graphql/execution/instrumentation_spec.rb +0 -165
  147. data/spec/graphql/language/block_string_spec.rb +0 -70
  148. data/spec/graphql/language/document_from_schema_definition_spec.rb +0 -770
  149. data/spec/graphql/language/printer_spec.rb +0 -203
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
- SHA256:
3
- metadata.gz: 1cacc586788be6d1c7d8d721f94b13332f01da66caff8f25ebfcab17c0c579c8
4
- data.tar.gz: 778cde880c6fed60de3ba35e5114031e5fe334bf730d4a58b285f1de3fa56156
2
+ SHA1:
3
+ metadata.gz: 909c3eda6b9624635a5901ceddee57a8e714a96c
4
+ data.tar.gz: 7cc0f7c57d20b6979fba3156077e7989d55d6646
5
5
  SHA512:
6
- metadata.gz: '0729de66b6906d811ae9dcecb835f65166787697189c6faf0738913910116696c65103d7354f5099f6c72dde95dc270bfcc307ac94f4aa2e18990a1604456839'
7
- data.tar.gz: e463d0e0f9ab888982d8652bc1aec4409530a146e9183387103223e25043d4811a097be4d9ef566762685f2d8d416a1b767200d6d6392ace180f98d9c0d890e9
6
+ metadata.gz: d94639f25409ba6fb4504fd9cd5fba087e717c36f88ef6329202c3f286050927ca73d67bba12313368f0aa8080af408611184b6f7bb2a4f0e24a327a76e124e7
7
+ data.tar.gz: d84a84ad71225d052113c863b69ff25cb724fc97d31db680b8eee1befe7252ee94e50ff5b4cf23018fc8460c20dc80c60075dc00f42af5138c01f1f7342af9d3
@@ -11,7 +11,7 @@ module Graphql
11
11
  source_root File.expand_path('../templates', __FILE__)
12
12
 
13
13
  def create_function_file
14
- template "function.erb", "#{options[:directory]}/functions/#{file_path}.rb"
14
+ template "function.erb", "#{options[:directory]}/functions/#{file_name}.rb"
15
15
  end
16
16
  end
17
17
  end
@@ -13,7 +13,7 @@ module Graphql
13
13
  source_root File.expand_path('../templates', __FILE__)
14
14
 
15
15
  def create_loader_file
16
- template "loader.erb", "#{options[:directory]}/loaders/#{file_path}.rb"
16
+ template "loader.erb", "#{options[:directory]}/loaders/#{file_name}.rb"
17
17
  end
18
18
  end
19
19
  end
@@ -27,12 +27,7 @@ module Graphql
27
27
  attr_reader :file_name, :mutation_name, :field_name
28
28
 
29
29
  def create_mutation_file
30
- unless @behavior == :revoke
31
- create_mutation_root_type
32
- else
33
- log :gsub, "#{options[:directory]}/types/mutation_type.rb"
34
- end
35
-
30
+ create_mutation_root_type
36
31
  template "mutation.erb", "#{options[:directory]}/mutations/#{file_name}.rb"
37
32
 
38
33
  sentinel = /name "Mutation"\s*\n/m
@@ -1,7 +1,7 @@
1
- class Functions::<%= class_name %> < GraphQL::Function
1
+ class Functions::<%= name %> < GraphQL::Function
2
2
  # Define `initialize` to store field-level options, eg
3
3
  #
4
- # field :myField, function: Functions::<%= class_name %>.new(type: MyType)
4
+ # field :myField, function: Functions::<%= name %>.new(type: MyType)
5
5
  #
6
6
  # attr_reader :type
7
7
  # def initialize(type:)
@@ -1,7 +1,7 @@
1
- class Loaders::<%= class_name %> < GraphQL::Batch::Loader
1
+ class Loaders::<%= name %> < GraphQL::Batch::Loader
2
2
  # Define `initialize` to store grouping arguments, eg
3
3
  #
4
- # Loaders::<%= class_name %>.for(group).load(value)
4
+ # Loaders::<%= name %>.for(group).load(value)
5
5
  #
6
6
  # def initialize()
7
7
  # end
data/lib/graphql.rb CHANGED
@@ -116,3 +116,5 @@ require "graphql/filter"
116
116
  require "graphql/subscriptions"
117
117
  require "graphql/parse_error"
118
118
  require "graphql/backtrace"
119
+
120
+ require "graphql/deprecated_dsl"
@@ -37,7 +37,6 @@ module GraphQL
37
37
  include GraphQL::Define::InstanceDefinable
38
38
  accepts_definitions :name, :type, :description, :default_value, :as, :prepare
39
39
  attr_accessor :type, :description, :default_value, :name, :as
40
- attr_accessor :ast_node
41
40
 
42
41
  ensure_defined(:name, :description, :default_value, :type=, :type, :as, :expose_as, :prepare)
43
42
 
@@ -12,11 +12,10 @@ module GraphQL
12
12
  # If `last`, then use the last arguments to call the function.
13
13
  def wrap_arity(callable, from:, to:, name:, last: false)
14
14
  arity = get_arity(callable)
15
- case arity
16
- when to
15
+ if arity == to || arity < 0
17
16
  # It already matches, return it as is
18
17
  callable
19
- when from
18
+ elsif arity == from
20
19
  # It has the old arity, so wrap it with an arity converter
21
20
  message ="#{name} with #{from} arguments is deprecated, it now accepts #{to} arguments, see:"
22
21
  backtrace = caller(0, 20)
@@ -15,8 +15,6 @@ module GraphQL
15
15
 
16
16
  ensure_defined(:name, :description, :introspection?, :default_scalar?)
17
17
 
18
- attr_accessor :ast_node
19
-
20
18
  def initialize
21
19
  @introspection = false
22
20
  @default_scalar = false
@@ -32,11 +30,12 @@ module GraphQL
32
30
 
33
31
  # @return [String] the name of this type, must be unique within a Schema
34
32
  attr_accessor :name
35
-
36
- def name=(name)
37
- GraphQL::NameValidator.validate!(name)
38
- @name = name
39
- end
33
+ # Future-compatible alias
34
+ # @see {GraphQL::SchemaMember}
35
+ alias :graphql_name :name
36
+ # Future-compatible alias
37
+ # @see {GraphQL::SchemaMember}
38
+ alias :graphql_definition :itself
40
39
 
41
40
  # @return [String, nil] a description for this type
42
41
  attr_accessor :description
@@ -61,9 +60,12 @@ module GraphQL
61
60
 
62
61
  # @param other [GraphQL::BaseType] compare to this object
63
62
  # @return [Boolean] are these types equivalent? (incl. non-null, list)
64
- # @see {ModifiesAnotherType#==} for override on List & NonNull types
65
63
  def ==(other)
66
- other.is_a?(GraphQL::BaseType) && self.name == other.name
64
+ if other.is_a?(GraphQL::BaseType)
65
+ self.to_s == other.to_s
66
+ else
67
+ super
68
+ end
67
69
  end
68
70
 
69
71
  # If this type is modifying an underlying type,
@@ -86,10 +88,6 @@ module GraphQL
86
88
  def unwrap
87
89
  self.of_type.unwrap
88
90
  end
89
-
90
- def ==(other)
91
- other.is_a?(ModifiesAnotherType) && other.of_type == of_type
92
- end
93
91
  end
94
92
 
95
93
  # Find out which possible type to use for `value`.
@@ -172,13 +170,17 @@ module GraphQL
172
170
  def self.resolve_related_type(type_arg)
173
171
  case type_arg
174
172
  when Proc
175
- # lazy-eval it
176
- type_arg.call
173
+ # lazy-eval it, then try again
174
+ resolve_related_type(type_arg.call)
177
175
  when String
178
176
  # Get a constant by this name
179
177
  Object.const_get(type_arg)
180
178
  else
181
- type_arg
179
+ if type_arg.respond_to?(:graphql_definition)
180
+ type_arg.graphql_definition
181
+ else
182
+ type_arg
183
+ end
182
184
  end
183
185
  end
184
186
 
@@ -67,10 +67,6 @@ module GraphQL
67
67
  nullValue: null
68
68
  nullValueInObject: {a: null, b: "b"}
69
69
  nullValueInArray: ["a", null, "b"]
70
- blockString: """
71
- Hello,
72
- World
73
- """
74
70
  )
75
71
  }
76
72
  |
@@ -104,9 +100,6 @@ module GraphQL
104
100
  assert_equal 'a', values[0]
105
101
  assert_instance_of GraphQL::Language::Nodes::NullValue, values[1]
106
102
  assert_equal 'b', values[2]
107
-
108
- block_str_value = inputs[12].value
109
- assert_equal "Hello,\n World", block_str_value
110
103
  end
111
104
 
112
105
  def test_it_doesnt_parse_nonsense_variables
@@ -123,116 +116,6 @@ module GraphQL
123
116
  end
124
117
  assert_equal [1,26], [err_2.line, err_2.col]
125
118
  end
126
-
127
- def test_enum_value_definitions_have_a_position
128
- document = parse("""
129
- enum Enum {
130
- VALUE
131
- }
132
- """)
133
-
134
- assert_equal [3, 17], document.definitions[0].values[0].position
135
- end
136
-
137
- def test_field_definitions_have_a_position
138
- document = parse("""
139
- type A {
140
- field: String
141
- }
142
- """)
143
-
144
- assert_equal [3, 17], document.definitions[0].fields[0].position
145
- end
146
-
147
- def test_input_value_definitions_have_a_position
148
- document = parse("""
149
- input A {
150
- field: String
151
- }
152
- """)
153
-
154
- assert_equal [3, 17], document.definitions[0].fields[0].position
155
- end
156
-
157
- def test_parses_when_there_are_no_interfaces
158
- schema = "
159
- type A {
160
- a: String
161
- }
162
- "
163
-
164
- document = parse(schema)
165
-
166
- assert_equal [], document.definitions[0].interfaces.map(&:name)
167
- end
168
-
169
- def test_parses_implements_with_leading_ampersand
170
- schema = "
171
- type A implements & B {
172
- a: String
173
- }
174
- "
175
-
176
- document = parse(schema)
177
-
178
- assert_equal ["B"], document.definitions[0].interfaces.map(&:name)
179
- assert_equal [2, 35], document.definitions[0].interfaces[0].position
180
- end
181
-
182
- def test_parses_implements_with_leading_ampersand_and_multiple_interfaces
183
- schema = "
184
- type A implements & B & C {
185
- a: String
186
- }
187
- "
188
-
189
- document = parse(schema)
190
-
191
- assert_equal ["B", "C"], document.definitions[0].interfaces.map(&:name)
192
- assert_equal [2, 35], document.definitions[0].interfaces[0].position
193
- assert_equal [2, 39], document.definitions[0].interfaces[1].position
194
- end
195
-
196
- def test_parses_implements_without_leading_ampersand
197
- schema = "
198
- type A implements B {
199
- a: String
200
- }
201
- "
202
-
203
- document = parse(schema)
204
-
205
- assert_equal ["B"], document.definitions[0].interfaces.map(&:name)
206
- assert_equal [2, 33], document.definitions[0].interfaces[0].position
207
- end
208
-
209
- def test_parses_implements_without_leading_ampersand_and_multiple_interfaces
210
- schema = "
211
- type A implements B & C {
212
- a: String
213
- }
214
- "
215
-
216
- document = parse(schema)
217
-
218
- assert_equal ["B", "C"], document.definitions[0].interfaces.map(&:name)
219
- assert_equal [2, 33], document.definitions[0].interfaces[0].position
220
- assert_equal [2, 37], document.definitions[0].interfaces[1].position
221
- end
222
-
223
- def test_supports_old_syntax_for_parsing_multiple_interfaces
224
- schema = "
225
- type A implements B, C {
226
- a: String
227
- }
228
- "
229
-
230
- document = parse(schema)
231
-
232
- assert_equal ["B", "C"], document.definitions[0].interfaces.map(&:name)
233
- assert_equal [2, 33], document.definitions[0].interfaces[0].position
234
- assert_equal [2, 36], document.definitions[0].interfaces[1].position
235
- end
236
119
  end
237
120
  end
238
121
 
@@ -56,20 +56,6 @@ module GraphQL
56
56
  assert_raises_parse_error(%|{ field(arg:"\\uXXXF") }|)
57
57
  end
58
58
 
59
- def test_it_rejects_empty_inline_fragments
60
- assert_raises_parse_error("
61
- query {
62
- viewer {
63
- login {
64
- ... on String {
65
-
66
- }
67
- }
68
- }
69
- }
70
- ")
71
- end
72
-
73
59
  def assert_empty_document(query_string)
74
60
  doc = parse(query_string)
75
61
  assert_equal 0, doc.definitions.length
@@ -18,23 +18,16 @@ module GraphQL
18
18
  base_field = if type_or_field.is_a?(GraphQL::Field)
19
19
  type_or_field.redefine(name: name_s)
20
20
  elsif function
21
- GraphQL::Field.define(
22
- arguments: function.arguments,
23
- complexity: function.complexity,
24
- name: name_s,
25
- type: function.type,
26
- resolve: function,
27
- description: function.description,
28
- function: function,
29
- deprecation_reason: function.deprecation_reason,
30
- )
21
+ func_field = GraphQL::Function.build_field(function)
22
+ func_field.name = name_s
23
+ func_field
31
24
  elsif field.is_a?(GraphQL::Field)
32
25
  field.redefine(name: name_s)
33
26
  else
34
27
  nil
35
28
  end
36
29
 
37
- field = if base_field
30
+ obj_field = if base_field
38
31
  base_field.redefine(kwargs, &block)
39
32
  else
40
33
  GraphQL::Field.define(kwargs, &block)
@@ -42,7 +35,7 @@ module GraphQL
42
35
 
43
36
 
44
37
  # Attach the field to the type
45
- owner_type.fields[name_s] = field
38
+ owner_type.fields[name_s] = obj_field
46
39
  end
47
40
  end
48
41
  end
@@ -0,0 +1,28 @@
1
+ # frozen_string_literal: true
2
+ module GraphQL
3
+ # There are two ways to apply the deprecated `!` DSL to class-style schema definitions:
4
+ #
5
+ # 1. Scoped by file (CRuby only), add to the top of the file:
6
+ #
7
+ # using GraphQL::DeprecatedDSL
8
+ #
9
+ # (This is a "refinement", there are also other ways to scope it.)
10
+ #
11
+ # 2. Global application, add before schema definition:
12
+ #
13
+ # GraphQL::DeprecatedDSL.activate
14
+ #
15
+ module DeprecatedDSL
16
+ def self.activate
17
+ GraphQL::Schema::Member.extend(Methods)
18
+ end
19
+ module Methods
20
+ def !
21
+ to_non_null_type
22
+ end
23
+ end
24
+ refine GraphQL::Schema::Member.singleton_class do
25
+ include Methods
26
+ end
27
+ end
28
+ end
@@ -11,7 +11,6 @@ module GraphQL
11
11
  accepts_definitions :locations, :name, :description, :arguments, :default_directive, argument: GraphQL::Define::AssignArgument
12
12
 
13
13
  attr_accessor :locations, :arguments, :name, :description, :arguments_class
14
- attr_accessor :ast_node
15
14
  # @api private
16
15
  attr_writer :default_directive
17
16
  ensure_defined(:locations, :arguments, :name, :description, :default_directive?)
@@ -74,7 +74,6 @@ module GraphQL
74
74
  class EnumType < GraphQL::BaseType
75
75
  accepts_definitions :values, value: GraphQL::Define::AssignEnumValue
76
76
  ensure_defined(:values, :validate_non_null_input, :coerce_non_null_input, :coerce_result)
77
- attr_accessor :ast_node
78
77
 
79
78
  def initialize
80
79
  super
@@ -122,7 +121,7 @@ module GraphQL
122
121
  if enum_value
123
122
  enum_value.name
124
123
  else
125
- raise(UnresolvedValueError, "Can't resolve enum #{name} for #{value.inspect}")
124
+ raise(UnresolvedValueError, "Can't resolve enum #{name} for #{value}")
126
125
  end
127
126
  end
128
127
 
@@ -138,7 +137,6 @@ module GraphQL
138
137
  ATTRIBUTES = [:name, :description, :deprecation_reason, :value]
139
138
  accepts_definitions(*ATTRIBUTES)
140
139
  attr_accessor(*ATTRIBUTES)
141
- attr_accessor :ast_node
142
140
  ensure_defined(*ATTRIBUTES)
143
141
 
144
142
  def name=(new_name)
@@ -2,7 +2,6 @@
2
2
  require "graphql/execution/directive_checks"
3
3
  require "graphql/execution/execute"
4
4
  require "graphql/execution/flatten"
5
- require "graphql/execution/instrumentation"
6
5
  require "graphql/execution/lazy"
7
6
  require "graphql/execution/multiplex"
8
7
  require "graphql/execution/typecast"
@@ -60,12 +60,12 @@ module GraphQL
60
60
  if queries.length != 1
61
61
  raise ArgumentError, "Multiplexing doesn't support custom execution strategies, run one query at a time instead"
62
62
  else
63
- instrument_and_analyze(multiplex, max_complexity: max_complexity) do
63
+ with_instrumentation(multiplex, max_complexity: max_complexity) do
64
64
  [run_one_legacy(schema, queries.first)]
65
65
  end
66
66
  end
67
67
  else
68
- instrument_and_analyze(multiplex, max_complexity: max_complexity) do
68
+ with_instrumentation(multiplex, max_complexity: max_complexity) do
69
69
  run_as_multiplex(multiplex)
70
70
  end
71
71
  end
@@ -93,7 +93,7 @@ module GraphQL
93
93
  end
94
94
  rescue StandardError
95
95
  # Assign values here so that the query's `@executed` becomes true
96
- queries.map { |q| q.result_values ||= {} }
96
+ queries.map { |q| q.result_values ||= nil }
97
97
  raise
98
98
  end
99
99
 
@@ -162,17 +162,34 @@ module GraphQL
162
162
  # Apply multiplex & query instrumentation to `queries`.
163
163
  #
164
164
  # It yields when the queries should be executed, then runs teardown.
165
- def instrument_and_analyze(multiplex, max_complexity:)
166
- GraphQL::Execution::Instrumentation.apply_instrumenters(multiplex) do
167
- schema = multiplex.schema
168
- multiplex_analyzers = schema.multiplex_analyzers
169
- if max_complexity
170
- multiplex_analyzers += [GraphQL::Analysis::MaxQueryComplexity.new(max_complexity)]
171
- end
165
+ def with_instrumentation(multiplex, max_complexity:)
166
+ schema = multiplex.schema
167
+ queries = multiplex.queries
168
+ query_instrumenters = schema.instrumenters[:query]
169
+ multiplex_instrumenters = schema.instrumenters[:multiplex]
170
+
171
+ # First, run multiplex instrumentation, then query instrumentation for each query
172
+ multiplex_instrumenters.each { |i| i.before_multiplex(multiplex) }
173
+ queries.each do |query|
174
+ query_instrumenters.each { |i| i.before_query(query) }
175
+ end
176
+
177
+ multiplex_analyzers = schema.multiplex_analyzers
178
+ if max_complexity
179
+ multiplex_analyzers += [GraphQL::Analysis::MaxQueryComplexity.new(max_complexity)]
180
+ end
181
+
182
+ GraphQL::Analysis.analyze_multiplex(multiplex, multiplex_analyzers)
172
183
 
173
- GraphQL::Analysis.analyze_multiplex(multiplex, multiplex_analyzers)
174
- yield
184
+ # Let them be executed
185
+ yield
186
+ ensure
187
+ # Finally, run teardown instrumentation for each query + the multiplex
188
+ # Use `reverse_each` so instrumenters are treated like a stack
189
+ queries.each do |query|
190
+ query_instrumenters.reverse_each { |i| i.after_query(query) }
175
191
  end
192
+ multiplex_instrumenters.reverse_each { |i| i.after_multiplex(multiplex) }
176
193
  end
177
194
  end
178
195
  end