graphql 0.12.1 → 0.13.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (146) hide show
  1. checksums.yaml +4 -4
  2. data/lib/graphql.rb +31 -41
  3. data/lib/graphql/argument.rb +23 -21
  4. data/lib/graphql/base_type.rb +5 -8
  5. data/lib/graphql/define/assign_argument.rb +5 -2
  6. data/lib/graphql/define/type_definer.rb +2 -1
  7. data/lib/graphql/directive.rb +34 -36
  8. data/lib/graphql/directive/include_directive.rb +3 -7
  9. data/lib/graphql/directive/skip_directive.rb +3 -7
  10. data/lib/graphql/enum_type.rb +78 -76
  11. data/lib/graphql/execution_error.rb +1 -3
  12. data/lib/graphql/field.rb +99 -95
  13. data/lib/graphql/input_object_type.rb +49 -47
  14. data/lib/graphql/interface_type.rb +31 -34
  15. data/lib/graphql/introspection.rb +19 -18
  16. data/lib/graphql/introspection/directive_location_enum.rb +8 -0
  17. data/lib/graphql/introspection/directive_type.rb +1 -3
  18. data/lib/graphql/introspection/field_type.rb +1 -1
  19. data/lib/graphql/introspection/fields_field.rb +1 -1
  20. data/lib/graphql/introspection/introspection_query.rb +1 -3
  21. data/lib/graphql/introspection/possible_types_field.rb +7 -1
  22. data/lib/graphql/introspection/schema_field.rb +13 -9
  23. data/lib/graphql/introspection/type_by_name_field.rb +13 -17
  24. data/lib/graphql/introspection/typename_field.rb +12 -8
  25. data/lib/graphql/language.rb +5 -9
  26. data/lib/graphql/language/lexer.rb +668 -0
  27. data/lib/graphql/language/lexer.rl +149 -0
  28. data/lib/graphql/language/parser.rb +842 -116
  29. data/lib/graphql/language/parser.y +264 -0
  30. data/lib/graphql/language/token.rb +21 -0
  31. data/lib/graphql/list_type.rb +33 -31
  32. data/lib/graphql/non_null_type.rb +33 -31
  33. data/lib/graphql/object_type.rb +52 -55
  34. data/lib/graphql/query.rb +83 -80
  35. data/lib/graphql/query/context.rb +5 -1
  36. data/lib/graphql/query/directive_resolution.rb +16 -0
  37. data/lib/graphql/query/executor.rb +3 -3
  38. data/lib/graphql/query/input_validation_result.rb +17 -15
  39. data/lib/graphql/query/serial_execution.rb +5 -5
  40. data/lib/graphql/query/serial_execution/execution_context.rb +4 -3
  41. data/lib/graphql/query/serial_execution/selection_resolution.rb +19 -21
  42. data/lib/graphql/query/serial_execution/value_resolution.rb +1 -1
  43. data/lib/graphql/query/type_resolver.rb +22 -18
  44. data/lib/graphql/query/variable_validation_error.rb +14 -12
  45. data/lib/graphql/schema.rb +87 -77
  46. data/lib/graphql/schema/each_item_validator.rb +16 -12
  47. data/lib/graphql/schema/field_validator.rb +14 -10
  48. data/lib/graphql/schema/implementation_validator.rb +26 -22
  49. data/lib/graphql/schema/middleware_chain.rb +2 -1
  50. data/lib/graphql/schema/possible_types.rb +34 -0
  51. data/lib/graphql/schema/printer.rb +122 -120
  52. data/lib/graphql/schema/type_expression.rb +1 -0
  53. data/lib/graphql/schema/type_map.rb +3 -10
  54. data/lib/graphql/schema/type_reducer.rb +65 -81
  55. data/lib/graphql/schema/type_validator.rb +45 -41
  56. data/lib/graphql/static_validation.rb +7 -9
  57. data/lib/graphql/static_validation/all_rules.rb +29 -24
  58. data/lib/graphql/static_validation/arguments_validator.rb +39 -35
  59. data/lib/graphql/static_validation/literal_validator.rb +44 -40
  60. data/lib/graphql/static_validation/message.rb +30 -26
  61. data/lib/graphql/static_validation/rules/argument_literals_are_compatible.rb +15 -11
  62. data/lib/graphql/static_validation/rules/arguments_are_defined.rb +14 -10
  63. data/lib/graphql/static_validation/rules/directives_are_defined.rb +16 -12
  64. data/lib/graphql/static_validation/rules/directives_are_in_valid_locations.rb +59 -0
  65. data/lib/graphql/static_validation/rules/fields_are_defined_on_type.rb +25 -21
  66. data/lib/graphql/static_validation/rules/fields_have_appropriate_selections.rb +28 -24
  67. data/lib/graphql/static_validation/rules/fields_will_merge.rb +84 -80
  68. data/lib/graphql/static_validation/rules/fragment_spreads_are_possible.rb +49 -43
  69. data/lib/graphql/static_validation/rules/fragment_types_exist.rb +22 -17
  70. data/lib/graphql/static_validation/rules/fragments_are_finite.rb +19 -15
  71. data/lib/graphql/static_validation/rules/fragments_are_on_composite_types.rb +25 -20
  72. data/lib/graphql/static_validation/rules/fragments_are_used.rb +36 -23
  73. data/lib/graphql/static_validation/rules/required_arguments_are_present.rb +29 -25
  74. data/lib/graphql/static_validation/rules/variable_default_values_are_correctly_typed.rb +21 -17
  75. data/lib/graphql/static_validation/rules/variable_usages_are_allowed.rb +79 -70
  76. data/lib/graphql/static_validation/rules/variables_are_input_types.rb +24 -20
  77. data/lib/graphql/static_validation/rules/variables_are_used_and_defined.rb +122 -119
  78. data/lib/graphql/static_validation/type_stack.rb +138 -129
  79. data/lib/graphql/static_validation/validator.rb +29 -25
  80. data/lib/graphql/type_kinds.rb +42 -40
  81. data/lib/graphql/union_type.rb +22 -16
  82. data/lib/graphql/version.rb +1 -1
  83. data/readme.md +12 -27
  84. data/spec/graphql/base_type_spec.rb +3 -3
  85. data/spec/graphql/directive_spec.rb +10 -18
  86. data/spec/graphql/enum_type_spec.rb +7 -7
  87. data/spec/graphql/execution_error_spec.rb +1 -1
  88. data/spec/graphql/field_spec.rb +14 -13
  89. data/spec/graphql/id_type_spec.rb +6 -6
  90. data/spec/graphql/input_object_type_spec.rb +39 -39
  91. data/spec/graphql/interface_type_spec.rb +16 -32
  92. data/spec/graphql/introspection/directive_type_spec.rb +5 -9
  93. data/spec/graphql/introspection/input_value_type_spec.rb +10 -4
  94. data/spec/graphql/introspection/introspection_query_spec.rb +2 -2
  95. data/spec/graphql/introspection/schema_type_spec.rb +2 -2
  96. data/spec/graphql/introspection/type_type_spec.rb +34 -6
  97. data/spec/graphql/language/parser_spec.rb +299 -105
  98. data/spec/graphql/language/visitor_spec.rb +4 -4
  99. data/spec/graphql/list_type_spec.rb +11 -11
  100. data/spec/graphql/object_type_spec.rb +10 -10
  101. data/spec/graphql/query/arguments_spec.rb +7 -7
  102. data/spec/graphql/query/context_spec.rb +11 -3
  103. data/spec/graphql/query/executor_spec.rb +26 -19
  104. data/spec/graphql/query/serial_execution/execution_context_spec.rb +6 -6
  105. data/spec/graphql/query/serial_execution/value_resolution_spec.rb +2 -2
  106. data/spec/graphql/query/type_resolver_spec.rb +3 -3
  107. data/spec/graphql/query_spec.rb +6 -38
  108. data/spec/graphql/scalar_type_spec.rb +28 -19
  109. data/spec/graphql/schema/field_validator_spec.rb +1 -1
  110. data/spec/graphql/schema/middleware_chain_spec.rb +12 -1
  111. data/spec/graphql/schema/printer_spec.rb +12 -4
  112. data/spec/graphql/schema/rescue_middleware_spec.rb +1 -1
  113. data/spec/graphql/schema/type_expression_spec.rb +2 -2
  114. data/spec/graphql/schema/type_reducer_spec.rb +21 -36
  115. data/spec/graphql/schema/type_validator_spec.rb +9 -9
  116. data/spec/graphql/schema_spec.rb +1 -1
  117. data/spec/graphql/static_validation/rules/argument_literals_are_compatible_spec.rb +4 -4
  118. data/spec/graphql/static_validation/rules/arguments_are_defined_spec.rb +4 -4
  119. data/spec/graphql/static_validation/rules/directives_are_defined_spec.rb +5 -5
  120. data/spec/graphql/static_validation/rules/directives_are_in_valid_locations_spec.rb +39 -0
  121. data/spec/graphql/static_validation/rules/fields_are_defined_on_type_spec.rb +5 -5
  122. data/spec/graphql/static_validation/rules/fields_have_appropriate_selections_spec.rb +4 -4
  123. data/spec/graphql/static_validation/rules/fields_will_merge_spec.rb +2 -2
  124. data/spec/graphql/static_validation/rules/fragment_spreads_are_possible_spec.rb +1 -1
  125. data/spec/graphql/static_validation/rules/fragment_types_exist_spec.rb +2 -2
  126. data/spec/graphql/static_validation/rules/fragments_are_finite_spec.rb +2 -2
  127. data/spec/graphql/static_validation/rules/fragments_are_on_composite_types_spec.rb +2 -2
  128. data/spec/graphql/static_validation/rules/fragments_are_used_spec.rb +3 -3
  129. data/spec/graphql/static_validation/rules/required_arguments_are_present_spec.rb +3 -3
  130. data/spec/graphql/static_validation/rules/variable_default_values_are_correctly_typed_spec.rb +5 -5
  131. data/spec/graphql/static_validation/rules/variable_usages_are_allowed_spec.rb +3 -1
  132. data/spec/graphql/static_validation/rules/variables_are_input_types_spec.rb +4 -4
  133. data/spec/graphql/static_validation/rules/variables_are_used_and_defined_spec.rb +3 -3
  134. data/spec/graphql/static_validation/type_stack_spec.rb +3 -2
  135. data/spec/graphql/static_validation/validator_spec.rb +26 -6
  136. data/spec/graphql/union_type_spec.rb +5 -4
  137. data/spec/spec_helper.rb +2 -5
  138. data/spec/support/dairy_app.rb +30 -9
  139. data/spec/support/dairy_data.rb +1 -1
  140. data/spec/support/star_wars_data.rb +26 -26
  141. data/spec/support/star_wars_schema.rb +1 -1
  142. metadata +40 -21
  143. data/lib/graphql/language/transform.rb +0 -113
  144. data/lib/graphql/query/directive_chain.rb +0 -44
  145. data/lib/graphql/repl.rb +0 -27
  146. data/spec/graphql/language/transform_spec.rb +0 -156
