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
@@ -0,0 +1,40 @@
1
+ # frozen_string_literal: true
2
+ require "spec_helper"
3
+
4
+ describe GraphQL::Schema::Scalar do
5
+ describe "in queries" do
6
+ it "becomes output" do
7
+ query_str = <<-GRAPHQL
8
+ {
9
+ find(id: "Musician/Herbie Hancock") {
10
+ ... on Musician {
11
+ name
12
+ favoriteKey
13
+ }
14
+ }
15
+ }
16
+ GRAPHQL
17
+
18
+ res = Jazz::Schema.execute(query_str)
19
+ assert_equal "B♭", res["data"]["find"]["favoriteKey"]
20
+ end
21
+
22
+ it "can be input" do
23
+ query_str = <<-GRAPHQL
24
+ {
25
+ inspectKey(key: "F♯") {
26
+ root
27
+ isSharp
28
+ isFlat
29
+ }
30
+ }
31
+ GRAPHQL
32
+
33
+ res = Jazz::Schema.execute(query_str)
34
+ key_info = res["data"]["inspectKey"]
35
+ assert_equal "F", key_info["root"]
36
+ assert_equal true, key_info["isSharp"]
37
+ assert_equal false, key_info["isFlat"]
38
+ end
39
+ end
40
+ end
@@ -0,0 +1,35 @@
1
+ # frozen_string_literal: true
2
+ require "spec_helper"
3
+
4
+ describe GraphQL::Schema::Union do
5
+ let(:union) { Jazz::PerformingAct }
6
+ describe "type info" do
7
+ it "has some" do
8
+ assert_equal 2, union.possible_types.size
9
+ end
10
+ end
11
+
12
+ describe "in queries" do
13
+ it "works" do
14
+ query_str = <<-GRAPHQL
15
+ {
16
+ nowPlaying {
17
+ ... on Musician {
18
+ name
19
+ instrument {
20
+ family
21
+ }
22
+ }
23
+ ... on Ensemble {
24
+ name
25
+ }
26
+ }
27
+ }
28
+ GRAPHQL
29
+
30
+ res = Jazz::Schema.execute(query_str)
31
+ expected_data = { "name" => "Bela Fleck and the Flecktones" }
32
+ assert_equal expected_data, res["data"]["nowPlaying"]
33
+ end
34
+ end
35
+ end
@@ -333,7 +333,7 @@ describe GraphQL::Schema::Validation do
333
333
  end
334
334
 
335
335
  it "allows null default value for nullable argument" do
336
- assert_nil GraphQL::Schema::Validation.validate(null_default_value)
336
+ assert_equal nil, GraphQL::Schema::Validation.validate(null_default_value)
337
337
  end
338
338
  end
339
339
 
@@ -242,8 +242,8 @@ describe GraphQL::Schema::Warden do
242
242
  GRAPHQL
243
243
  res = MaskHelpers.query_with_mask(query_string, mask)
244
244
  assert_equal "Query", res["data"]["__schema"]["queryType"]["name"]
245
- assert_nil res["data"]["__schema"]["mutationType"]
246
- assert_nil res["data"]["__schema"]["subscriptionType"]
245
+ assert_equal nil, res["data"]["__schema"]["mutationType"]
246
+ assert_equal nil, res["data"]["__schema"]["subscriptionType"]
247
247
  type_names = res["data"]["__schema"]["types"].map { |t| t["name"] }
248
248
  refute type_names.include?("Mutation")
249
249
  refute type_names.include?("Subscription")
@@ -344,7 +344,7 @@ describe GraphQL::Schema::Warden do
344
344
  res = MaskHelpers.run_query(query_string, only: whitelist)
345
345
 
346
346
  # It's not visible by name
347
- assert_nil res["data"]["Phoneme"]
347
+ assert_equal nil, res["data"]["Phoneme"]
348
348
 
349
349
  # It's not visible in `__schema`
350
350
  all_type_names = type_names(res)
@@ -423,7 +423,7 @@ describe GraphQL::Schema::Warden do
423
423
 
424
424
  res = MaskHelpers.query_with_mask(query_string, mask)
425
425
  type = res["data"]["__type"]
426
- assert_nil type
426
+ assert_equal nil, type
427
427
  end
428
428
  end
429
429
  end
@@ -543,7 +543,7 @@ describe GraphQL::Schema::Warden do
543
543
 
