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
@@ -34,9 +34,6 @@
34
34
  RBRACKET = ']';
35
35
  COLON = ':';
36
36
  QUOTE = '"';
37
- BLOCK_QUOTE = '"""';
38
- ESCAPED_BLOCK_QUOTE = '\\"""';
39
- BLOCK_STRING_CHAR = (ESCAPED_BLOCK_QUOTE | ^'"""');
40
37
  ESCAPED_QUOTE = '\\"';
41
38
  STRING_CHAR = (ESCAPED_QUOTE | ^'"');
42
39
  VAR_SIGN = '$';
@@ -45,10 +42,9 @@
45
42
  EQUALS = '=';
46
43
  BANG = '!';
47
44
  PIPE = '|';
48
- AMP = '&';
49
45
 
50
46
  QUOTED_STRING = QUOTE STRING_CHAR* QUOTE;
51
- BLOCK_STRING = BLOCK_QUOTE BLOCK_STRING_CHAR* BLOCK_QUOTE;
47
+
52
48
  # catch-all for anything else. must be at the bottom for precedence.
53
49
  UNKNOWN_CHAR = /./;
54
50
 
@@ -79,15 +75,13 @@
79
75
  RBRACKET => { emit(:RBRACKET, ts, te, meta) };
80
76
  LBRACKET => { emit(:LBRACKET, ts, te, meta) };
81
77
  COLON => { emit(:COLON, ts, te, meta) };
82
- QUOTED_STRING => { emit_string(ts, te, meta, block: false) };
83
- BLOCK_STRING => { emit_string(ts, te, meta, block: true) };
78
+ QUOTED_STRING => { emit_string(ts + 1, te - 1, meta) };
84
79
  VAR_SIGN => { emit(:VAR_SIGN, ts, te, meta) };
85
80
  DIR_SIGN => { emit(:DIR_SIGN, ts, te, meta) };
86
81
  ELLIPSIS => { emit(:ELLIPSIS, ts, te, meta) };
87
82
  EQUALS => { emit(:EQUALS, ts, te, meta) };
88
83
  BANG => { emit(:BANG, ts, te, meta) };
89
84
  PIPE => { emit(:PIPE, ts, te, meta) };
90
- AMP => { emit(:AMP, ts, te, meta) };
91
85
  IDENTIFIER => { emit(:IDENTIFIER, ts, te, meta) };
92
86
  COMMENT => { record_comment(ts, te, meta) };
93
87
 
@@ -194,13 +188,8 @@ module GraphQL
194
188
  PACK_DIRECTIVE = "c*"
195
189
  UTF_8_ENCODING = "UTF-8"
196
190
 
197
- def self.emit_string(ts, te, meta, block:)
198
- quotes_length = block ? 3 : 1
199
- ts += quotes_length
200
- value = meta[:data][ts...te - quotes_length].pack(PACK_DIRECTIVE).force_encoding(UTF_8_ENCODING)
201
- if block
202
- value = GraphQL::Language::BlockString.trim_whitespace(value)
203
- end
191
+ def self.emit_string(ts, te, meta)
192
+ value = meta[:data][ts...te].pack(PACK_DIRECTIVE).force_encoding(UTF_8_ENCODING)
204
193
  if value !~ VALID_STRING
