graphql 0.18.7 → 0.18.8

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: d560175134555b76ef12afce0b9a3e71b84d71bc
4
- data.tar.gz: 47f43437b229e9abfe655804cd05e02642c17f38
3
+ metadata.gz: e3550ea852aad13e43cd451dfa44ed0889f71f9a
4
+ data.tar.gz: ce68835d73683f572b8b53529dc5f7de426b7a02
5
5
  SHA512:
6
- metadata.gz: 50032a491c2c078266193c85072d4cb3d3827bbd56c6d04318cced4b7366de5b037b0e91d2b98e98ff7617811e5118625375a4a818232a70ac4bc486a82935da
7
- data.tar.gz: d77d29e850053e7a1aa5096933790011b97acc32e4eab0d9e2450b6aedb902e5055586b17a1dc6de948c4521b429960ae51b63990ddb28ee60c22d8a8a46315c
6
+ metadata.gz: af009ae9281638daab169b41c94b6def2967a16ba2e41f667cf51d5c45a83b6aeacf0169195c651e5f2136934346a086775d65be713d4da03db429e4d41ce421
7
+ data.tar.gz: b7c1225ffe636db87a332f8ec0af465ee38b29d8269cc18485f40f22296608b1cb0ee0d69a17be58e7f28067611ebf946b1b306d1c796bb4dcf439190bc15249
@@ -4,7 +4,7 @@ module GraphQL
4
4
  def self.call(type_defn, *field_args, max_page_size: nil, **field_kwargs, &field_block)
5
5
  underlying_field = GraphQL::Define::AssignObjectField.call(type_defn, *field_args, **field_kwargs, &field_block)
6
6
  connection_field = GraphQL::Relay::ConnectionField.create(underlying_field, max_page_size: max_page_size)
7
- type_defn.fields[name.to_s] = connection_field
7
+ type_defn.fields[underlying_field.name] = connection_field
8
8
  end
9
9
  end
10
10
  end
@@ -25,6 +25,13 @@ module GraphQL
25
25
  raise NotImplementedError
26
26
  end
27
27
 
28
+ def eql?(other)
29
+ return true if equal?(other)
30
+ other.is_a?(self.class) &&
31
+ other.scalars.eql?(self.scalars) &&
32
+ other.children.eql?(self.children)
33
+ end
34
+
28
35
  # @return [GraphQL::Language::Nodes::AbstractNode] all nodes in the tree below this one
29
36
  def children
30
37
  self.class.child_attributes
@@ -32,7 +39,22 @@ module GraphQL
32
39
  .flatten
33
40
  end
34
41
 
42
+ def scalars
43
+ self.class.scalar_attributes
44
+ .map { |attr_name| public_send(attr_name) }
45
+ end
46
+
35
47
  class << self
48
+ def inherited(subclass)
49
+ subclass.scalar_attributes(*@scalar_attributes)
50
+ subclass.child_attributes(*@child_attributes)
51
+ end
52
+
53
+ def scalar_attributes(*attr_names)
54
+ @scalar_attributes ||= []
55
+ @scalar_attributes += attr_names
56
+ end
57
+
36
58
  def child_attributes(*attr_names)
37
59
  @child_attributes ||= []
38
60
  @child_attributes += attr_names
@@ -50,6 +72,8 @@ module GraphQL
50
72
 
51
73
  class WrapperType < AbstractNode
52
74
  attr_accessor :of_type
75
+ scalar_attributes :of_type
76
+
53
77
  def initialize_node(of_type: nil)
54
78
  @of_type = of_type
55
79
  end
@@ -61,6 +85,8 @@ module GraphQL
61
85
 
62
86
  class NameOnlyNode < AbstractNode
63
87
  attr_accessor :name
88
+ scalar_attributes :name
89
+
64
90
  def initialize_node(name: nil)
65
91
  @name = name
66
92
  end
@@ -73,6 +99,7 @@ module GraphQL
73
99
 
74
100
  class Argument < AbstractNode
75
101
  attr_accessor :name, :value
102
+ scalar_attributes :name, :value
76
103
 
