graphql 1.9.0.pre1 → 1.9.0.pre2

Sign up to get free protection for your applications and to get access to all the features.
Files changed (235) hide show
  1. checksums.yaml +4 -4
  2. data/lib/graphql.rb +5 -1
  3. data/lib/graphql/analysis/ast/analyzer.rb +1 -1
  4. data/lib/graphql/analysis/ast/visitor.rb +6 -1
  5. data/lib/graphql/backwards_compatibility.rb +1 -1
  6. data/lib/graphql/dig.rb +19 -0
  7. data/lib/graphql/directive.rb +13 -1
  8. data/lib/graphql/directive/include_directive.rb +1 -7
  9. data/lib/graphql/directive/skip_directive.rb +1 -8
  10. data/lib/graphql/execution/interpreter.rb +23 -13
  11. data/lib/graphql/execution/interpreter/resolve.rb +56 -0
  12. data/lib/graphql/execution/interpreter/runtime.rb +174 -74
  13. data/lib/graphql/execution/lazy.rb +7 -1
  14. data/lib/graphql/execution/lookahead.rb +71 -6
  15. data/lib/graphql/execution_error.rb +1 -1
  16. data/lib/graphql/introspection/entry_points.rb +5 -1
  17. data/lib/graphql/introspection/type_type.rb +4 -4
  18. data/lib/graphql/language.rb +0 -1
  19. data/lib/graphql/language/block_string.rb +37 -0
  20. data/lib/graphql/language/document_from_schema_definition.rb +1 -1
  21. data/lib/graphql/language/lexer.rb +55 -36
  22. data/lib/graphql/language/lexer.rl +8 -3
  23. data/lib/graphql/language/nodes.rb +27 -4
  24. data/lib/graphql/language/parser.rb +55 -55
  25. data/lib/graphql/language/parser.y +11 -11
  26. data/lib/graphql/language/printer.rb +1 -1
  27. data/lib/graphql/language/visitor.rb +22 -13
  28. data/lib/graphql/literal_validation_error.rb +6 -0
  29. data/lib/graphql/query.rb +13 -0
  30. data/lib/graphql/query/arguments.rb +2 -1
  31. data/lib/graphql/query/context.rb +3 -10
  32. data/lib/graphql/query/executor.rb +1 -1
  33. data/lib/graphql/query/validation_pipeline.rb +1 -1
  34. data/lib/graphql/relay/connection_resolve.rb +1 -1
  35. data/lib/graphql/relay/relation_connection.rb +1 -1
  36. data/lib/graphql/schema.rb +81 -11
  37. data/lib/graphql/schema/argument.rb +1 -1
  38. data/lib/graphql/schema/build_from_definition.rb +2 -4
  39. data/lib/graphql/schema/directive.rb +103 -0
  40. data/lib/graphql/schema/directive/feature.rb +66 -0
  41. data/lib/graphql/schema/directive/include.rb +25 -0
  42. data/lib/graphql/schema/directive/skip.rb +25 -0
  43. data/lib/graphql/schema/directive/transform.rb +48 -0
  44. data/lib/graphql/schema/enum_value.rb +2 -2
  45. data/lib/graphql/schema/field.rb +63 -17
  46. data/lib/graphql/schema/input_object.rb +1 -0
  47. data/lib/graphql/schema/member/base_dsl_methods.rb +4 -2
  48. data/lib/graphql/schema/member/build_type.rb +33 -1
  49. data/lib/graphql/schema/member/has_fields.rb +8 -73
  50. data/lib/graphql/schema/relay_classic_mutation.rb +6 -1
  51. data/lib/graphql/schema/resolver.rb +1 -1
  52. data/lib/graphql/static_validation.rb +2 -1
  53. data/lib/graphql/static_validation/all_rules.rb +1 -0
  54. data/lib/graphql/static_validation/base_visitor.rb +25 -10
  55. data/lib/graphql/static_validation/definition_dependencies.rb +3 -3
  56. data/lib/graphql/static_validation/{message.rb → error.rb} +11 -11
  57. data/lib/graphql/static_validation/interpreter_visitor.rb +14 -0
  58. data/lib/graphql/static_validation/literal_validator.rb +54 -11
  59. data/lib/graphql/static_validation/rules/argument_literals_are_compatible.rb +34 -5
  60. data/lib/graphql/static_validation/rules/argument_literals_are_compatible_error.rb +31 -0
  61. data/lib/graphql/static_validation/rules/argument_names_are_unique.rb +2 -2
  62. data/lib/graphql/static_validation/rules/argument_names_are_unique_error.rb +30 -0
  63. data/lib/graphql/static_validation/rules/arguments_are_defined.rb +7 -1
  64. data/lib/graphql/static_validation/rules/arguments_are_defined_error.rb +35 -0
  65. data/lib/graphql/static_validation/rules/directives_are_defined.rb +5 -1
  66. data/lib/graphql/static_validation/rules/directives_are_defined_error.rb +29 -0
  67. data/lib/graphql/static_validation/rules/directives_are_in_valid_locations.rb +11 -2
  68. data/lib/graphql/static_validation/rules/directives_are_in_valid_locations_error.rb +31 -0
  69. data/lib/graphql/static_validation/rules/fields_are_defined_on_type.rb +11 -2
  70. data/lib/graphql/static_validation/rules/fields_are_defined_on_type_error.rb +32 -0
  71. data/lib/graphql/static_validation/rules/fields_have_appropriate_selections.rb +14 -2
  72. data/lib/graphql/static_validation/rules/fields_have_appropriate_selections_error.rb +31 -0
  73. data/lib/graphql/static_validation/rules/fields_will_merge.rb +24 -6
  74. data/lib/graphql/static_validation/rules/fields_will_merge_error.rb +32 -0
  75. data/lib/graphql/static_validation/rules/fragment_names_are_unique.rb +5 -1
  76. data/lib/graphql/static_validation/rules/fragment_names_are_unique_error.rb +29 -0
  77. data/lib/graphql/static_validation/rules/fragment_spreads_are_possible.rb +8 -1
  78. data/lib/graphql/static_validation/rules/fragment_spreads_are_possible_error.rb +35 -0
  79. data/lib/graphql/static_validation/rules/fragment_types_exist.rb +5 -1
  80. data/lib/graphql/static_validation/rules/fragment_types_exist_error.rb +29 -0
  81. data/lib/graphql/static_validation/rules/fragments_are_finite.rb +6 -1
  82. data/lib/graphql/static_validation/rules/fragments_are_finite_error.rb +29 -0
  83. data/lib/graphql/static_validation/rules/fragments_are_named.rb +4 -1
  84. data/lib/graphql/static_validation/rules/fragments_are_named_error.rb +26 -0
  85. data/lib/graphql/static_validation/rules/fragments_are_on_composite_types.rb +5 -1
  86. data/lib/graphql/static_validation/rules/fragments_are_on_composite_types_error.rb +30 -0
  87. data/lib/graphql/static_validation/rules/fragments_are_used.rb +13 -3
  88. data/lib/graphql/static_validation/rules/fragments_are_used_error.rb +29 -0
  89. data/lib/graphql/static_validation/rules/mutation_root_exists.rb +4 -1
  90. data/lib/graphql/static_validation/rules/mutation_root_exists_error.rb +26 -0
  91. data/lib/graphql/static_validation/rules/no_definitions_are_present.rb +2 -2
  92. data/lib/graphql/static_validation/rules/no_definitions_are_present_error.rb +25 -0
  93. data/lib/graphql/static_validation/rules/operation_names_are_valid.rb +9 -2
  94. data/lib/graphql/static_validation/rules/operation_names_are_valid_error.rb +28 -0
  95. data/lib/graphql/static_validation/rules/required_arguments_are_present.rb +7 -1
  96. data/lib/graphql/static_validation/rules/required_arguments_are_present_error.rb +35 -0
  97. data/lib/graphql/static_validation/rules/required_input_object_attributes_are_present.rb +47 -0
  98. data/lib/graphql/static_validation/rules/required_input_object_attributes_are_present_error.rb +35 -0
  99. data/lib/graphql/static_validation/rules/subscription_root_exists.rb +4 -1
  100. data/lib/graphql/static_validation/rules/subscription_root_exists_error.rb +26 -0
  101. data/lib/graphql/static_validation/rules/unique_directives_per_location.rb +4 -3
  102. data/lib/graphql/static_validation/rules/unique_directives_per_location_error.rb +29 -0
  103. data/lib/graphql/static_validation/rules/variable_default_values_are_correctly_typed.rb +20 -6
  104. data/lib/graphql/static_validation/rules/variable_default_values_are_correctly_typed_error.rb +39 -0
  105. data/lib/graphql/static_validation/rules/variable_names_are_unique.rb +5 -1
  106. data/lib/graphql/static_validation/rules/variable_names_are_unique_error.rb +29 -0
  107. data/lib/graphql/static_validation/rules/variable_usages_are_allowed.rb +8 -1
  108. data/lib/graphql/static_validation/rules/variable_usages_are_allowed_error.rb +38 -0
  109. data/lib/graphql/static_validation/rules/variables_are_input_types.rb +12 -2
  110. data/lib/graphql/static_validation/rules/variables_are_input_types_error.rb +32 -0
  111. data/lib/graphql/static_validation/rules/variables_are_used_and_defined.rb +18 -2
  112. data/lib/graphql/static_validation/rules/variables_are_used_and_defined_error.rb +37 -0
  113. data/lib/graphql/static_validation/validator.rb +24 -14
  114. data/lib/graphql/tracing/new_relic_tracing.rb +2 -2
  115. data/lib/graphql/tracing/skylight_tracing.rb +2 -2
  116. data/lib/graphql/unauthorized_field_error.rb +23 -0
  117. data/lib/graphql/version.rb +1 -1
  118. data/spec/graphql/analysis/ast_spec.rb +40 -0
  119. data/spec/graphql/authorization_spec.rb +93 -20
  120. data/spec/graphql/base_type_spec.rb +3 -1
  121. data/spec/graphql/execution/interpreter_spec.rb +127 -4
  122. data/spec/graphql/execution/lazy_spec.rb +49 -0
  123. data/spec/graphql/execution/lookahead_spec.rb +113 -21
  124. data/spec/graphql/execution/multiplex_spec.rb +2 -1
  125. data/spec/graphql/introspection/type_type_spec.rb +1 -1
  126. data/spec/graphql/language/lexer_spec.rb +72 -3
  127. data/spec/graphql/language/printer_spec.rb +18 -6
  128. data/spec/graphql/query/arguments_spec.rb +21 -0
  129. data/spec/graphql/query/context_spec.rb +10 -0
  130. data/spec/graphql/schema/build_from_definition_spec.rb +144 -29
  131. data/spec/graphql/schema/directive/feature_spec.rb +81 -0
  132. data/spec/graphql/schema/directive/transform_spec.rb +39 -0
  133. data/spec/graphql/schema/enum_spec.rb +5 -3
  134. data/spec/graphql/schema/field_extension_spec.rb +3 -3
  135. data/spec/graphql/schema/field_spec.rb +19 -0
  136. data/spec/graphql/schema/input_object_spec.rb +81 -0
  137. data/spec/graphql/schema/member/build_type_spec.rb +46 -0
  138. data/spec/graphql/schema/member/scoped_spec.rb +3 -3
  139. data/spec/graphql/schema/printer_spec.rb +244 -96
  140. data/spec/graphql/schema/relay_classic_mutation_spec.rb +26 -0
  141. data/spec/graphql/schema/resolver_spec.rb +1 -1
  142. data/spec/graphql/schema/warden_spec.rb +35 -11
  143. data/spec/graphql/static_validation/rules/argument_literals_are_compatible_spec.rb +212 -72
  144. data/spec/graphql/static_validation/rules/argument_names_are_unique_spec.rb +2 -2
  145. data/spec/graphql/static_validation/rules/arguments_are_defined_spec.rb +72 -29
  146. data/spec/graphql/static_validation/rules/directives_are_defined_spec.rb +4 -2
  147. data/spec/graphql/static_validation/rules/directives_are_in_valid_locations_spec.rb +4 -2
  148. data/spec/graphql/static_validation/rules/fields_are_defined_on_type_spec.rb +10 -5
  149. data/spec/graphql/static_validation/rules/fields_have_appropriate_selections_spec.rb +10 -5
  150. data/spec/graphql/static_validation/rules/fields_will_merge_spec.rb +2 -1
  151. data/spec/graphql/static_validation/rules/fragment_names_are_unique_spec.rb +2 -1
  152. data/spec/graphql/static_validation/rules/fragment_spreads_are_possible_spec.rb +6 -3
  153. data/spec/graphql/static_validation/rules/fragment_types_exist_spec.rb +4 -2
  154. data/spec/graphql/static_validation/rules/fragments_are_finite_spec.rb +4 -2
  155. data/spec/graphql/static_validation/rules/fragments_are_named_spec.rb +2 -1
  156. data/spec/graphql/static_validation/rules/fragments_are_on_composite_types_spec.rb +6 -3
  157. data/spec/graphql/static_validation/rules/fragments_are_used_spec.rb +22 -2
  158. data/spec/graphql/static_validation/rules/mutation_root_exists_spec.rb +2 -1
  159. data/spec/graphql/static_validation/rules/operation_names_are_valid_spec.rb +6 -3
  160. data/spec/graphql/static_validation/rules/required_arguments_are_present_spec.rb +13 -4
  161. data/spec/graphql/static_validation/rules/required_input_object_attributes_are_present_spec.rb +58 -0
  162. data/spec/graphql/static_validation/rules/subscription_root_exists_spec.rb +2 -1
  163. data/spec/graphql/static_validation/rules/unique_directives_per_location_spec.rb +14 -7
  164. data/spec/graphql/static_validation/rules/variable_default_values_are_correctly_typed_spec.rb +14 -7
  165. data/spec/graphql/static_validation/rules/variable_usages_are_allowed_spec.rb +8 -4
  166. data/spec/graphql/static_validation/rules/variables_are_input_types_spec.rb +8 -4
  167. data/spec/graphql/static_validation/rules/variables_are_used_and_defined_spec.rb +6 -3
  168. data/spec/graphql/static_validation/validator_spec.rb +6 -4
  169. data/spec/graphql/tracing/new_relic_tracing_spec.rb +10 -0
  170. data/spec/graphql/tracing/skylight_tracing_spec.rb +10 -0
  171. data/spec/graphql/types/iso_8601_date_time_spec.rb +1 -2
  172. data/spec/integration/mongoid/star_trek/schema.rb +5 -5
  173. data/spec/integration/rails/graphql/relay/relation_connection_spec.rb +37 -8
  174. data/spec/integration/rails/graphql/schema_spec.rb +2 -2
  175. data/spec/integration/rails/spec_helper.rb +10 -0
  176. data/spec/integration/tmp/app/graphql/types/bird_type.rb +7 -0
  177. data/spec/integration/tmp/dummy/Gemfile +45 -0
  178. data/spec/integration/tmp/dummy/README.rdoc +28 -0
  179. data/spec/integration/tmp/dummy/Rakefile +6 -0
  180. data/spec/integration/tmp/dummy/app/assets/javascripts/application.js +16 -0
  181. data/spec/integration/tmp/dummy/app/assets/stylesheets/application.css +15 -0
  182. data/spec/integration/tmp/dummy/app/controllers/application_controller.rb +5 -0
  183. data/spec/integration/tmp/dummy/app/controllers/graphql_controller.rb +43 -0
  184. data/spec/integration/tmp/dummy/app/graphql/dummy_schema.rb +34 -0
  185. data/spec/integration/tmp/dummy/app/graphql/types/base_enum.rb +4 -0
  186. data/spec/integration/tmp/dummy/app/graphql/types/base_input_object.rb +4 -0
  187. data/spec/integration/tmp/dummy/app/graphql/types/base_interface.rb +5 -0
  188. data/spec/integration/tmp/dummy/app/graphql/types/base_object.rb +4 -0
  189. data/spec/integration/tmp/dummy/app/graphql/types/base_scalar.rb +4 -0
  190. data/spec/integration/tmp/dummy/app/graphql/types/base_union.rb +4 -0
  191. data/spec/integration/tmp/dummy/app/graphql/types/mutation_type.rb +10 -0
  192. data/spec/integration/tmp/dummy/app/graphql/types/query_type.rb +15 -0
  193. data/spec/integration/tmp/dummy/app/helpers/application_helper.rb +2 -0
  194. data/spec/integration/tmp/dummy/app/views/layouts/application.html.erb +14 -0
  195. data/spec/integration/tmp/dummy/bin/bundle +3 -0
  196. data/spec/integration/tmp/dummy/bin/rails +4 -0
  197. data/spec/integration/tmp/dummy/bin/rake +4 -0
  198. data/spec/integration/tmp/dummy/bin/setup +29 -0
  199. data/spec/integration/tmp/dummy/config.ru +4 -0
  200. data/spec/integration/tmp/dummy/config/application.rb +32 -0
  201. data/spec/integration/tmp/dummy/config/boot.rb +3 -0
  202. data/spec/integration/tmp/dummy/config/environment.rb +5 -0
  203. data/spec/integration/tmp/dummy/config/environments/development.rb +38 -0
  204. data/spec/integration/tmp/dummy/config/environments/production.rb +76 -0
  205. data/spec/integration/tmp/dummy/config/environments/test.rb +42 -0
  206. data/spec/integration/tmp/dummy/config/initializers/assets.rb +11 -0
  207. data/spec/integration/tmp/dummy/config/initializers/backtrace_silencers.rb +7 -0
  208. data/spec/integration/tmp/dummy/config/initializers/cookies_serializer.rb +3 -0
  209. data/spec/integration/tmp/dummy/config/initializers/filter_parameter_logging.rb +4 -0
  210. data/spec/integration/tmp/dummy/config/initializers/inflections.rb +16 -0
  211. data/spec/integration/tmp/dummy/config/initializers/mime_types.rb +4 -0
  212. data/spec/integration/tmp/dummy/config/initializers/session_store.rb +3 -0
  213. data/spec/integration/tmp/dummy/config/initializers/to_time_preserves_timezone.rb +10 -0
  214. data/spec/integration/tmp/dummy/config/initializers/wrap_parameters.rb +9 -0
  215. data/spec/integration/tmp/dummy/config/locales/en.yml +23 -0
  216. data/spec/integration/tmp/dummy/config/routes.rb +61 -0
  217. data/spec/integration/tmp/dummy/config/secrets.yml +22 -0
  218. data/spec/integration/tmp/dummy/db/seeds.rb +7 -0
  219. data/spec/integration/tmp/dummy/public/404.html +67 -0
  220. data/spec/integration/tmp/dummy/public/422.html +67 -0
  221. data/spec/integration/tmp/dummy/public/500.html +66 -0
  222. data/spec/integration/tmp/dummy/public/favicon.ico +0 -0
  223. data/spec/integration/tmp/dummy/public/robots.txt +5 -0
  224. data/spec/support/dummy/schema.rb +2 -2
  225. data/spec/support/error_bubbling_helpers.rb +23 -0
  226. data/spec/support/jazz.rb +53 -6
  227. data/spec/support/lazy_helpers.rb +26 -8
  228. data/spec/support/new_relic.rb +3 -0
  229. data/spec/support/skylight.rb +3 -0
  230. data/spec/support/star_wars/schema.rb +13 -9
  231. data/spec/support/static_validation_helpers.rb +3 -1
  232. metadata +145 -22
  233. data/lib/graphql/language/comments.rb +0 -45
  234. data/spec/graphql/schema/member/has_fields_spec.rb +0 -132
  235. data/spec/integration/tmp/app/graphql/types/family_type.rb +0 -9
