graphql 1.7.4 → 1.7.5

Sign up to get free protection for your applications and to get access to all the features.
Files changed (43) hide show
  1. checksums.yaml +4 -4
  2. data/lib/generators/graphql/core.rb +13 -3
  3. data/lib/generators/graphql/enum_generator.rb +1 -1
  4. data/lib/generators/graphql/function_generator.rb +4 -1
  5. data/lib/generators/graphql/install_generator.rb +3 -3
  6. data/lib/generators/graphql/interface_generator.rb +1 -1
  7. data/lib/generators/graphql/loader_generator.rb +4 -1
  8. data/lib/generators/graphql/mutation_generator.rb +3 -3
  9. data/lib/generators/graphql/object_generator.rb +1 -1
  10. data/lib/generators/graphql/type_generator.rb +3 -0
  11. data/lib/generators/graphql/union_generator.rb +1 -1
  12. data/lib/graphql/backtrace/inspect_result.rb +1 -1
  13. data/lib/graphql/backtrace/table.rb +2 -2
  14. data/lib/graphql/backtrace/tracer.rb +7 -1
  15. data/lib/graphql/base_type.rb +10 -0
  16. data/lib/graphql/compatibility/query_parser_specification.rb +15 -0
  17. data/lib/graphql/execution/multiplex.rb +4 -0
  18. data/lib/graphql/language/parser.rb +595 -514
  19. data/lib/graphql/language/parser.y +21 -5
  20. data/lib/graphql/list_type.rb +4 -0
  21. data/lib/graphql/non_null_type.rb +5 -1
  22. data/lib/graphql/query.rb +3 -0
  23. data/lib/graphql/static_validation/all_rules.rb +1 -0
  24. data/lib/graphql/static_validation/rules/variable_names_are_unique.rb +23 -0
  25. data/lib/graphql/subscriptions.rb +6 -0
  26. data/lib/graphql/subscriptions/action_cable_subscriptions.rb +2 -4
  27. data/lib/graphql/subscriptions/serialize.rb +36 -10
  28. data/lib/graphql/tracing/scout_tracing.rb +5 -3
  29. data/lib/graphql/version.rb +1 -1
  30. data/spec/dummy/Gemfile +4 -2
  31. data/spec/dummy/config/application.rb +0 -1
  32. data/spec/generators/graphql/install_generator_spec.rb +7 -0
  33. data/spec/generators/graphql/mutation_generator_spec.rb +25 -2
  34. data/spec/generators/graphql/union_generator_spec.rb +14 -0
  35. data/spec/graphql/backtrace_spec.rb +21 -1
  36. data/spec/graphql/base_type_spec.rb +42 -0
  37. data/spec/graphql/execution/multiplex_spec.rb +48 -0
  38. data/spec/graphql/field_spec.rb +14 -2
  39. data/spec/graphql/static_validation/rules/variable_names_are_unique_spec.rb +23 -0
  40. data/spec/graphql/subscriptions/serialize_spec.rb +53 -0
  41. data/spec/graphql/subscriptions_spec.rb +9 -2
  42. data/spec/graphql/tracing/scout_tracing_spec.rb +17 -0
  43. metadata +23 -2
@@ -132,4 +132,52 @@ describe GraphQL::Execution::Multiplex do
132
132
  ], checks
133
133
  end
134
134
  end