544
544
  res = MaskHelpers.query_with_mask(query_string, mask)
545
545
 
546
- assert_nil res["data"]["WithinInput"], "The type isn't accessible by name"
546
+ assert_equal nil, res["data"]["WithinInput"], "The type isn't accessible by name"
547
547
 
548
548
  languages_arg_names = res["data"]["Query"]["fields"].find { |f| f["name"] == "languages" }["args"].map { |a| a["name"] }
549
549
  refute_includes languages_arg_names, "within", "Arguments that point to it are gone"
@@ -666,7 +666,7 @@ describe GraphQL::Schema::Warden do
666
666
  it "is additive with query filters" do
667
667
  query_except = ->(member, ctx) { member.metadata[:hidden_input_object_type] }
668
668
  res = schema.execute(query_str, except: query_except)
669
- assert_nil res["data"]["input"]
669
+ assert_equal nil, res["data"]["input"]
670
670
  enum_values = res["data"]["enum"]["enumValues"].map { |v| v["name"] }
671
671
  refute_includes enum_values, "TRILL"
672
672
  end
@@ -695,13 +695,13 @@ describe GraphQL::Schema::Warden do
695
695
  only: [visible_enum_value, visible_abstract_type],
696
696
  except: [hidden_input_object, hidden_type],
697
697
  )
698
- assert_nil res["data"]["input"]
698
+ assert_equal nil, res["data"]["input"]
699
699
  enum_values = res["data"]["enum"]["enumValues"].map { |v| v["name"] }
700
700
  assert_equal 5, enum_values.length
701
701
  refute_includes enum_values, "TRILL"
702
702
  # These are also filtered out:
703
703
  assert_equal 0, res["data"]["abstractType"]["interfaces"].length
704
- assert_nil res["data"]["type"]
704
+ assert_equal nil, res["data"]["type"]
705
705
  end
706
706
  end
707
707
 
@@ -712,7 +712,7 @@ describe GraphQL::Schema::Warden do
712
712
  except: hidden_input_object,
713
713
  }
714
714
  res = MaskHelpers.run_query(query_str, context: { filters: filters })
715
- assert_nil res["data"]["input"]
715
+ assert_equal nil, res["data"]["input"]
716
716
  enum_values = res["data"]["enum"]["enumValues"].map { |v| v["name"] }
717
717
  assert_equal 5, enum_values.length
718
718
  refute_includes enum_values, "TRILL"
@@ -727,13 +727,13 @@ describe GraphQL::Schema::Warden do
727
727
  except: [hidden_input_object, hidden_type],
728
728
  }
729
729
  res = MaskHelpers.run_query(query_str, context: { filters: filters })
730
- assert_nil res["data"]["input"]
730
+ assert_equal nil, res["data"]["input"]
731
731
  enum_values = res["data"]["enum"]["enumValues"].map { |v| v["name"] }
732
732
  assert_equal 5, enum_values.length
733
733
  refute_includes enum_values, "TRILL"
734
734
  # These are also filtered out:
735
735
  assert_equal 0, res["data"]["abstractType"]["interfaces"].length
736
- assert_nil res["data"]["type"]
736
+ assert_equal nil, res["data"]["type"]
737
737
  end
738
738
  end
739
739
  end
@@ -23,19 +23,12 @@ describe GraphQL::Schema do
23
23
  end
24
24
  end
25
25
 
26
- describe "#to_document" do
27
- it "returns the AST for the schema IDL" do
28
- expected = GraphQL::Language::DocumentFromSchemaDefinition.new(schema).document
29
- assert expected.eql?(schema.to_document)
30
- end
31
- end
32
-
33
26
  describe "#root_types" do
34
27
  it "returns a list of the schema's root types" do