77
104
  def initialize_node(name: nil, value: nil)
78
105
  @name = name
@@ -86,6 +113,7 @@ module GraphQL
86
113
 
87
114
  class Directive < AbstractNode
88
115
  attr_accessor :name, :arguments
116
+ scalar_attributes :name
89
117
  child_attributes :arguments
90
118
 
91
119
  def initialize_node(name: nil, arguments: [])
@@ -107,6 +135,7 @@ module GraphQL
107
135
 
108
136
  class Field < AbstractNode
109
137
  attr_accessor :name, :alias, :arguments, :directives, :selections
138
+ scalar_attributes :name, :alias
110
139
  child_attributes :arguments, :directives, :selections
111
140
 
112
141
  def initialize_node(name: nil, arguments: [], directives: [], selections: [], **kwargs)
@@ -121,6 +150,7 @@ module GraphQL
121
150
 
122
151
  class FragmentDefinition < AbstractNode
123
152
  attr_accessor :name, :type, :directives, :selections
153
+ scalar_attributes :name, :type
124
154
  child_attributes :directives, :selections
125
155
 
126
156
  def initialize_node(name: nil, type: nil, directives: [], selections: [])
@@ -133,6 +163,7 @@ module GraphQL
133
163
 
134
164
  class FragmentSpread < AbstractNode
135
165
  attr_accessor :name, :directives
166
+ scalar_attributes :name
136
167
  child_attributes :directives
137
168
 
138
169
  def initialize_node(name: nil, directives: [])
@@ -143,6 +174,7 @@ module GraphQL
143
174
 
144
175
  class InlineFragment < AbstractNode
145
176
  attr_accessor :type, :directives, :selections
177
+ scalar_attributes :type
146
178
  child_attributes :directives, :selections
147
179
 
148
180
  def initialize_node(type: nil, directives: [], selections: [])
@@ -176,6 +208,7 @@ module GraphQL
176
208
 
177
209
  class OperationDefinition < AbstractNode
178
210
  attr_accessor :operation_type, :name, :variables, :directives, :selections
211
+ scalar_attributes :operation_type, :name
179
212
  child_attributes :variables, :directives, :selections
180
213
 
181
214
  def initialize_node(operation_type: nil, name: nil, variables: [], directives: [], selections: [])
@@ -191,6 +224,8 @@ module GraphQL
191
224
 
192
225
  class VariableDefinition < AbstractNode
193
226
  attr_accessor :name, :type, :default_value
227
+ scalar_attributes :name, :type, :default_value
228
+
194
229
  def initialize_node(name: nil, type: nil, default_value: nil)
195
230
  @name = name
196
231
  @type = type
@@ -203,6 +238,8 @@ module GraphQL
203
238
 
204
239
  class SchemaDefinition < AbstractNode
205
240
  attr_accessor :query, :mutation, :subscription
241
+ scalar_attributes :query, :mutation, :subscription
242
+
206
243
  def initialize_node(query: nil, mutation: nil, subscription: nil)
207
244
  @query = query
208
245
  @mutation = mutation
@@ -214,7 +251,9 @@ module GraphQL
214
251
 
215
252
  class ObjectTypeDefinition < AbstractNode
216
253
  attr_accessor :name, :interfaces, :fields
217
- child_attributes :fields
254
+ scalar_attributes :name
255
+ child_attributes :interfaces, :fields
256
+
218
257
  def initialize_node(name:, interfaces:, fields:)
219
258
  @name = name
220
259
  @interfaces = interfaces || []
@@ -224,6 +263,8 @@ module GraphQL
224
263
 
225
264
  class InputValueDefinition < AbstractNode
226
265
  attr_accessor :name, :type, :default_value
266
+ scalar_attributes :name, :type, :default_value
267
+
227
268
  def initialize_node(name:, type:, default_value: nil)
228
269
  @name = name
229
270
  @type = type
@@ -233,7 +274,9 @@ module GraphQL
233
274
 
234
275
  class FieldDefinition < AbstractNode
235
276
  attr_accessor :name, :arguments, :type
277
+ scalar_attributes :name, :type
236
278
  child_attributes :arguments