135
+
136
+ describe "after_query when errors are raised" do
137
+ class InspectQueryInstrumentation
138
+ class << self
139
+ attr_reader :last_json
140
+ def before_query(query)
141
+ end
142
+
143
+ def after_query(query)
144
+ @last_json = query.result.to_json
145
+ end
146
+ end
147
+ end
148
+
149
+ InspectQueryType = GraphQL::ObjectType.define do
150
+ name "Query"
151
+
152
+ field :raiseExecutionError, types.String do
153
+ resolve ->(object, args, ctx) {
154
+ raise GraphQL::ExecutionError, "Whoops"
155
+ }
156
+ end
157
+
158
+ field :raiseError, types.String do
159
+ resolve ->(object, args, ctx) {
160
+ raise GraphQL::Error, "Crash"
161
+ }
162
+ end
163
+ end
164
+
165
+ InspectSchema = GraphQL::Schema.define do
166
+ query InspectQueryType
167
+ instrument(:query, InspectQueryInstrumentation)
168
+ end
169
+
170
+ it "can access the query results" do
171
+ InspectSchema.execute("{ raiseExecutionError }")
172
+ handled_err_json = '{"data":{"raiseExecutionError":null},"errors":[{"message":"Whoops","locations":[{"line":1,"column":3}],"path":["raiseExecutionError"]}]}'
173
+ assert_equal handled_err_json, InspectQueryInstrumentation.last_json
174
+
175
+
176
+ assert_raises(GraphQL::Error) do
177
+ InspectSchema.execute("{ raiseError }")
178
+ end
179
+ unhandled_err_json = 'null'
180
+ assert_equal unhandled_err_json, InspectQueryInstrumentation.last_json
181
+ end
182
+ end
135
183
  end
@@ -225,10 +225,22 @@ describe GraphQL::Field do
225
225
 
226
226
  describe "#resolve_proc" do
227
227
  it "ensures the definition was called" do
228
- field = GraphQL::Field.define do
228
+ class SimpleResolver
229
+ def self.call(*args)
230
+ :whatever
231
+ end
232
+ end
233
+
234
+ field_with_proc = GraphQL::Field.define do
229
235
  resolve ->(o, a, c) { :whatever }
230
236
  end
231
- assert_instance_of Proc, field.resolve_proc
237
+
238
+ field_with_class = GraphQL::Field.define do
239
+ resolve SimpleResolver
240
+ end
241
+
242
+ assert_respond_to field_with_proc.resolve_proc, :call
243
+ assert_respond_to field_with_class.resolve_proc, :call
232
244
  end
233
245
  end
234
246
  end
@@ -0,0 +1,23 @@
1
+ # frozen_string_literal: true
2
+ require "spec_helper"
3
+
4
+ describe GraphQL::StaticValidation::VariableNamesAreUnique do
5
+ include StaticValidationHelpers
6
+
7
+ let(:query_string) { <<-GRAPHQL
8
+ query GetStuff($var1: Int!, $var2: Int!, $var1: Int!, $var2: Int!, $var3: Int!) {
9
+ c1: cheese(id: $var1) { flavor }
10
+ c2: cheese(id: $var2) { flavor }
11
+ c3: cheese(id: $var3) { flavor }
12
+ }
13
+ GRAPHQL
14
+ }
15
+
16
+ it "finds duplicate variable names" do
17
+ assert_equal 2, errors.size
18
+
19
+ last_err = errors.last
20
+ assert_equal 'There can only be one variable named "var2"', last_err["message"]
21
+ assert_equal 2, last_err["locations"].size
22
+ end
23
+ end
@@ -0,0 +1,53 @@
1
+ # frozen_string_literal: true
2
+ require "spec_helper"
3
+
4
+ if defined?(GlobalID)
5
+ GlobalID.app = "graphql-ruby-test"
6
+
7
+ class GlobalIDUser
8
+ include GlobalID::Identification
9
+
10
+ attr_reader :id
11
+
12
+ def initialize(id)
13
+ @id = id
14
+ end
15
+
16
+ def self.find(id)
17
+ GlobalIDUser.new(id)
18
+ end
19
+
20
+ def ==(that)
21
+ self.id == that.id
22
+ end
23
+ end
24
+ end
25
+
26
+ describe GraphQL::Subscriptions::Serialize do
27
+ if defined?(GlobalID)
28
+ it "should serialize GlobalID::Identification in Array/Hash" do
29
+ user_a = GlobalIDUser.new("a")
30
+ user_b = GlobalIDUser.new("b")
31
+
32
+ str_a = GraphQL::Subscriptions::Serialize.dump(["first", 2, user_a])
33
+ str_b = GraphQL::Subscriptions::Serialize.dump({first: 'first', second: 2, user: user_b})
34
+
35
+ assert_equal str_a, '["first",2,{"__gid__":"Z2lkOi8vZ3JhcGhxbC1ydWJ5LXRlc3QvR2xvYmFsSURVc2VyL2E"}]'
36
+ assert_equal str_b, '{"first":"first","second":2,"user":{"__gid__":"Z2lkOi8vZ3JhcGhxbC1ydWJ5LXRlc3QvR2xvYmFsSURVc2VyL2I"}}'
37
+ end
38
+
39
+ it "should deserialize GlobalID::Identification in Array/Hash" do
40
+ user_a = GlobalIDUser.new("a")
41
+ user_b = GlobalIDUser.new("b")
42
+
43
+ str_a = '["first",2,{"__gid__":"Z2lkOi8vZ3JhcGhxbC1ydWJ5LXRlc3QvR2xvYmFsSURVc2VyL2E"}]'
44
+ str_b = '{"first":"first","second":2,"user":{"__gid__":"Z2lkOi8vZ3JhcGhxbC1ydWJ5LXRlc3QvR2xvYmFsSURVc2VyL2I"}}'
45
+
46
+ parsed_obj_a = GraphQL::Subscriptions::Serialize.load(str_a)
47
+ parsed_obj_b = GraphQL::Subscriptions::Serialize.load(str_b)
48
+
49
+ assert_equal parsed_obj_a, ["first", 2, user_a]
50
+ assert_equal parsed_obj_b, {'first' => 'first', 'second' => 2, 'user' => user_b}
51
+ end
52
+ end
53
+ end
@@ -133,7 +133,7 @@ class InMemoryBackend
133
133
  Schema.get_field("Subscription", "myEvent").subscription_scope = :me