35
28
  assert_equal(
36
29
  [
37
30
  Dummy::DairyAppQueryType,
38
- Dummy::DairyAppMutationType,
31
+ Dummy::DairyAppMutationType.graphql_definition,
39
32
  Dummy::SubscriptionType
40
33
  ],
41
34
  schema.root_types
@@ -379,24 +372,25 @@ type Query {
379
372
  assert_equal true, schema.lazy?(LazyObj.new)
380
373
  assert_equal :dup, schema.lazy_method_name(LazyObjChild.new)
381
374
  assert_equal true, schema.lazy?(LazyObjChild.new)
382
- assert_nil schema.lazy_method_name({})
375
+ assert_equal nil, schema.lazy_method_name({})
383
376
  assert_equal false, schema.lazy?({})
384
377
  end
385
378
  end
386
379
 
387
380
  describe "#dup" do
388
381
  it "copies internal state" do
389
- schema_2 = schema.dup
390
- refute schema_2.types.equal?(schema.types)
382
+ schema_1 = schema.graphql_definition
383
+ schema_2 = schema_1.dup
384
+ refute schema_2.types.equal?(schema_1.types)
391
385
 
392
- refute schema_2.instrumenters.equal?(schema.instrumenters)
393
- assert_equal schema_2.instrumenters, schema.instrumenters
386
+ refute schema_2.instrumenters.equal?(schema_1.instrumenters)
387
+ assert_equal schema_2.instrumenters, schema_1.instrumenters
394
388
 
395
- refute schema_2.middleware.equal?(schema.middleware)
396
- assert_equal schema_2.middleware, schema.middleware
389
+ refute schema_2.middleware.equal?(schema_1.middleware)
390
+ assert_equal schema_2.middleware, schema_1.middleware
397
391
 
398
392
  schema_2.middleware << ->(*args) { :noop }
399
- refute_equal schema_2.middleware, schema.middleware
393
+ refute_equal schema_2.middleware, schema_1.middleware
400
394
  end
401
395
  end
402
396
 
@@ -425,13 +419,6 @@ type Query {
425
419
  end
426
420
  end
427
421
 
428
- describe "#as_json" do
429
- it "returns a hash" do
430
- result = schema.execute(GraphQL::Introspection::INTROSPECTION_QUERY)
431
- assert_equal result.as_json.class, Hash
432
- end
433
- end
434
-
435
422
  describe "#get_field" do
436
423
  it "returns fields by type or type name" do
437
424
  field = schema.get_field("Cheese", "id")
@@ -440,4 +427,19 @@ type Query {
440
427
  assert_equal field, field_2
441
428
  end
442
429
  end
430
+
431
+ describe "class-based schemas" do
432
+ it "delegates to the graphql definition" do
433
+ # Not delegated:
434
+ assert_equal Jazz::Query.graphql_definition, Jazz::Schema.query
435
+ assert Jazz::Schema.respond_to?(:query)
436
+ # Delegated
437
+ assert_equal [], Jazz::Schema.tracers
438
+ assert Jazz::Schema.respond_to?(:tracers)
439
+ end
440
+
441
+ it "works with plugins" do
442
+ assert_equal "xyz", Jazz::Schema.metadata[:plugin_key]
443
+ end
444
+ end
443
445
  end
@@ -8,19 +8,18 @@ describe GraphQL::StaticValidation::FieldsHaveAppropriateSelections do
8
8
  okCheese: cheese(id: 1) { fatContent, similarCheese(source: YAK) { source } }
9
9
  missingFieldsCheese: cheese(id: 1)
10
10
  illegalSelectionCheese: cheese(id: 1) { id { something, ... someFields } }
11
- incorrectFragmentSpread: cheese(id: 1) { flavor { ... on String { __typename } } }
12
11
  }
13
12
  "}
14
13
 
15
14
  it "adds errors for selections on scalars" do
16
- assert_equal(3, errors.length)
15
+ assert_equal(2, errors.length)
17
16
 
18
17
  illegal_selection_error = {
19
18
  "message"=>"Selections can't be made on scalars (field 'id' returns Int but has selections [something, someFields])",
20
19
  "locations"=>[{"line"=>5, "column"=>47}],
21
20
  "fields"=>["query getCheese", "illegalSelectionCheese", "id"],
22
21
  }
23
- assert_includes(errors, illegal_selection_error, "finds illegal selections on scalars")
22
+ assert_includes(errors, illegal_selection_error, "finds illegal selections on scalarss")
24
23
 
25
24
  selection_required_error = {
26
25
  "message"=>"Objects must have selections (field 'cheese' returns Cheese but has no selections)",
@@ -28,13 +27,6 @@ describe GraphQL::StaticValidation::FieldsHaveAppropriateSelections do
28
27
  "fields"=>["query getCheese", "missingFieldsCheese"],
29
28
  }
30
29
  assert_includes(errors, selection_required_error, "finds objects without selections")
31
-
32
- incorrect_fragment_error = {
33
- "message"=>"Selections can't be made on scalars (field 'flavor' returns String but has inline fragments [String])",
34
- "locations"=>[{"line"=>6, "column"=>48}],
35
- "fields"=>["query getCheese", "incorrectFragmentSpread", "flavor"],
36
- }
37
- assert_includes(errors, incorrect_fragment_error, "finds scalar fields with selections")
38
30
  end
39
31
 
40
32
  describe "anonymous operations" do
@@ -515,7 +515,7 @@ describe GraphQL::StaticValidation::FieldsWillMerge do
515
515
  scalar: String!
516
516
  }
517
517
 
518
- type NonNullStringBox1Impl implements SomeBox & NonNullStringBox1 {
518
+ type NonNullStringBox1Impl implements SomeBox, NonNullStringBox1 {
519
519
  scalar: String!
520
520
  unrelatedField: String
521
521
  deepBox: SomeBox
@@ -525,7 +525,7 @@ describe GraphQL::StaticValidation::FieldsWillMerge do
525
525
  scalar: String!
526
526
  }
527
527
 
528
- type NonNullStringBox2Impl implements SomeBox & NonNullStringBox2 {
528
+ type NonNullStringBox2Impl implements SomeBox, NonNullStringBox2 {
529
529
  scalar: String!
530
530
  unrelatedField: String
531
531
  deepBox: SomeBox
@@ -72,9 +72,9 @@ describe GraphQL::STRING_TYPE do
72
72
  end
73
73
 
74
74
  it "doesn't accept other types" do
75
- assert_nil string_type.coerce_isolated_input(100)
76
- assert_nil string_type.coerce_isolated_input(true)
77
- assert_nil string_type.coerce_isolated_input(0.999)
75
+ assert_equal nil, string_type.coerce_isolated_input(100)
76
+ assert_equal nil, string_type.coerce_isolated_input(true)
77
+ assert_equal nil, string_type.coerce_isolated_input(0.999)
78
78
  end
79
79
  end
80
80
  end
@@ -242,7 +242,7 @@ describe GraphQL::Subscriptions do
242
242
  schema.execute(query_str, context: { socket: "1" }, variables: { "id" => "8" }, root_value: root_object)
243
243
  schema.subscriptions.trigger("payload", { "id" => "8"}, OpenStruct.new(str: nil, int: nil))
244
244
  delivery = deliveries["1"].first
245
- assert_nil delivery.fetch("data")
245
+ assert_equal nil, delivery.fetch("data")
246
246
  assert_equal 1, delivery["errors"].length
247
247
  end
248
248
 
@@ -41,72 +41,13 @@ describe GraphQL::Tracing::PlatformTracing do
41
41
  schema.execute(" { cheese(id: 1) { flavor } }")
42
42
  expected_trace = [
43
43
  "em",
44
- "am",
45
44
  "l",
46
45
  "p",
47
46
  "v",
48
- "aq",
49
- "eq",
50
- "Q.c", # notice that the flavor is skipped
51
- "eql",
52
- ]
53
- assert_equal expected_trace, CustomPlatformTracer::TRACE
54
- end
55
- end
56
-
57
- describe "by default, scalar fields are not traced" do
58
- let(:schema) {
59
- Dummy::Schema.redefine {
60
- use(CustomPlatformTracer)
61
- }
62
- }
63
-
64
- before do
65
- CustomPlatformTracer::TRACE.clear
66
- end
67
-
68
- it "only traces traceTrue, not traceFalse or traceNil" do
69
- schema.execute(" { tracingScalar { traceNil traceFalse traceTrue } }")
70
- expected_trace = [
71
- "em",
72
47
  "am",
73
- "l",
74
- "p",
75
- "v",
76
48
  "aq",
77
49
  "eq",
78
- "Q.t",
79
- "T.t",
80
- "eql",
81
- ]
82
- assert_equal expected_trace, CustomPlatformTracer::TRACE
83
- end
84
- end
85
-
86
- describe "when scalar fields are traced by default, they are unless specified" do
87
- let(:schema) {
88
- Dummy::Schema.redefine {
89
- use(CustomPlatformTracer, trace_scalars: true)
90
- }
91
- }
92
-
93
- before do
94
- CustomPlatformTracer::TRACE.clear
95
- end
96
-
97
- it "traces traceTrue and traceNil but not traceFalse" do
98
- schema.execute(" { tracingScalar { traceNil traceFalse traceTrue } }")
99
- expected_trace = [
100
- "em",
101
- "am",
102
- "l",
103
- "p",
104
- "v",
105
- "aq",
106
- "eq",
107
- "Q.t",
108
- "T.t",
109
- "T.t",
50
+ "Q.c", # notice that the flavor is skipped
110
51
  "eql",
111
52
  ]
112
53
  assert_equal expected_trace, CustomPlatformTracer::TRACE
@@ -149,15 +149,6 @@ module Dummy
149
149
  field :cheese, CheeseType
150
150
  end
151
151
 
152
- TracingScalarType = GraphQL::ObjectType.define do
153
- name "TracingScalar"
154
- description "An object which has traced scalars"
155
-
156
- field :traceNil, types.Int
157
- field :traceFalse, types.Int, trace: false
158
- field :traceTrue, types.Int, trace: true
159
- end
160
-
161
152
  DairyProductUnion = GraphQL::UnionType.define do
162
153
  name "DairyProduct"
163
154
  description "Kinds of food made from milk"
@@ -381,16 +372,6 @@ module Dummy
381
372
  resolve ->(t, a, c) { OpenStruct.new(cheese: nil) }
382
373
  end
383
374
 
384
- field :tracingScalar, TracingScalarType do
385
- resolve ->(o, a, c) do
386
- OpenStruct.new(
387
- traceNil: 2,
388
- traceFalse: 3,
389
- tracetrue: 5,
390
- )
391
- end
392
- end
393
-
394
375
  field :deepNonNull, !DeepNonNullType do
395
376
  resolve ->(o, a, c) { :deepNonNull }
396
377
  end
@@ -403,26 +384,31 @@ module Dummy
403
384
  input_field :values, !types[!types.Int]
404
385
  end
405
386
 
406
- DairyAppMutationType = GraphQL::ObjectType.define do
407
- name "Mutation"
387
+ PushValueField = GraphQL::Field.define do
388
+ name :pushValue
389
+ type !types[!types.Int]
390
+ description("Push a value onto a global array :D")
391
+ argument :value, !types.Int, as: :val
392
+ resolve ->(o, args, ctx) {
393
+ GLOBAL_VALUES << args.val
394
+ GLOBAL_VALUES
395
+ }
396
+ end
397
+
398
+ class DairyAppMutationType < GraphQL::Schema::Object
399
+ graphql_name "Mutation"
408
400
  description "The root for mutations in this schema"
409
- field :pushValue, !types[!types.Int] do
410
- description("Push a value onto a global array :D")
411
- argument :value, !types.Int, as: :val
412
- resolve ->(o, args, ctx) {
413
- GLOBAL_VALUES << args.val
414
- GLOBAL_VALUES
415
- }
401
+ # Test the `field:` compatibility option
402
+ field :pushValue, field: PushValueField
403
+
404
+ field :replaceValues, [Integer], "Replace the global array with new values", null: false do
405
+ argument :input, ReplaceValuesInputType, required: true
416
406
  end
417
407
 
418
- field :replaceValues, !types[!types.Int] do
419
- description("Replace the global array with new values")
420
- argument :input, !ReplaceValuesInputType
421
- resolve ->(o, args, ctx) {
422
- GLOBAL_VALUES.clear
423
- GLOBAL_VALUES.push(*args.input[:values])
424
- GLOBAL_VALUES
425
- }
408
+ def replace_values(input:)
409
+ GLOBAL_VALUES.clear
410
+ GLOBAL_VALUES.concat(input["values"])
411
+ GLOBAL_VALUES
426
412
  end
427
413
  end
428
414
 
@@ -433,7 +419,7 @@ module Dummy
433
419
  end
434
420
  end
435
421
 
436
- Schema = GraphQL::Schema.define do
422
+ class Schema < GraphQL::Schema
437
423
  query DairyAppQueryType
438
424
  mutation DairyAppMutationType
439
425
  subscription SubscriptionType
@@ -442,8 +428,8 @@ module Dummy
442
428
 
443
429
  rescue_from(NoSuchDairyError) { |err| err.message }
444
430
 
445
- resolve_type ->(type, obj, ctx) {
431
+ def self.resolve_type(type, obj, ctx)
446
432
  Schema.types[obj.class.name.split("::").last]
447
- }
433
+ end
448
434
  end
449
435
  end