279
+
237
280
  def initialize_node(name:, arguments:, type:)
238
281
  @name = name
239
282
  @arguments = arguments
@@ -243,7 +286,9 @@ module GraphQL
243
286
 
244
287
  class InterfaceTypeDefinition < AbstractNode
245
288
  attr_accessor :name, :fields
289
+ scalar_attributes :name
246
290
  child_attributes :fields
291
+
247
292
  def initialize_node(name:, fields:)
248
293
  @name = name
249
294
  @fields = fields
@@ -252,6 +297,9 @@ module GraphQL
252
297
 
253
298
  class UnionTypeDefinition < AbstractNode
254
299
  attr_accessor :name, :types
300
+ scalar_attributes :name
301
+ child_attributes :types
302
+
255
303
  def initialize_node(name:, types:)
256
304
  @name = name
257
305
  @types = types
@@ -260,6 +308,9 @@ module GraphQL
260
308
 
261
309
  class EnumTypeDefinition < AbstractNode
262
310
  attr_accessor :name, :values
311
+ scalar_attributes :name
312
+ child_attributes :values
313
+
263
314
  def initialize_node(name:, values:)
264
315
  @name = name
265
316
  @values = values
@@ -268,7 +319,9 @@ module GraphQL
268
319
 
269
320
  class InputObjectTypeDefinition < AbstractNode
270
321
  attr_accessor :name, :fields
322
+ scalar_attributes :name
271
323
  child_attributes :fields
324
+
272
325
  def initialize_node(name:, fields:)
273
326
  @name = name
274
327
  @fields = fields
@@ -1,3 +1,3 @@
1
1
  module GraphQL
2
- VERSION = "0.18.7"
2
+ VERSION = "0.18.8"
3
3
  end
@@ -0,0 +1,83 @@
1
+ require "spec_helper"
2
+
3
+ describe GraphQL::Language::Nodes::AbstractNode do
4
+ describe ".eql?" do
5
+ let(:document1) { GraphQL::Language::Parser.parse(query_string1) }
6
+ let(:document2) { GraphQL::Language::Parser.parse(query_string2) }
7
+
8
+ describe "large identical document" do
9
+ let(:query_string1) {%|
10
+ query getStuff($someVar: Int = 1, $anotherVar: [String!], $skipNested: Boolean! = false) @skip(if: false) {
11
+ myField: someField(someArg: $someVar, ok: 1.4) @skip(if: $anotherVar) @thing(or: "Whatever")
12
+ anotherField(someArg: [1, 2, 3]) {
13
+ nestedField
14
+ ...moreNestedFields @skip(if: $skipNested)
15
+ }
16
+ ... on OtherType @include(unless: false) {
17
+ field(arg: [{ key: "value", anotherKey: 0.9, anotherAnotherKey: WHATEVER }])
18
+ anotherField
19
+ }
20
+ ... {
21
+ id
22
+ }
23
+ }
24
+
25
+ fragment moreNestedFields on NestedType @or(something: "ok") {
26
+ anotherNestedField
27
+ }
28
+ |}
29
+ let(:query_string2) { query_string1 }
30
+
31
+ it "should be equal" do
32
+ assert document1.eql?(document2)
33
+ assert document2.eql?(document1)
34
+ end
35
+ end
36
+
37
+ describe "different operations" do
38
+ let(:query_string1) { "query { field }" }
39
+ let(:query_string2) { "mutation { setField }" }
40
+
41
+ it "should not be equal" do
42
+ refute document1.eql?(document2)
43
+ refute document2.eql?(document1)
44
+ end
45
+ end
46
+
47
+ describe "different query fields" do
48
+ let(:query_string1) { "query { foo }" }
49
+ let(:query_string2) { "query { bar }" }
50
+
51
+ it "should not be equal" do
52
+ refute document1.eql?(document2)
53
+ refute document2.eql?(document1)
54
+ end
55
+ end
56
+
57
+ describe "different schemas" do
58
+ let(:query_string1) {%|
59
+ schema {
60
+ query: Query
61
+ }
62
+
63
+ type Query {
64
+ field: String!
65
+ }
66
+ |}
67
+ let(:query_string2) {%|
68
+ schema {
69
+ query: Query
70
+ }
71
+
72
+ type Query {
73
+ field: Int!
74
+ }
75
+ |}
76
+
77
+ it "should not be equal" do
78
+ refute document1.eql?(document2)
79
+ refute document2.eql?(document1)
80
+ end
81
+ end
82
+ end
83
+ end
@@ -0,0 +1,15 @@
1
+ require "spec_helper"
2
+
3
+ describe GraphQL::Language::Nodes::AbstractNode do
4
+ describe "child and scalar attributes" do
5
+ it "are inherited by node subclasses" do
6
+ subclassed_directive = Class.new(GraphQL::Language::Nodes::Directive)
7
+
8
+ assert_equal GraphQL::Language::Nodes::Directive.scalar_attributes,
9
+ subclassed_directive.scalar_attributes
10
+
11
+ assert_equal GraphQL::Language::Nodes::Directive.child_attributes,
12
+ subclassed_directive.child_attributes
13
+ end
14
+ end
15
+ end
@@ -0,0 +1,12 @@
1
+ require "spec_helper"
2
+
3
+ describe GraphQL::Relay::ConnectionField do
4
+ it "replaces the previous field definition" do
5
+ test_type = GraphQL::ObjectType.define do
6
+ name "Test"
7
+ connection :tests, test_type.connection_type
8
+ end
9
+
10
+ assert_equal ["tests"], test_type.fields.keys
11
+ end
12
+ end
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: 0.18.7
4
+ version: 0.18.8
5
5
  platform: ruby