134
134
  end
135
135
 
136
- if rails_should_be_installed? && defined?(GlobalID)
136
+ if defined?(GlobalID)
137
137
  GlobalID.app = "graphql-ruby-test"
138
138
 
139
139
  class GlobalIDUser
@@ -308,7 +308,7 @@ describe GraphQL::Subscriptions do
308
308
  assert_equal [3], deliveries["3"].map { |d| d["data"]["myEvent"]["int"] }
309
309
  end
310
310
 
311
- if rails_should_be_installed? && defined?(GlobalID)
311
+ if defined?(GlobalID)
312
312
  it "allows complex object subscription scopes" do
313
313
  query_str = <<-GRAPHQL
314
314
  subscription($type: PayloadType) {
@@ -384,4 +384,11 @@ describe GraphQL::Subscriptions do
384
384
  assert_equal 123, schema.subscriptions.extra
385
385
  end
386
386
  end
387
+
388
+ describe "#build_id" do
389
+ it "returns a unique ID string" do
390
+ assert_instance_of String, schema.subscriptions.build_id
391
+ refute_equal schema.subscriptions.build_id, schema.subscriptions.build_id
392
+ end
393
+ end
387
394
  end
@@ -0,0 +1,17 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "spec_helper"
4
+
5
+ describe GraphQL::Tracing::ScoutTracing do
6
+ class ScoutApm
7
+ module Tracer
8
+ end
9
+ end
10
+
11
+ describe "Initializing" do
12
+ it "should include the module only after initilization" do
13
+ refute GraphQL::Tracing::ScoutTracing.included_modules.include?(ScoutApm::Tracer)
14
+ assert GraphQL::Tracing::ScoutTracing.new.class.included_modules.include?(ScoutApm::Tracer)
15
+ end
16
+ end
17
+ 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: 1.7.4
4
+ version: 1.7.5
5
5
  platform: ruby
6
6
  authors:
7
7
  - Robert Mosolgo
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2017-10-09 00:00:00.000000000 Z
11
+ date: 2017-11-07 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: benchmark-ips
@@ -276,6 +276,20 @@ dependencies:
276
276
  - - ">="
277
277
  - !ruby/object:Gem::Version
278
278
  version: '0'
279
+ - !ruby/object:Gem::Dependency
280
+ name: algoliasearch-jekyll
281
+ requirement: !ruby/object:Gem::Requirement
282
+ requirements:
283
+ - - ">="
284
+ - !ruby/object:Gem::Version
285
+ version: '0'
286
+ type: :development
287
+ prerelease: false
288
+ version_requirements: !ruby/object:Gem::Requirement
289
+ requirements:
290
+ - - ">="
291
+ - !ruby/object:Gem::Version
292
+ version: '0'
279
293
  description: A plain-Ruby implementation of GraphQL.
280
294
  email:
281
295
  - rdmosolgo@gmail.com
@@ -504,6 +518,7 @@ files:
504
518
  - lib/graphql/static_validation/rules/subscription_root_exists.rb
505
519
  - lib/graphql/static_validation/rules/unique_directives_per_location.rb
506
520
  - lib/graphql/static_validation/rules/variable_default_values_are_correctly_typed.rb
521
+ - lib/graphql/static_validation/rules/variable_names_are_unique.rb
507
522
  - lib/graphql/static_validation/rules/variable_usages_are_allowed.rb
508
523
  - lib/graphql/static_validation/rules/variables_are_input_types.rb
509
524
  - lib/graphql/static_validation/rules/variables_are_used_and_defined.rb
@@ -941,15 +956,18 @@ files:
941
956
  - spec/graphql/static_validation/rules/subscription_root_exists_spec.rb
942
957
  - spec/graphql/static_validation/rules/unique_directives_per_location_spec.rb
943
958
  - spec/graphql/static_validation/rules/variable_default_values_are_correctly_typed_spec.rb
959
+ - spec/graphql/static_validation/rules/variable_names_are_unique_spec.rb
944
960
  - spec/graphql/static_validation/rules/variable_usages_are_allowed_spec.rb
945
961
  - spec/graphql/static_validation/rules/variables_are_input_types_spec.rb
946
962
  - spec/graphql/static_validation/rules/variables_are_used_and_defined_spec.rb
947
963
  - spec/graphql/static_validation/type_stack_spec.rb
948
964
  - spec/graphql/static_validation/validator_spec.rb
949
965
  - spec/graphql/string_type_spec.rb
966
+ - spec/graphql/subscriptions/serialize_spec.rb
950
967
  - spec/graphql/subscriptions_spec.rb
951
968
  - spec/graphql/tracing/active_support_notifications_tracing_spec.rb
952
969
  - spec/graphql/tracing/platform_tracing_spec.rb
970
+ - spec/graphql/tracing/scout_tracing_spec.rb
953
971
  - spec/graphql/tracing_spec.rb
954
972
  - spec/graphql/union_type_spec.rb
955
973
  - spec/rails_dependency_sanity_spec.rb
@@ -1403,15 +1421,18 @@ test_files:
1403
1421
  - spec/graphql/static_validation/rules/subscription_root_exists_spec.rb
1404
1422
  - spec/graphql/static_validation/rules/unique_directives_per_location_spec.rb
1405
1423
  - spec/graphql/static_validation/rules/variable_default_values_are_correctly_typed_spec.rb
1424
+ - spec/graphql/static_validation/rules/variable_names_are_unique_spec.rb
1406
1425
  - spec/graphql/static_validation/rules/variable_usages_are_allowed_spec.rb
1407
1426
  - spec/graphql/static_validation/rules/variables_are_input_types_spec.rb
1408
1427
  - spec/graphql/static_validation/rules/variables_are_used_and_defined_spec.rb
1409
1428
  - spec/graphql/static_validation/type_stack_spec.rb
1410
1429
  - spec/graphql/static_validation/validator_spec.rb
1411
1430
  - spec/graphql/string_type_spec.rb
1431
+ - spec/graphql/subscriptions/serialize_spec.rb
1412
1432
  - spec/graphql/subscriptions_spec.rb
1413
1433
  - spec/graphql/tracing/active_support_notifications_tracing_spec.rb
1414
1434
  - spec/graphql/tracing/platform_tracing_spec.rb
1435
+ - spec/graphql/tracing/scout_tracing_spec.rb
1415
1436
  - spec/graphql/tracing_spec.rb
1416
1437
  - spec/graphql/union_type_spec.rb
1417
1438
  - spec/rails_dependency_sanity_spec.rb