205
194
  meta[:tokens] << token = GraphQL::Language::Token.new(
206
195
  name: :BAD_UNICODE_ESCAPE,
@@ -8,16 +8,7 @@ module GraphQL
8
8
  # - `children` returns all AST nodes attached to this one. Used for tree traversal.
9
9
  # - `scalars` returns all scalar (Ruby) values attached to this one. Used for comparing nodes.
10
10
  # - `to_query_string` turns an AST node into a GraphQL string
11
-
12
11
  class AbstractNode
13
- module Scalars # :nodoc:
14
- module Name
15
- def scalars
16
- super + [name]
17
- end
18
- end
19
- end
20
-
21
12
  attr_accessor :line, :col, :filename
22
13
 
23
14
  # Initialize a node by extracting its position,
@@ -50,50 +41,79 @@ module GraphQL
50
41
 
51
42
  # @return [Array<GraphQL::Language::Nodes::AbstractNode>] all nodes in the tree below this one
52
43
  def children
53
- []
44
+ self.class.child_attributes
45
+ .map { |attr_name| public_send(attr_name) }
46
+ .flatten
54
47
  end
55
48
 
56
49
  # @return [Array<Integer, Float, String, Boolean, Array>] Scalar values attached to this node
57
50
  def scalars
58
- []
51
+ self.class.scalar_attributes
52
+ .map { |attr_name| public_send(attr_name) }
53
+ end
54
+
55
+ class << self
56
+ # A node subclass inherits `scalar_attributes`
57
+ # and `child_attributes` from its parent
58
+ def inherited(subclass)
59
+ subclass.scalar_attributes(*@scalar_attributes)
60
+ subclass.child_attributes(*@child_attributes)
61
+ end
62
+
63
+ # define `attr_names` as places where scalars may be attached to this node
64
+ def scalar_attributes(*attr_names)
65
+ @scalar_attributes ||= []
66
+ @scalar_attributes += attr_names
67
+ end
68
+
69
+ # define `attr_names` as places where child nodes may be attached to this node
70
+ def child_attributes(*attr_names)
71
+ @child_attributes ||= []
72
+ @child_attributes += attr_names
73
+ end
59
74
  end
60
75
 
61
76
  def position
62
77
  [line, col]
63
78
  end
64
79
 
65
- def to_query_string(printer: GraphQL::Language::Printer.new)
66
- printer.print(self)
80
+ def to_query_string
81
+ Generation.generate(self)
67
82
  end
68
83
  end
69
84
 
70
85
  # Base class for non-null type names and list type names
71
86
  class WrapperType < AbstractNode
72
87
  attr_accessor :of_type
88
+ scalar_attributes :of_type
73
89
 
74
90
  def initialize_node(of_type: nil)
75
91
  @of_type = of_type
76
92
  end
77
93
 
78
- def scalars
79
- [of_type]
94
+ def children
95
+ [].freeze
80
96
  end
81
97
  end
82
98
 
83
99
  # Base class for nodes whose only value is a name (no child nodes or other scalars)
84
100
  class NameOnlyNode < AbstractNode
85
- include Scalars::Name
86
-
87
101
  attr_accessor :name
102
+ scalar_attributes :name
88
103
 
89
104
  def initialize_node(name: nil)
90
105
  @name = name
91
106
  end
107
+
108
+ def children
109
+ [].freeze
110
+ end
92
111
  end
93
112
 
94
113
  # A key-value pair for a field's inputs
95
114
  class Argument < AbstractNode
96
115
  attr_accessor :name, :value
116
+ scalar_attributes :name, :value
97
117
 
98
118
  # @!attribute name
99
119
  # @return [String] the key for this argument
@@ -106,20 +126,15 @@ module GraphQL
106
126
  @value = value
107
127
  end
108
128
 
109
- def scalars
110
- [name, value]
111
- end
112
-
113
129
  def children
114
130
  [value].flatten.select { |v| v.is_a?(AbstractNode) }
115
131
  end
116
132
  end
117
133
 
118
134
  class Directive < AbstractNode
119
- include Scalars::Name
120
-
121
135
  attr_accessor :name, :arguments
122
- alias :children :arguments
136
+ scalar_attributes :name
137
+ child_attributes :arguments
123
138
 
124
139
  def initialize_node(name: nil, arguments: [])
125
140
  @name = name
@@ -128,9 +143,9 @@ module GraphQL
128
143
  end
129
144
 
130
145
  class DirectiveDefinition < AbstractNode
131
- include Scalars::Name
132
-
133
146
  attr_accessor :name, :arguments, :locations, :description
147
+ scalar_attributes :name
148
+ child_attributes :arguments, :locations
134
149
 
135
150
  def initialize_node(name: nil, arguments: [], locations: [], description: nil)
136
151
  @name = name
@@ -138,10 +153,6 @@ module GraphQL
138
153
  @locations = locations
139
154
  @description = description
140
155
  end
141
-
142
- def children
143
- arguments + locations
144
- end
145
156
  end
146
157
 
147
158
  # This is the AST root for normal queries
@@ -153,18 +164,9 @@ module GraphQL
153
164
  # document.to_query_string
154
165
  # # { ... }
155
166
  #
156
- # @example Creating a custom string from a document
157
- # class VariableScrubber < GraphQL::Language::Printer
158
- # def print_argument(arg)
159
- # "#{arg.name}: <HIDDEN>"
160
- # end
161
- # end
162
- #
163
- # document.to_query_string(printer: VariableSrubber.new)
164
- #
165
167
  class Document < AbstractNode
166
168
  attr_accessor :definitions
167
- alias :children :definitions
169
+ child_attributes :definitions
168
170
 
169
171
  # @!attribute definitions
170
172
  # @return [Array<OperationDefinition, FragmentDefinition>] top-level GraphQL units: operations or fragments
@@ -186,6 +188,8 @@ module GraphQL
186
188
  # A single selection in a GraphQL query.
187
189
  class Field < AbstractNode
188
190
  attr_accessor :name, :alias, :arguments, :directives, :selections
191
+ scalar_attributes :name, :alias
192
+ child_attributes :arguments, :directives, :selections
189
193
 
190
194
  # @!attribute selections
191
195
  # @return [Array<Nodes::Field>] Selections on this object (or empty array if this is a scalar field)
@@ -198,19 +202,13 @@ module GraphQL
198
202
  @directives = directives
199
203
  @selections = selections
200
204
  end
201
-
202
- def scalars
203
- [name, self.alias]
204
- end
205
-
206
- def children
207
- arguments + directives + selections
208
- end
209
205
  end
210
206
 
211
207
  # A reusable fragment, defined at document-level.
212
208
  class FragmentDefinition < AbstractNode
213
209
  attr_accessor :name, :type, :directives, :selections
210
+ scalar_attributes :name, :type
211
+ child_attributes :directives, :selections
214
212
 
215
213
  # @!attribute name
216
214
  # @return [String] the identifier for this fragment, which may be applied with `...#{name}`
@@ -223,22 +221,13 @@ module GraphQL
223
221
  @directives = directives
224
222
  @selections = selections
225
223
  end
226
-
227
- def children
228
- directives + selections
229
- end
230
-
231
- def scalars
232
- [name, type]
233
- end
234
224
  end
235
225
 
236
226
  # Application of a named fragment in a selection
237
227
  class FragmentSpread < AbstractNode
238
- include Scalars::Name
239
-
240
228
  attr_accessor :name, :directives
241
- alias :children :directives
229
+ scalar_attributes :name
230
+ child_attributes :directives
242
231
 
243
232
  # @!attribute name
244
233
  # @return [String] The identifier of the fragment to apply, corresponds with {FragmentDefinition#name}
@@ -252,6 +241,8 @@ module GraphQL
252
241
  # An unnamed fragment, defined directly in the query with `... { }`
253
242
  class InlineFragment < AbstractNode
254
243
  attr_accessor :type, :directives, :selections
244
+ scalar_attributes :type
245
+ child_attributes :directives, :selections
255
246
 
256
247
  # @!attribute type
257
248
  # @return [String, nil] Name of the type this fragment applies to, or `nil` if this fragment applies to any type
@@ -261,20 +252,12 @@ module GraphQL
261
252
  @directives = directives
262
253
  @selections = selections
263
254
  end
264
-
265
- def children
266
- directives + selections
267
- end
268
-
269
- def scalars
270
- [type]
271
- end
272
255
  end
273
256
 
274
257
  # A collection of key-value inputs which may be a field argument
275
258
  class InputObject < AbstractNode
276
259
  attr_accessor :arguments
277
- alias :children :arguments
260
+ child_attributes :arguments
278
261
 
279
262
  # @!attribute arguments
280
263
  # @return [Array<Nodes::Argument>] A list of key-value pairs inside this input object
@@ -295,16 +278,13 @@ module GraphQL
295
278
  private
296
279
 
297
280
  def serialize_value_for_hash(value)
298
- case value
299
- when InputObject
281
+ if value.is_a? InputObject
300
282
  value.to_h
301
- when Array
283
+ elsif value.is_a? Array
302
284
  value.map do |v|
303
285
  serialize_value_for_hash v
304
286
  end
305
- when Enum
306
- value.name
307
- when NullValue
287
+ elsif value.is_a? NullValue
308
288
  nil
309
289
  else
310
290
  value
@@ -324,6 +304,8 @@ module GraphQL
324
304
  # May be explicitly typed (eg `mutation { ... }`) or implicitly a query (eg `{ ... }`).
325
305
  class OperationDefinition < AbstractNode
326
306
  attr_accessor :operation_type, :name, :variables, :directives, :selections
307
+ scalar_attributes :operation_type, :name
308
+ child_attributes :variables, :directives, :selections
327
309
 
328
310
  # @!attribute variables
329
311
  # @return [Array<VariableDefinition>] Variable definitions for this operation
@@ -344,14 +326,6 @@ module GraphQL
344
326
  @directives = directives
345
327
  @selections = selections
346
328
  end
347
-
348
- def children
349
- variables + directives + selections
350
- end
351
-
352
- def scalars
353
- [operation_type, name]
354
- end
355
329
  end
356
330
 
357
331
  # A type name, used for variable definitions
@@ -360,6 +334,7 @@ module GraphQL
360
334
  # An operation-level query variable
361
335
  class VariableDefinition < AbstractNode
362
336
  attr_accessor :name, :type, :default_value
337
+ scalar_attributes :name, :type, :default_value
363
338
 
364
339
  # @!attribute default_value
365
340
  # @return [String, Integer, Float, Boolean, Array, NullValue] A Ruby value to use if no other value is provided
@@ -375,10 +350,6 @@ module GraphQL
375
350
  @type = type
376
351
  @default_value = default_value
377
352
  end
378
-
379
- def scalars
380
- [name, type, default_value]
381
- end
382
353
  end
383
354
 
384
355
  # Usage of a variable in a query. Name does _not_ include `$`.
@@ -386,23 +357,19 @@ module GraphQL
386
357
 
387
358
  class SchemaDefinition < AbstractNode
388
359
  attr_accessor :query, :mutation, :subscription
360
+ scalar_attributes :query, :mutation, :subscription
389
361
 
390
362
  def initialize_node(query: nil, mutation: nil, subscription: nil)
391
363
  @query = query
392
364
  @mutation = mutation
393
365
  @subscription = subscription
394
366
  end
395
-
396
- def scalars
397
- [query, mutation, subscription]
398
- end
399
367
  end
400
368
 
401
369
  class ScalarTypeDefinition < AbstractNode
402
- include Scalars::Name
403
-
404
370
  attr_accessor :name, :directives, :description
405
- alias :children :directives
371
+ scalar_attributes :name
372
+ child_attributes :directives
406
373
 
407
374
  def initialize_node(name:, directives: [], description: nil)
408
375
  @name = name
@@ -412,9 +379,9 @@ module GraphQL
412
379
  end
413
380
 
414
381
  class ObjectTypeDefinition < AbstractNode
415
- include Scalars::Name
416
-
417
382
  attr_accessor :name, :interfaces, :fields, :directives, :description
383
+ scalar_attributes :name
384
+ child_attributes :interfaces, :fields, :directives
418
385
 
419
386
  def initialize_node(name:, interfaces:, fields:, directives: [], description: nil)
420
387
  @name = name
@@ -423,15 +390,12 @@ module GraphQL
423
390
  @fields = fields
424
391
  @description = description
425
392
  end
426
-
427
- def children
428
- interfaces + fields + directives
429
- end
430
393
  end
431
394
 
432
395
  class InputValueDefinition < AbstractNode
433
396
  attr_accessor :name, :type, :default_value, :directives,:description
434
- alias :children :directives
397
+ scalar_attributes :name, :type, :default_value
398
+ child_attributes :directives
435
399
 
436
400
  def initialize_node(name:, type:, default_value: nil, directives: [], description: nil)
437
401
  @name = name
@@ -440,14 +404,12 @@ module GraphQL
440
404
  @directives = directives
441
405
  @description = description
442
406
  end
443
-
444
- def scalars
445
- [name, type, default_value]
446
- end
447
407
  end
448
408
 
449
409
  class FieldDefinition < AbstractNode
450
410
  attr_accessor :name, :arguments, :type, :directives, :description
411
+ scalar_attributes :name, :type
412
+ child_attributes :arguments, :directives
451
413
 
452
414
  def initialize_node(name:, arguments:, type:, directives: [], description: nil)
453
415
  @name = name
@@ -456,20 +418,12 @@ module GraphQL
456
418
  @directives = directives
457
419
  @description = description
458
420
  end
459
-
460
- def children
461
- arguments + directives
462
- end
463
-
464
- def scalars
465
- [name, type]
466
- end
467
421
  end
468
422
 
469
423
  class InterfaceTypeDefinition < AbstractNode
470
- include Scalars::Name
471
-
472
424
  attr_accessor :name, :fields, :directives, :description
425
+ scalar_attributes :name
426
+ child_attributes :fields, :directives
473
427
 
474
428
  def initialize_node(name:, fields:, directives: [], description: nil)
475
429
  @name = name
@@ -477,16 +431,12 @@ module GraphQL
477
431
  @directives = directives
478
432
  @description = description
479
433
  end
480
-
481
- def children
482
- fields + directives
483
- end
484
434
  end
485
435
 
486
436
  class UnionTypeDefinition < AbstractNode
487
- include Scalars::Name
488
-
489
437
  attr_accessor :name, :types, :directives, :description
438
+ scalar_attributes :name
439
+ child_attributes :types, :directives
490
440
 
491
441
  def initialize_node(name:, types:, directives: [], description: nil)
492
442
  @name = name
@@ -494,16 +444,12 @@ module GraphQL
494
444
  @directives = directives
495
445
  @description = description
496
446
  end
497
-
498
- def children
499
- types + directives
500
- end
501
447
  end
502
448
 
503
449
  class EnumTypeDefinition < AbstractNode
504
- include Scalars::Name
505
-
506
450
  attr_accessor :name, :values, :directives, :description
451
+ scalar_attributes :name
452
+ child_attributes :values, :directives
507
453
 
508
454
  def initialize_node(name:, values:, directives: [], description: nil)
509
455
  @name = name
@@ -511,17 +457,12 @@ module GraphQL
511
457
  @directives = directives
512
458
  @description = description
513
459
  end
514
-
515
- def children
516
- values + directives
517
- end
518
460
  end
519
461
 
520
462
  class EnumValueDefinition < AbstractNode
521
- include Scalars::Name
522
-
523
463
  attr_accessor :name, :directives, :description
524
- alias :children :directives
464
+ scalar_attributes :name
465
+ child_attributes :directives
525
466
 
526
467
  def initialize_node(name:, directives: [], description: nil)
527
468
  @name = name
@@ -531,10 +472,9 @@ module GraphQL
531
472
  end
532
473
 
533
474
  class InputObjectTypeDefinition < AbstractNode
534
- include Scalars::Name
535
-
536
475
  attr_accessor :name, :fields, :directives, :description
537
- alias :children :fields
476
+ scalar_attributes :name
477
+ child_attributes :fields
538
478
 
539
479
  def initialize_node(name:, fields:, directives: [], description: nil)
540
480
  @name = name