6
6
  authors:
7
7
  - Robert Mosolgo
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2016-09-06 00:00:00.000000000 Z
11
+ date: 2016-09-08 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: codeclimate-test-reporter
@@ -413,7 +413,9 @@ files:
413
413
  - spec/graphql/introspection/introspection_query_spec.rb
414
414
  - spec/graphql/introspection/schema_type_spec.rb
415
415
  - spec/graphql/introspection/type_type_spec.rb
416
+ - spec/graphql/language/equality_spec.rb
416
417
  - spec/graphql/language/generation_spec.rb
418
+ - spec/graphql/language/nodes_spec.rb
417
419
  - spec/graphql/language/parser_spec.rb
418
420
  - spec/graphql/language/visitor_spec.rb
419
421
  - spec/graphql/list_type_spec.rb
@@ -427,6 +429,7 @@ files:
427
429
  - spec/graphql/query/variables_spec.rb
428
430
  - spec/graphql/query_spec.rb
429
431
  - spec/graphql/relay/array_connection_spec.rb
432
+ - spec/graphql/relay/connection_field_spec.rb
430
433
  - spec/graphql/relay/connection_type_spec.rb
431
434
  - spec/graphql/relay/global_node_identification_spec.rb
432
435
  - spec/graphql/relay/mutation_spec.rb
@@ -521,7 +524,9 @@ test_files:
521
524
  - spec/graphql/introspection/introspection_query_spec.rb
522
525
  - spec/graphql/introspection/schema_type_spec.rb
523
526
  - spec/graphql/introspection/type_type_spec.rb
527
+ - spec/graphql/language/equality_spec.rb
524
528
  - spec/graphql/language/generation_spec.rb
529
+ - spec/graphql/language/nodes_spec.rb
525
530
  - spec/graphql/language/parser_spec.rb
526
531
  - spec/graphql/language/visitor_spec.rb
527
532
  - spec/graphql/list_type_spec.rb
@@ -535,6 +540,7 @@ test_files:
535
540
  - spec/graphql/query/variables_spec.rb
536
541
  - spec/graphql/query_spec.rb
537
542
  - spec/graphql/relay/array_connection_spec.rb
543
+ - spec/graphql/relay/connection_field_spec.rb
538
544
  - spec/graphql/relay/connection_type_spec.rb
539
545
  - spec/graphql/relay/global_node_identification_spec.rb
540
546
  - spec/graphql/relay/mutation_spec.rb