@@ -123,6 +123,13 @@ describe GraphQL::Schema::InputObject do
123
123
  end
124
124
  end
125
125
 
126
+ describe "when used with default_value" do
127
+ it "comes as an instance" do
128
+ res = Jazz::Schema.execute("{ defaultValueTest }")
129
+ assert_equal "Jazz::InspectableInput -> {:string_value=>\"S\"}", res["data"]["defaultValueTest"]
130
+ end
131
+ end
132
+
126
133
  describe "#to_h" do
127
134
  module InputObjectToHTest
128
135
  class TestInput1 < GraphQL::Schema::InputObject
@@ -154,4 +161,78 @@ describe GraphQL::Schema::InputObject do
154
161
  assert_equal({ a: 1, b: 2, input_object: { d: 3, e: 4 } }, input_object.to_h)
155
162
  end
156
163
  end
164
+
165
+ describe "#dig" do
166
+ module InputObjectDigTest
167
+ class TestInput1 < GraphQL::Schema::InputObject
168
+ graphql_name "TestInput1"
169
+ argument :d, Int, required: true
170
+ argument :e, Int, required: true
171
+ end
172
+
173
+ class TestInput2 < GraphQL::Schema::InputObject
174
+ graphql_name "TestInput2"
175
+ argument :a, Int, required: true
176
+ argument :b, Int, required: true
177
+ argument :c, TestInput1, as: :inputObject, required: true
178
+ end
179
+
180
+ TestInput1.to_graphql
181
+ TestInput2.to_graphql
182
+ end
183
+ arg_values = {a: 1, b: 2, c: { d: 3, e: 4 }}
184
+
185
+ input_object = InputObjectDigTest::TestInput2.new(
186
+ arg_values,
187
+ context: nil,
188
+ defaults_used: Set.new
189
+ )
190
+ it "returns the value at that key" do
191
+ assert_equal 1, input_object.dig("a")
192
+ assert_equal 1, input_object.dig(:a)
193
+ assert input_object.dig("inputObject").is_a?(GraphQL::Schema::InputObject)
194
+ end
195
+
196
+ it "works with nested keys" do
197
+ assert_equal 3, input_object.dig("inputObject", "d")
198
+ assert_equal 3, input_object.dig(:inputObject, :d)
199
+ assert_equal 3, input_object.dig("inputObject", :d)
200
+ assert_equal 3, input_object.dig(:inputObject, "d")
201
+ end
202
+
203
+ it "returns nil for missing keys" do
204
+ assert_nil input_object.dig("z")
205
+ assert_nil input_object.dig(7)
206
+ end
207
+
208
+ it "handles underscored keys" do
209
+ # TODO - shouldn't this work too?
210
+ # assert_equal 3, input_object.dig('input_object', 'd')
211
+ assert_equal 3, input_object.dig(:input_object, :d)
212
+ end
213
+ end
214
+
215
+ describe "introspection" do
216
+ it "returns input fields" do
217
+ res = Jazz::Schema.execute('
218
+ {
219
+ __type(name: "InspectableInput") {
220
+ name
221
+ inputFields { name }
222
+ }
223
+ __schema {
224
+ types {
225
+ name
226
+ inputFields { name }
227
+ }
228
+ }
229
+ }')
230
+ # Test __type
231
+ assert_equal ["stringValue", "nestedInput", "legacyInput"], res["data"]["__type"]["inputFields"].map { |f| f["name"] }
232
+ # Test __schema { types }
233
+ # It's upcased to test custom introspection
234
+ input_type = res["data"]["__schema"]["types"].find { |t| t["name"] == "INSPECTABLEINPUT" }
235
+ assert_equal ["stringValue", "nestedInput", "legacyInput"], input_type["inputFields"].map { |f| f["name"] }
236
+ end
237
+ end
157
238
  end
@@ -2,6 +2,52 @@
2
2
  require "spec_helper"
3
3
 
4
4
  describe GraphQL::Schema::Member::BuildType do
5
+ describe ".parse_type" do
6
+ it "resolves a string type from a string" do
7
+ assert_equal GraphQL::Types::String, GraphQL::Schema::Member::BuildType.parse_type("String", null: true)
8
+ end
9
+
10
+ it "resolves an integer type from a string" do
11
+ assert_equal GraphQL::Types::Int, GraphQL::Schema::Member::BuildType.parse_type("Integer", null: true)
12
+ end
13
+
14
+ it "resolves a float type from a string" do
15
+ assert_equal GraphQL::Types::Float, GraphQL::Schema::Member::BuildType.parse_type("Float", null: true)
16
+ end
17
+
18
+ it "resolves a boolean type from a string" do
19
+ assert_equal GraphQL::Types::Boolean, GraphQL::Schema::Member::BuildType.parse_type("Boolean", null: true)
20
+ end
21
+
22
+ it "resolves an interface type from a string" do
23
+ assert_equal Jazz::BaseInterface, GraphQL::Schema::Member::BuildType.parse_type("Jazz::BaseInterface", null: true)
24
+ end
25
+
26
+ it "resolves an object type from a class" do
27
+ assert_equal Jazz::BaseObject, GraphQL::Schema::Member::BuildType.parse_type(Jazz::BaseObject, null: true)
28
+ end
29
+
30
+ it "resolves an object type from a string" do
31
+ assert_equal Jazz::BaseObject, GraphQL::Schema::Member::BuildType.parse_type("Jazz::BaseObject", null: true)
32
+ end
33
+
34
+ it "resolves a nested object type from a string" do
35
+ assert_equal Jazz::Introspection::NestedType, GraphQL::Schema::Member::BuildType.parse_type("Jazz::Introspection::NestedType", null: true)
36
+ end
37
+
38
+ it "resolves a deeply nested object type from a string" do
39
+ assert_equal Jazz::Introspection::NestedType::DeeplyNestedType, GraphQL::Schema::Member::BuildType.parse_type("Jazz::Introspection::NestedType::DeeplyNestedType", null: true)
40
+ end
41
+
42
+ it "resolves a list type from an array of classes" do
43
+ assert_instance_of GraphQL::Schema::List, GraphQL::Schema::Member::BuildType.parse_type([Jazz::BaseObject], null: true)
44
+ end
45
+
46
+ it "resolves a list type from an array of strings" do
47
+ assert_instance_of GraphQL::Schema::List, GraphQL::Schema::Member::BuildType.parse_type(["Jazz::BaseObject"], null: true)
48
+ end
49
+ end
50
+
5
51
  describe ".to_type_name" do
6
52
  it "works with lists and non-nulls" do
7
53
  t = Class.new(GraphQL::Schema::Object) do
@@ -54,11 +54,11 @@ describe GraphQL::Schema::Member::Scoped do
54
54
  field :items, [Item], null: false
55
55
  field :unscoped_items, [Item], null: false,
56
56
  scope: false,
57
- method: :items
57
+ resolver_method: :items
58
58
  field :french_items, [FrenchItem], null: false,
59
- method: :items
59
+ resolver_method: :items
60
60
  field :items_connection, Item.connection_type, null: false,
61
- method: :items
61
+ resolver_method: :items
62
62
 
63
63
  def items
64
64
  [
@@ -140,32 +140,46 @@ schema {
140
140
  query: Root
141
141
  }
142
142
 
143
- # Marks an element of a GraphQL schema as no longer supported.
143
+ """
144
+ Marks an element of a GraphQL schema as no longer supported.
145
+ """
144
146
  directive @deprecated(
145
- # Explains why this element was deprecated, usually also including a suggestion
146
- # for how to access supported similar data. Formatted in
147
- # [Markdown](https://daringfireball.net/projects/markdown/).
147
+ """
148
+ Explains why this element was deprecated, usually also including a suggestion
149
+ for how to access supported similar data. Formatted in
150
+ [Markdown](https://daringfireball.net/projects/markdown/).
151
+ """
148
152
  reason: String = "No longer supported"
149
153
  ) on FIELD_DEFINITION | ENUM_VALUE
150
154
 
151
- # Directs the executor to include this field or fragment only when the `if` argument is true.
155
+ """
156
+ Directs the executor to include this field or fragment only when the `if` argument is true.
157
+ """
152
158
  directive @include(
153
- # Included when true.
159
+ """
160
+ Included when true.
161
+ """
154
162
  if: Boolean!
155
163
  ) on FIELD | FRAGMENT_SPREAD | INLINE_FRAGMENT
156
164
 
157
- # Directs the executor to skip this field or fragment when the `if` argument is true.
165
+ """
166
+ Directs the executor to skip this field or fragment when the `if` argument is true.
167
+ """
158
168
  directive @skip(
159
- # Skipped when true.
169
+ """
170
+ Skipped when true.
171
+ """
160
172
  if: Boolean!
161
173
  ) on FIELD | FRAGMENT_SPREAD | INLINE_FRAGMENT
162
174
 
163
- # A Directive provides a way to describe alternate runtime execution and type validation behavior in a GraphQL document.
164
- #
165
- # In some cases, you need to provide options to alter GraphQL's execution behavior
166
- # in ways field arguments will not suffice, such as conditionally including or
167
- # skipping a field. Directives provide this by describing additional information
168
- # to the executor.
175
+ """
176
+ A Directive provides a way to describe alternate runtime execution and type validation behavior in a GraphQL document.
177
+
178
+ In some cases, you need to provide options to alter GraphQL's execution behavior
179
+ in ways field arguments will not suffice, such as conditionally including or
180
+ skipping a field. Directives provide this by describing additional information
181
+ to the executor.
182
+ """
169
183
  type __Directive {
170
184
  args: [__InputValue!]!
171
185
  description: String
@@ -176,67 +190,107 @@ type __Directive {
176
190
  onOperation: Boolean! @deprecated(reason: "Use `locations`.")
177
191
  }
178
192
 
179
- # A Directive can be adjacent to many parts of the GraphQL language, a
180
- # __DirectiveLocation describes one such possible adjacencies.
193
+ """
194
+ A Directive can be adjacent to many parts of the GraphQL language, a
195
+ __DirectiveLocation describes one such possible adjacencies.
196
+ """
181
197
  enum __DirectiveLocation {
182
- # Location adjacent to an argument definition.
198
+ """
199
+ Location adjacent to an argument definition.
200
+ """
183
201
  ARGUMENT_DEFINITION
184
202
 
185
- # Location adjacent to an enum definition.
203
+ """
204
+ Location adjacent to an enum definition.
205
+ """
186
206
  ENUM
187
207
 
188
- # Location adjacent to an enum value definition.
208
+ """
209
+ Location adjacent to an enum value definition.
210
+ """
189
211
  ENUM_VALUE
190
212
 
191
- # Location adjacent to a field.
213
+ """
214
+ Location adjacent to a field.
215
+ """
192
216
  FIELD
193
217
 
194
- # Location adjacent to a field definition.
218
+ """
219
+ Location adjacent to a field definition.
220
+ """
195
221
  FIELD_DEFINITION
196
222
 
197
- # Location adjacent to a fragment definition.
223
+ """
224
+ Location adjacent to a fragment definition.
225
+ """
198
226
  FRAGMENT_DEFINITION
199
227
 
200
- # Location adjacent to a fragment spread.
228
+ """
229
+ Location adjacent to a fragment spread.
230
+ """
201
231
  FRAGMENT_SPREAD
202
232
 
203
- # Location adjacent to an inline fragment.
233
+ """
234
+ Location adjacent to an inline fragment.
235
+ """
204
236
  INLINE_FRAGMENT
205
237
 
206
- # Location adjacent to an input object field definition.
238
+ """
239
+ Location adjacent to an input object field definition.
240
+ """
207
241
  INPUT_FIELD_DEFINITION
208
242
 
209
- # Location adjacent to an input object type definition.
243
+ """
244
+ Location adjacent to an input object type definition.
245
+ """
210
246
  INPUT_OBJECT
211
247
 
212
- # Location adjacent to an interface definition.
248
+ """
249
+ Location adjacent to an interface definition.
250
+ """
213
251
  INTERFACE
214
252
 
215
- # Location adjacent to a mutation operation.
253
+ """
254
+ Location adjacent to a mutation operation.
255
+ """
216
256
  MUTATION
217
257
 
218
- # Location adjacent to an object type definition.
258
+ """
259
+ Location adjacent to an object type definition.
260
+ """
219
261
  OBJECT
220
262
 
221
- # Location adjacent to a query operation.
263
+ """
264
+ Location adjacent to a query operation.
265
+ """
222
266
  QUERY
223
267
 
224
- # Location adjacent to a scalar definition.
268
+ """
269
+ Location adjacent to a scalar definition.
270
+ """
225
271
  SCALAR
226
272
 
227
- # Location adjacent to a schema definition.
273
+ """
274
+ Location adjacent to a schema definition.
275
+ """
228
276
  SCHEMA
229
277
 
230
- # Location adjacent to a subscription operation.
278
+ """
279
+ Location adjacent to a subscription operation.
280
+ """
231
281
  SUBSCRIPTION
232
282
 
233
- # Location adjacent to a union definition.
283
+ """
284
+ Location adjacent to a union definition.
285
+ """
234
286
  UNION
235
287
  }
236
288
 
237
- # One possible value for a given Enum. Enum values are unique values, not a
238
- # placeholder for a string or numeric value. However an Enum value is returned in
239
- # a JSON response as a string.
289
+ """
290
+ One possible value for a given Enum. Enum values are unique values, not a
291
+ placeholder for a string or numeric value. However an Enum value is returned in
292
+ a JSON response as a string.
293
+ """
240
294
  type __EnumValue {
241
295
  deprecationReason: String
242
296
  description: String
@@ -244,8 +298,10 @@ type __EnumValue {
244
298
  name: String!
245
299
  }
246
300
 
247
- # Object and Interface types are described by a list of Fields, each of which has
248
- # a name, potentially a list of arguments, and a return type.
301
+ """
302
+ Object and Interface types are described by a list of Fields, each of which has
303
+ a name, potentially a list of arguments, and a return type.
304
+ """
249
305
  type __Field {
250
306
  args: [__InputValue!]!
251
307
  deprecationReason: String
@@ -255,45 +311,63 @@ type __Field {
255
311
  type: __Type!
256
312
  }
257
313
 
258
- # Arguments provided to Fields or Directives and the input fields of an
259
- # InputObject are represented as Input Values which describe their type and
260
- # optionally a default value.
314
+ """
315
+ Arguments provided to Fields or Directives and the input fields of an
316
+ InputObject are represented as Input Values which describe their type and
317
+ optionally a default value.
318
+ """
261
319
  type __InputValue {
262
- # A GraphQL-formatted string representing the default value for this input value.
320
+ """
321
+ A GraphQL-formatted string representing the default value for this input value.
322
+ """
263
323
  defaultValue: String
264
324
  description: String
265
325
  name: String!
266
326
  type: __Type!
267
327
  }
268
328
 
269
- # A GraphQL Schema defines the capabilities of a GraphQL server. It exposes all
270
- # available types and directives on the server, as well as the entry points for
271
- # query, mutation, and subscription operations.
329
+ """
330
+ A GraphQL Schema defines the capabilities of a GraphQL server. It exposes all
331
+ available types and directives on the server, as well as the entry points for
332
+ query, mutation, and subscription operations.
333
+ """
272
334
  type __Schema {
273
- # A list of all directives supported by this server.
335
+ """
336
+ A list of all directives supported by this server.
337
+ """
274
338
  directives: [__Directive!]!
275
339
 
276
- # If this server supports mutation, the type that mutation operations will be rooted at.
340
+ """
341
+ If this server supports mutation, the type that mutation operations will be rooted at.
342
+ """
277
343
  mutationType: __Type
278
344
 
279
- # The type that query operations will be rooted at.
345
+ """
346
+ The type that query operations will be rooted at.
347
+ """
280
348
  queryType: __Type!
281
349
 
282
- # If this server support subscription, the type that subscription operations will be rooted at.
350
+ """
351
+ If this server support subscription, the type that subscription operations will be rooted at.
352
+ """
283
353
  subscriptionType: __Type
284
354
 
285
- # A list of all types supported by this server.
355
+ """
356
+ A list of all types supported by this server.
357
+ """
286
358
  types: [__Type!]!
287
359
  }
288
360
 
289
- # The fundamental unit of any GraphQL Schema is the type. There are many kinds of
290
- # types in GraphQL as represented by the `__TypeKind` enum.
291
- #
292
- # Depending on the kind of a type, certain fields describe information about that
293
- # type. Scalar types provide no information beyond a name and description, while
294
- # Enum types provide their values. Object and Interface types provide the fields
295
- # they describe. Abstract types, Union and Interface, provide the Object types
296
- # possible at runtime. List and NonNull types compose other types.
361
+ """
362
+ The fundamental unit of any GraphQL Schema is the type. There are many kinds of
363
+ types in GraphQL as represented by the `__TypeKind` enum.
364
+
365
+ Depending on the kind of a type, certain fields describe information about that
366
+ type. Scalar types provide no information beyond a name and description, while
367
+ Enum types provide their values. Object and Interface types provide the fields
368
+ they describe. Abstract types, Union and Interface, provide the Object types
369
+ possible at runtime. List and NonNull types compose other types.
370
+ """
297
371
  type __Type {
298
372
  description: String
299
373
  enumValues(includeDeprecated: Boolean = false): [__EnumValue!]
@@ -306,30 +380,48 @@ type __Type {
306
380
  possibleTypes: [__Type!]
307
381
  }
308
382
 
309
- # An enum describing what kind of type a given `__Type` is.
383
+ """
384
+ An enum describing what kind of type a given `__Type` is.
385
+ """
310
386
  enum __TypeKind {
311
- # Indicates this type is an enum. `enumValues` is a valid field.
387
+ """
388
+ Indicates this type is an enum. `enumValues` is a valid field.
389
+ """
312
390
  ENUM
313
391
 
314
- # Indicates this type is an input object. `inputFields` is a valid field.
392
+ """
393
+ Indicates this type is an input object. `inputFields` is a valid field.
394
+ """
315
395
  INPUT_OBJECT
316
396
 
317
- # Indicates this type is an interface. `fields` and `possibleTypes` are valid fields.
397
+ """
398
+ Indicates this type is an interface. `fields` and `possibleTypes` are valid fields.
399
+ """
318
400
  INTERFACE
319
401
 
320
- # Indicates this type is a list. `ofType` is a valid field.
402
+ """
403
+ Indicates this type is a list. `ofType` is a valid field.
404
+ """
321
405
  LIST
322
406
 
323
- # Indicates this type is a non-null. `ofType` is a valid field.
407
+ """
408
+ Indicates this type is a non-null. `ofType` is a valid field.
409
+ """
324
410
  NON_NULL
325
411
 
326
- # Indicates this type is an object. `fields` and `interfaces` are valid fields.
412
+ """
413
+ Indicates this type is an object. `fields` and `interfaces` are valid fields.
414
+ """
327
415
  OBJECT
328
416
 
329
- # Indicates this type is a scalar.
417
+ """
418
+ Indicates this type is a scalar.
419
+ """
330
420
  SCALAR
331
421
 
332
- # Indicates this type is a union. `possibleTypes` is a valid field.
422
+ """
423
+ Indicates this type is a union. `possibleTypes` is a valid field.
424
+ """
333
425
  UNION
334
426
  }
335
427
  SCHEMA
@@ -397,23 +489,33 @@ enum Choice {
397
489
  WOZ @deprecated
398
490
  }
399
491
 
400
- # A blog comment
492
+ """
493
+ A blog comment
494
+ """
401
495
  type Comment implements Node {
402
496
  id: ID!
403
497
  }
404
498
 
405
- # Autogenerated input type of CreatePost
499
+ """
500
+ Autogenerated input type of CreatePost
501
+ """
406
502
  input CreatePostInput {
407
503
  body: String!
408
504
 
409
- # A unique identifier for the client performing the mutation.
505
+ """
506
+ A unique identifier for the client performing the mutation.
507
+ """
410
508
  clientMutationId: String
411
509
  title: String!
412
510
  }
413
511
 
414
- # Autogenerated return type of CreatePost
512
+ """
513
+ Autogenerated return type of CreatePost
514
+ """
415
515
  type CreatePostPayload {
416
- # A unique identifier for the client performing the mutation.
516
+ """
517
+ A unique identifier for the client performing the mutation.
518
+ """
417
519
  clientMutationId: String
418
520
  post: Post
419
521
  }
@@ -425,11 +527,15 @@ type Image {
425
527
  width: Int!
426
528
  }
427
529
 
428
- # Media objects
530
+ """
531
+ Media objects
532
+ """
429
533
  union Media = Audio | Image
430
534
 
431
535
  type Mutation {
432
- # Create a blog post
536
+ """
537
+ Create a blog post
538
+ """
433
539
  createPost(input: CreatePostInput!): CreatePostPayload
434
540
  }
435
541
 
@@ -437,7 +543,9 @@ interface Node {
437
543
  id: ID!
438
544
  }
439
545
 
440
- # A blog post
546
+ """
547
+ A blog post
548
+ """
441
549
  type Post {
442
550
  body: String!
443
551
  comments: [Comment!]
@@ -446,22 +554,32 @@ type Post {
446
554
  title: String!
447
555
  }
448
556
 
449
- # The query root of this schema
557
+ """
558
+ The query root of this schema
559
+ """
450
560
  type Query {
451
561
  post(
452
- # Post ID
562
+ """
563
+ Post ID
564
+ """
453
565
  id: ID!
454
566
  varied: Varied = {id: "123", int: 234, float: 2.3, enum: FOO, sub: [{string: "str"}]}
455
567
  variedWithNulls: Varied = {id: null, int: null, float: null, enum: null, sub: null}
456
568
  ): Post
457
569
  }
458
570
 
459
- # Test
571
+ """
572
+ Test
573
+ """
460
574
  input Sub {
461
- # Something
575
+ """
576
+ Something
577
+ """
462
578
  int: Int
463
579
 
464
- # Something
580
+ """
581
+ Something
582
+ """
465
583
  string: String
466
584
  }
467
585
 
@@ -553,32 +671,46 @@ enum Choice {
553
671
  FOO
554
672
  }
555
673
 
556
- # A blog comment
674
+ """
675
+ A blog comment
676
+ """
557
677
  type Comment implements Node {
558
678
  id: ID!
559
679
  }
560
680
 
561
- # Autogenerated input type of CreatePost
681
+ """
682
+ Autogenerated input type of CreatePost
683
+ """
562
684
  input CreatePostInput {
563
685
  body: String!
564
686
 
565
- # A unique identifier for the client performing the mutation.
687
+ """
688
+ A unique identifier for the client performing the mutation.
689
+ """
566
690
  clientMutationId: String
567
691
  title: String!
568
692
  }
569
693
 
570
- # Autogenerated return type of CreatePost
694
+ """
695
+ Autogenerated return type of CreatePost
696
+ """
571
697
  type CreatePostPayload {
572
- # A unique identifier for the client performing the mutation.
698
+ """
699
+ A unique identifier for the client performing the mutation.
700
+ """
573
701
  clientMutationId: String
574
702
  post: Post
575
703
  }
576
704
 
577
- # Media objects
705
+ """
706
+ Media objects
707
+ """
578
708
  union Media = Audio
579
709
 
580
710
  type Mutation {
581
- # Create a blog post
711
+ """
712
+ Create a blog post
713
+ """
582
714
  createPost(input: CreatePostInput!): CreatePostPayload
583
715
  }
584
716
 
@@ -586,7 +718,9 @@ interface Node {
586
718
  id: ID!
587
719
  }
588
720
 
589
- # A blog post
721
+ """
722
+ A blog post
723
+ """
590
724
  type Post {
591
725
  body: String!
592
726
  comments: [Comment!]
@@ -594,10 +728,14 @@ type Post {
594
728
  title: String!
595
729
  }
596
730
 
597
- # The query root of this schema
731
+ """
732
+ The query root of this schema
733
+ """
598
734
  type Query {
599
735
  post(
600
- # Post ID
736
+ """
737
+ Post ID
738
+ """
601
739
  id: ID!
602
740
  ): Post
603
741
  }
@@ -618,7 +756,9 @@ SCHEMA
618
756
  describe "#print_type" do
619
757
  it "returns the type schema as a string" do
620
758
  expected = <<SCHEMA
621
- # A blog post
759
+ """
760
+ A blog post
761
+ """
622
762
  type Post {
623
763
  body: String!
624
764
  comments: [Comment!]
@@ -632,12 +772,18 @@ SCHEMA
632
772
 
633
773
  it "can print non-object types" do
634
774
  expected = <<SCHEMA
635
- # Test
775
+ """
776
+ Test
777
+ """
636
778
  input Sub {
637
- # Something
779
+ """
780
+ Something
781
+ """
638
782
  int: Int
639
783
 
640
- # Something
784
+ """
785
+ Something
786
+ """
641
787
  string: String
642
788
  }
643
789
  SCHEMA
@@ -669,7 +815,9 @@ SCHEMA
669
815
  end
670
816
 
671
817
  expected = <<SCHEMA
672
- # The query root of this schema
818
+ """
819
+ The query root of this schema
820
+ """
673
821
  type Query {
674
822
  example(input: SomeType = "Howdy"): SomeType
675
823
  }