@@ -1,4 +1,4 @@
1
- require 'spec_helper'
1
+ require "spec_helper"
2
2
 
3
3
  describe GraphQL::StaticValidation::FieldsWillMerge do
4
4
  let(:query_string) {"
@@ -34,7 +34,7 @@ describe GraphQL::StaticValidation::FieldsWillMerge do
34
34
  let(:errors) { validator.validate(query) }
35
35
  let(:error_messages) { errors.map { |e| e["message" ] }}
36
36
 
37
- it 'finds field naming conflicts' do
37
+ it "finds field naming conflicts" do
38
38
  expected_errors = [
39
39
  "Field 'id' has a directive conflict: [] or [someFlag]?", # different directives
40
40
  "Field 'id' has a directive argument conflict: [] or [{}]?", # not sure this is a great way to handle it but here we are!
@@ -1,4 +1,4 @@
1
- require 'spec_helper'
1
+ require "spec_helper"
2
2
 
3
3
  describe GraphQL::StaticValidation::FragmentSpreadsArePossible do
4
4
  let(:query_string) {%|
@@ -1,4 +1,4 @@
1
- require 'spec_helper'
1
+ require "spec_helper"
2
2
 
3
3
  describe GraphQL::StaticValidation::FragmentTypesExist do
4
4
  let(:query_string) {"
@@ -23,7 +23,7 @@ describe GraphQL::StaticValidation::FragmentTypesExist do
23
23
  let(:query) { GraphQL::Query.new(DummySchema, query_string) }
24
24
  let(:errors) { validator.validate(query) }
25
25
 
26
- it 'finds non-existent types on fragments' do
26
+ it "finds non-existent types on fragments" do
27
27
  assert_equal(2, errors.length)
28
28
  inline_fragment_error = {
29
29
  "message"=>"No such type Something, so it can't be a fragment condition",
@@ -1,4 +1,4 @@
1
- require 'spec_helper'
1
+ require "spec_helper"
2
2
 
3
3
  describe GraphQL::StaticValidation::FragmentsAreFinite do
4
4
  let(:query_string) {%|
@@ -28,7 +28,7 @@ describe GraphQL::StaticValidation::FragmentsAreFinite do
28
28
  let(:query) { GraphQL::Query.new(DummySchema, query_string) }
29
29
  let(:errors) { validator.validate(query) }
30
30
 
31
- it 'doesnt allow infinite loops' do
31
+ it "doesnt allow infinite loops" do
32
32
  expected = [
33
33
  {
34
34
  "message"=>"Fragment sourceField contains an infinite loop",
@@ -1,4 +1,4 @@
1
- require 'spec_helper'
1
+ require "spec_helper"
2
2
 
3
3
  describe GraphQL::StaticValidation::FragmentsAreOnCompositeTypes do
4
4
  let(:query_string) {%|
@@ -29,7 +29,7 @@ describe GraphQL::StaticValidation::FragmentsAreOnCompositeTypes do
29
29
  let(:query) { GraphQL::Query.new(DummySchema, query_string) }
30
30
  let(:errors) { validator.validate(query) }
31
31
 
32
- it 'requires Object/Union/Interface fragment types' do
32
+ it "requires Object/Union/Interface fragment types" do
33
33
  expected = [
34
34
  {
35
35
  "message"=>"Invalid fragment on type Boolean (must be Union, Interface or Object)",
@@ -1,4 +1,4 @@
1
- require 'spec_helper'
1
+ require "spec_helper"
2
2
 
3
3
  describe GraphQL::StaticValidation::FragmentsAreUsed do
4
4
  let(:query_string) {"
@@ -15,11 +15,11 @@ describe GraphQL::StaticValidation::FragmentsAreUsed do
15
15
  let(:query) { GraphQL::Query.new(DummySchema, query_string) }
16
16
  let(:errors) { validator.validate(query) }
17
17
 
18
- it 'adds errors for unused fragment definitions' do
18
+ it "adds errors for unused fragment definitions" do
19
19
  assert_includes(errors, {"message"=>"Fragment unusedFields was defined, but not used", "locations"=>[{"line"=>8, "column"=>5}]})
20
20
  end
21
21
 
22
- it 'adds errors for undefined fragment spreads' do
22
+ it "adds errors for undefined fragment spreads" do
23
23
  assert_includes(errors, {"message"=>"Fragment undefinedFields was used, but not defined", "locations"=>[{"line"=>5, "column"=>7}]})
24
24
  end
25
25
  end
@@ -1,4 +1,4 @@
1
- require 'spec_helper'
1
+ require "spec_helper"
2
2
 
3
3
  describe GraphQL::StaticValidation::RequiredArgumentsArePresent do
4
4
  let(:query_string) {"
@@ -18,7 +18,7 @@ describe GraphQL::StaticValidation::RequiredArgumentsArePresent do
18
18
  let(:query) { GraphQL::Query.new(DummySchema, query_string) }
19
19
  let(:errors) { validator.validate(query) }
20
20
 
21
- it 'finds undefined arguments to fields and directives' do
21
+ it "finds undefined arguments to fields and directives" do
22
22
  assert_equal(3, errors.length)
23
23
 
24
24
  query_root_error = {
@@ -35,7 +35,7 @@ describe GraphQL::StaticValidation::RequiredArgumentsArePresent do
35
35
 
36
36
  directive_error = {
37
37
  "message"=>"Directive 'skip' is missing required arguments: if",
38
- "locations"=>[{"line"=>10, "column"=>11}]
38
+ "locations"=>[{"line"=>10, "column"=>10}]
39
39
  }
40
40
  assert_includes(errors, directive_error)
41
41
  end
@@ -1,4 +1,4 @@
1
- require 'spec_helper'
1
+ require "spec_helper"
2
2
 
3
3
  describe GraphQL::StaticValidation::VariableDefaultValuesAreCorrectlyTyped do
4
4
  let(:query_string) {%|
@@ -24,19 +24,19 @@ describe GraphQL::StaticValidation::VariableDefaultValuesAreCorrectlyTyped do
24
24
  expected = [
25
25
  {
26
26
  "message"=>"Default value for $badFloat doesn't match type Float",
27
- "locations"=>[{"line"=>6, "column"=>8}]
27
+ "locations"=>[{"line"=>6, "column"=>7}]
28
28
  },
29
29
  {
30
30
  "message"=>"Default value for $badInt doesn't match type Int",
31
- "locations"=>[{"line"=>7, "column"=>8}]
31
+ "locations"=>[{"line"=>7, "column"=>7}]
32
32
  },
33
33
  {
34
34
  "message"=>"Default value for $badInput doesn't match type DairyProductInput",
35
- "locations"=>[{"line"=>9, "column"=>8}]
35
+ "locations"=>[{"line"=>9, "column"=>7}]
36
36
  },
37
37
  {
38
38
  "message"=>"Non-null variable $nonNull can't have a default value",
39
- "locations"=>[{"line"=>10, "column"=>8}]
39
+ "locations"=>[{"line"=>10, "column"=>7}]
40
40
  }
41
41
  ]
42
42
  assert_equal(expected, errors)
@@ -1,4 +1,4 @@
1
- require 'spec_helper'
1
+ require "spec_helper"
2
2
 
3
3
  describe GraphQL::StaticValidation::VariableUsagesAreAllowed do
4
4
  let(:query_string) {'
@@ -20,6 +20,8 @@ describe GraphQL::StaticValidation::VariableUsagesAreAllowed do
20
20
  similarCheese(source: $goodAnimals)
21
21
  other: similarCheese(source: $badAnimals)
22
22
  tooDeep: similarCheese(source: $deepAnimals)
23
+ nullableCheese(source: $goodAnimals)
24
+ deeplyNullableCheese(source: $deepAnimals)
23
25
  }
24
26
 
25
27
  milk(id: 1) {
@@ -1,4 +1,4 @@
1
- require 'spec_helper'
1
+ require "spec_helper"
2
2
 
3
3
  describe GraphQL::StaticValidation::VariablesAreInputTypes do
4
4
  let(:query_string) {'
@@ -21,15 +21,15 @@ describe GraphQL::StaticValidation::VariablesAreInputTypes do
21
21
  expected = [
22
22
  {
23
23
  "message"=>"AnimalProduct isn't a valid input type (on $interface)",
24
- "locations"=>[{"line"=>5, "column"=>8}]
24
+ "locations"=>[{"line"=>5, "column"=>7}]
25
25
  },
26
26
  {
27
27
  "message"=>"Milk isn't a valid input type (on $object)",
28
- "locations"=>[{"line"=>6, "column"=>8}]
28
+ "locations"=>[{"line"=>6, "column"=>7}]
29
29
  },
30
30
  {
31
31
  "message"=>"Cheese isn't a valid input type (on $objects)",
32
- "locations"=>[{"line"=>7, "column"=>8}]
32
+ "locations"=>[{"line"=>7, "column"=>7}]
33
33
  }
34
34
  ]
35
35
  assert_equal(expected, errors)
@@ -1,4 +1,4 @@
1
- require 'spec_helper'
1
+ require "spec_helper"
2
2
 
3
3
  describe GraphQL::StaticValidation::VariablesAreUsedAndDefined do
4
4
  let(:query_string) {'
@@ -41,11 +41,11 @@ describe GraphQL::StaticValidation::VariablesAreUsedAndDefined do
41
41
  },
42
42
  {
43
43
  "message"=>"Variable $undefinedVar is used by getCheese but not declared",
44
- "locations"=>[{"line"=>11, "column"=>30}]
44
+ "locations"=>[{"line"=>11, "column"=>29}]
45
45
  },
46
46
  {
47
47
  "message"=>"Variable $undefinedFragmentVar is used by innerCheeseFields but not declared",
48
- "locations"=>[{"line"=>24, "column"=>27}]
48
+ "locations"=>[{"line"=>24, "column"=>26}]
49
49
  },
50
50
  ]
51
51
  assert_equal(expected, errors)
@@ -1,4 +1,4 @@
1
- require 'spec_helper'
1
+ require "spec_helper"
2
2
 
3
3
  class TypeCheckValidator
4
4
  def self.checks
@@ -24,7 +24,8 @@ describe GraphQL::StaticValidation::TypeStack do
24
24
  let(:validator) { GraphQL::StaticValidation::Validator.new(schema: DummySchema, rules: [TypeCheckValidator]) }
25
25
  let(:query) { GraphQL::Query.new(DummySchema, query_string) }
26
26
 
27
- it 'stores up types' do
27
+
28
+ it "stores up types" do
28
29
  validator.validate(query)
29
30
  expected = [
30
31
  ["Query", "Cheese"],
@@ -1,13 +1,15 @@
1
- require 'spec_helper'
1
+ require "spec_helper"
2
2
 
3
3
  describe GraphQL::StaticValidation::Validator do
4
4
  let(:validator) { GraphQL::StaticValidation::Validator.new(schema: DummySchema) }
5
5
  let(:query) { GraphQL::Query.new(DummySchema, query_string) }
6
6
  let(:errors) { validator.validate(query) }
7
7
 
8
- describe 'validation order' do
9
8
 
10
- describe 'fields & arguments' do
9
+ describe "validation order" do
10
+ let(:document) { GraphQL.parse(query_string)}
11
+
12
+ describe "fields & arguments" do
11
13
  let(:query_string) { %|
12
14
  query getCheese($id: Int!) {
13
15
  cheese(id: $undefinedVar, bogusArg: true) {
@@ -23,13 +25,13 @@ describe GraphQL::StaticValidation::Validator do
23
25
  }
24
26
  |}
25
27
 
26
- it 'handles args on invalid fields' do
28
+ it "handles args on invalid fields" do
27
29
  # nonsenseField, nonsenseArg, bogusField, bogusArg, undefinedVar
28
30
  assert_equal(5, errors.length)
29
31
  end
30
32
  end
31
33
 
32
- describe 'infinite fragments' do
34
+ describe "infinite fragments" do
33
35
  let(:query_string) { %|
34
36
  query getCheese {
35
37
  cheese(id: 1) {
@@ -41,7 +43,25 @@ describe GraphQL::StaticValidation::Validator do
41
43
  }
42
44
  |}
43
45
 
44
- it 'handles infinite fragment spreads' do
46
+ it "handles infinite fragment spreads" do
47
+ assert_equal(1, errors.length)
48
+ end
49
+ end
50
+
51
+ describe "fragment spreads with no selections" do
52
+ let(:query_string) {%|
53
+ query SimpleQuery {
54
+ cheese(id: 1) {
55
+ # OK:
56
+ ... {
57
+ id
58
+ }
59
+ # NOT OK:
60
+ ...cheeseFields
61
+ }
62
+ }
63
+ |}
64
+ it "marks an error" do
45
65
  assert_equal(1, errors.length)
46
66
  end
47
67
  end
@@ -1,4 +1,4 @@
1
- require 'spec_helper'
1
+ require "spec_helper"
2
2
 
3
3
  describe GraphQL::UnionType do
4
4
  let(:type_1) { OpenStruct.new(kind: GraphQL::TypeKinds::OBJECT)}
@@ -12,12 +12,13 @@ describe GraphQL::UnionType do
12
12
  possible_types(types)
13
13
  }
14
14
  }
15
- it 'has a name' do
15
+ it "has a name" do
16
16
  assert_equal("MyUnion", union.name)
17
17
  end
18
18
 
19
- it 'infers type from an object' do
20
- assert_equal(CheeseType, DairyProductUnion.resolve_type(CHEESES[1]))
19
+
20
+ it "infers type from an object" do
21
+ assert_equal(CheeseType, DairyProductUnion.resolve_type(CHEESES[1], OpenStruct.new(schema: DummySchema)))
21
22
  end
22
23
 
23
24
  it '#include? returns true if type in in possible_types' do
@@ -1,11 +1,11 @@
1
1
  require "codeclimate-test-reporter"
2
2
  CodeClimate::TestReporter.start
3
- require 'graphql'
3
+ require "graphql"
4
4
  require "benchmark"
5
5
  require "minitest/autorun"
6
6
  require "minitest/focus"
7
7
  require "minitest/reporters"
8
- require 'pry'
8
+ require "pry"
9
9
  Minitest::Reporters.use! Minitest::Reporters::SpecReporter.new
10
10
 
11
11
  Minitest::Spec.make_my_diffs_pretty!
@@ -16,6 +16,3 @@ Minitest.backtrace_filter = Minitest::BacktraceFilter.new
16
16
 
17
17
  # # Load support files
18
18
  Dir["#{File.dirname(__FILE__)}/support/**/*.rb"].each { |f| require f }
19
-
20
- require 'parslet'
21
- require 'parslet/convenience'
@@ -1,4 +1,4 @@
1
- require_relative './dairy_data'
1
+ require_relative "./dairy_data"
2
2
 
3
3
  class NoSuchDairyError < StandardError; end
4
4
 
@@ -51,6 +51,16 @@ CheeseType = GraphQL::ObjectType.define do
51
51
  }
52
52
  end
53
53
 
54
+ field :nullableCheese, -> { CheeseType }, "Cheeses like this one" do
55
+ argument :source, types[!DairyAnimalEnum]
56
+ resolve -> (t, a, c) { raise("NotImplemented") }
57
+ end
58
+
59
+ field :deeplyNullableCheese, -> { CheeseType }, "Cheeses like this one" do
60
+ argument :source, types[types[DairyAnimalEnum]]
61
+ resolve -> (t, a, c) { raise("NotImplemented") }
62
+ end
63
+
54
64
  field :fatContent, property: :fat_content do
55
65
  type(!GraphQL::FLOAT_TYPE)
56
66
  description("Percentage which is milkfat")
@@ -59,7 +69,7 @@ CheeseType = GraphQL::ObjectType.define do
59
69
  end
60
70
 
61
71
  MilkType = GraphQL::ObjectType.define do
62
- name 'Milk'
72
+ name "Milk"
63
73
  description "Dairy beverage"
64
74
  interfaces [EdibleInterface, AnimalProductInterface]
65
75
  field :id, !types.ID
@@ -75,14 +85,14 @@ end
75
85
 
76
86
  # No actual data; This type is an "orphan", only accessible through Interfaces
77
87
  HoneyType = GraphQL::ObjectType.define do
78
- name 'Honey'
88
+ name "Honey"
79
89
  description "Sweet, dehydrated bee barf"
80
90
  interfaces [EdibleInterface, AnimalProductInterface]
81
91
  end
82
92
 
83
93
  DairyType = GraphQL::ObjectType.define do
84
- name 'Dairy'
85
- description 'A farm where milk is harvested and cheese is produced'
94
+ name "Dairy"
95
+ description "A farm where milk is harvested and cheese is produced"
86
96
  field :id, !types.ID
87
97
  field :cheese, CheeseType
88
98
  field :milks, types[MilkType]
@@ -101,8 +111,8 @@ DairyProductUnion = GraphQL::UnionType.define do
101
111
  end
102
112
 
103
113
  CowType = GraphQL::ObjectType.define do
104
- name 'Cow'
105
- description 'A farm where milk is harvested and cheese is produced'
114
+ name "Cow"
115
+ description "A farm where milk is harvested and cheese is produced"
106
116
  field :id, !types.ID
107
117
  field :name, types.String
108
118
  field :last_produced_dairy, DairyProductUnion
@@ -122,12 +132,22 @@ DairyProductInputType = GraphQL::InputObjectType.define {
122
132
  name "DairyProductInput"
123
133
  description "Properties for finding a dairy product"
124
134
  input_field :source, !DairyAnimalEnum do
135
+ # ensure we can define description in block
125
136
  description "Where it came from"
126
137
  end
127
138
 
128
- input_field :originDairy, types.String, "Dairy which produced it", default_value: "Sugar Hollow Dairy"
139
+ input_field :originDairy, types.String, "Dairy which produced it", default_value: "Sugar Hollow Dairy" do
140
+ description "Ignored because arg takes precedence"
141
+ default_value "Ignored because keyword arg takes precedence"
142
+ end
143
+
144
+ input_field :fatContent, types.Float, "How much fat it has" do
145
+ # ensure we can define default in block
146
+ default_value 0.3
147
+ end
129
148
 
130
- input_field :fatContent, types.Float, "How much fat it has"
149
+ # ensure default can be false
150
+ input_field :organic, types.Boolean, default_value: false
131
151
  }
132
152
 
133
153
 
@@ -260,5 +280,6 @@ DummySchema = GraphQL::Schema.new(
260
280
  mutation: MutationType,
261
281
  subscription: SubscriptionType,
262
282
  max_depth: 5,
283
+ types: [HoneyType],
263
284
  )
264
285
  DummySchema.rescue_from(NoSuchDairyError) { |err| err.message }
@@ -18,6 +18,6 @@ DAIRY = OpenStruct.new(
18
18
 
19
19
  COW = OpenStruct.new(
20
20
  id: 1,
21
- name: 'Billy',
21
+ name: "Billy",
22
22
  last_produced_dairy: MILKS[1]
23
23
  )
@@ -1,38 +1,38 @@
1
1
  luke = OpenStruct.new({
2
- id: '1000',
3
- name: 'Luke Skywalker',
4
- friends: ['1002', '1003', '2000', '2001'],
2
+ id: "1000",
3
+ name: "Luke Skywalker",
4
+ friends: ["1002", "1003", "2000", "2001"],
5
5
  appearsIn: [4, 5, 6],
6
- homePlanet: 'Tatooine',
6
+ homePlanet: "Tatooine",
7
7
  })
8
8
 
9
9
  vader = OpenStruct.new({
10
- id: '1001',
11
- name: 'Darth Vader',
12
- friends: ['1004'],
10
+ id: "1001",
11
+ name: "Darth Vader",
12
+ friends: ["1004"],
13
13
  appearsIn: [4, 5, 6],
14
- homePlanet: 'Tatooine',
14
+ homePlanet: "Tatooine",
15
15
  })
16
16
 
17
17
  han = OpenStruct.new({
18
- id: '1002',
19
- name: 'Han Solo',
20
- friends: ['1000', '1003', '2001'],
18
+ id: "1002",
19
+ name: "Han Solo",
20
+ friends: ["1000", "1003", "2001"],
21
21
  appearsIn: [4, 5, 6],
22
22
  })
23
23
 
24
24
  leia = OpenStruct.new({
25
- id: '1003',
26
- name: 'Leia Organa',
27
- friends: ['1000', '1002', '2000', '2001'],
25
+ id: "1003",
26
+ name: "Leia Organa",
27
+ friends: ["1000", "1002", "2000", "2001"],
28
28
  appearsIn: [4, 5, 6],
29
- homePlanet: 'Alderaan',
29
+ homePlanet: "Alderaan",
30
30
  })
31
31
 
32
32
  tarkin = OpenStruct.new({
33
- id: '1004',
34
- name: 'Wilhuff Tarkin',
35
- friends: ['1001'],
33
+ id: "1004",
34
+ name: "Wilhuff Tarkin",
35
+ friends: ["1001"],
36
36
  appearsIn: [4],
37
37
  })
38
38
 
@@ -45,19 +45,19 @@ HUMAN_DATA = {
45
45
  }
46
46
 
47
47
  threepio = OpenStruct.new({
48
- id: '2000',
49
- name: 'C-3PO',
50
- friends: ['1000', '1002', '1003', '2001'],
48
+ id: "2000",
49
+ name: "C-3PO",
50
+ friends: ["1000", "1002", "1003", "2001"],
51
51
  appearsIn: [4, 5, 6],
52
- primaryFunction: 'Protocol',
52
+ primaryFunction: "Protocol",
53
53
  })
54
54
 
55
55
  artoo = OpenStruct.new({
56
- id: '2001',
57
- name: 'R2-D2',
58
- friends: ['1000', '1002', '1003'],
56
+ id: "2001",
57
+ name: "R2-D2",
58
+ friends: ["1000", "1002", "1003"],
59
59
  appearsIn: [4, 5, 6],
60
- primaryFunction: 'Astromech',
60
+ primaryFunction: "Astromech",
61
61
  })
62
62
 
63
63
  DROID_DATA = {