rails-graphql 0.2.1 → 1.0.0.rc1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (315) hide show
  1. checksums.yaml +4 -4
  2. data/ext/console.rb +18 -0
  3. data/ext/extconf.h +3 -0
  4. data/ext/extconf.rb +1 -54
  5. data/ext/gql_parser.c +631 -0
  6. data/ext/gql_parser.h +21 -0
  7. data/ext/shared.c +477 -0
  8. data/ext/shared.h +177 -0
  9. data/lib/generators/graphql/channel_generator.rb +27 -0
  10. data/lib/generators/graphql/controller_generator.rb +9 -4
  11. data/lib/generators/graphql/install_generator.rb +49 -0
  12. data/lib/generators/graphql/schema_generator.rb +9 -4
  13. data/lib/generators/graphql/templates/channel.erb +7 -0
  14. data/lib/generators/graphql/templates/config.rb +97 -0
  15. data/lib/generators/graphql/templates/controller.erb +2 -0
  16. data/lib/generators/graphql/templates/schema.erb +5 -3
  17. data/lib/gql_parser.so +0 -0
  18. data/lib/rails/graphql/adapters/mysql_adapter.rb +59 -0
  19. data/lib/rails/graphql/adapters/pg_adapter.rb +25 -22
  20. data/lib/rails/graphql/adapters/sqlite_adapter.rb +17 -14
  21. data/lib/rails/graphql/alternative/field_set.rb +48 -0
  22. data/lib/rails/graphql/alternative/mutation.rb +17 -0
  23. data/lib/rails/graphql/alternative/query.rb +98 -0
  24. data/lib/rails/graphql/alternative/subscription.rb +18 -0
  25. data/lib/rails/graphql/alternative.rb +20 -0
  26. data/lib/rails/graphql/argument.rb +25 -26
  27. data/lib/rails/graphql/callback.rb +30 -14
  28. data/lib/rails/graphql/collectors/hash_collector.rb +26 -7
  29. data/lib/rails/graphql/collectors/idented_collector.rb +10 -7
  30. data/lib/rails/graphql/collectors/json_collector.rb +43 -17
  31. data/lib/rails/graphql/collectors.rb +4 -4
  32. data/lib/rails/graphql/config.rb +154 -23
  33. data/lib/rails/graphql/directive/cached_directive.rb +33 -0
  34. data/lib/rails/graphql/directive/deprecated_directive.rb +10 -10
  35. data/lib/rails/graphql/directive/include_directive.rb +4 -4
  36. data/lib/rails/graphql/directive/skip_directive.rb +4 -4
  37. data/lib/rails/graphql/directive/specified_by_directive.rb +24 -0
  38. data/lib/rails/graphql/directive.rb +134 -73
  39. data/lib/rails/graphql/errors.rb +33 -4
  40. data/lib/rails/graphql/event.rb +21 -9
  41. data/lib/rails/graphql/field/authorized_field.rb +17 -6
  42. data/lib/rails/graphql/field/input_field.rb +8 -12
  43. data/lib/rails/graphql/field/mutation_field.rb +43 -9
  44. data/lib/rails/graphql/field/output_field.rb +112 -12
  45. data/lib/rails/graphql/field/proxied_field.rb +35 -26
  46. data/lib/rails/graphql/field/resolved_field.rb +27 -25
  47. data/lib/rails/graphql/field/scoped_config.rb +10 -4
  48. data/lib/rails/graphql/field/subscription_field.rb +123 -0
  49. data/lib/rails/graphql/field/typed_field.rb +69 -24
  50. data/lib/rails/graphql/field.rb +89 -74
  51. data/lib/rails/graphql/global_id.rb +89 -0
  52. data/lib/rails/graphql/helpers/attribute_delegator.rb +5 -5
  53. data/lib/rails/graphql/helpers/inherited_collection/array.rb +51 -0
  54. data/lib/rails/graphql/helpers/inherited_collection/base.rb +45 -0
  55. data/lib/rails/graphql/helpers/inherited_collection/hash.rb +88 -0
  56. data/lib/rails/graphql/helpers/inherited_collection.rb +25 -76
  57. data/lib/rails/graphql/helpers/instantiable.rb +15 -0
  58. data/lib/rails/graphql/helpers/leaf_from_ar.rb +7 -7
  59. data/lib/rails/graphql/helpers/registerable.rb +44 -62
  60. data/lib/rails/graphql/helpers/unregisterable.rb +16 -0
  61. data/lib/rails/graphql/helpers/with_arguments.rb +33 -28
  62. data/lib/rails/graphql/helpers/with_assignment.rb +6 -6
  63. data/lib/rails/graphql/helpers/with_callbacks.rb +28 -11
  64. data/lib/rails/graphql/helpers/with_description.rb +73 -0
  65. data/lib/rails/graphql/helpers/with_directives.rb +58 -30
  66. data/lib/rails/graphql/helpers/with_events.rb +22 -23
  67. data/lib/rails/graphql/helpers/with_fields.rb +86 -26
  68. data/lib/rails/graphql/helpers/with_global_id.rb +22 -0
  69. data/lib/rails/graphql/helpers/with_name.rb +44 -0
  70. data/lib/rails/graphql/helpers/with_namespace.rb +7 -4
  71. data/lib/rails/graphql/helpers/with_owner.rb +8 -7
  72. data/lib/rails/graphql/helpers/with_schema_fields.rb +162 -56
  73. data/lib/rails/graphql/helpers/with_validator.rb +9 -9
  74. data/lib/rails/graphql/helpers.rb +10 -3
  75. data/lib/rails/graphql/introspection.rb +43 -36
  76. data/lib/rails/graphql/railtie.rb +89 -33
  77. data/lib/rails/graphql/railties/app/base_channel.rb +10 -0
  78. data/lib/rails/graphql/railties/app/base_controller.rb +12 -0
  79. data/lib/rails/graphql/railties/app/views/_cable.js.erb +56 -0
  80. data/lib/rails/graphql/railties/app/views/_fetch.js.erb +20 -0
  81. data/lib/rails/graphql/railties/app/views/graphiql.html.erb +101 -0
  82. data/lib/rails/graphql/railties/base_generator.rb +5 -17
  83. data/lib/rails/graphql/railties/channel.rb +157 -0
  84. data/lib/rails/graphql/railties/controller.rb +91 -25
  85. data/lib/rails/graphql/railties/controller_runtime.rb +5 -5
  86. data/lib/rails/graphql/railties/log_subscriber.rb +81 -14
  87. data/lib/rails/graphql/request/arguments.rb +26 -50
  88. data/lib/rails/graphql/request/backtrace.rb +212 -0
  89. data/lib/rails/graphql/request/component/field.rb +98 -70
  90. data/lib/rails/graphql/request/component/fragment.rb +80 -26
  91. data/lib/rails/graphql/request/component/operation/subscription.rb +162 -4
  92. data/lib/rails/graphql/request/component/operation.rb +73 -34
  93. data/lib/rails/graphql/request/component/spread.rb +79 -27
  94. data/lib/rails/graphql/request/component/typename.rb +28 -13
  95. data/lib/rails/graphql/request/component.rb +77 -36
  96. data/lib/rails/graphql/request/context.rb +19 -9
  97. data/lib/rails/graphql/request/errors.rb +16 -6
  98. data/lib/rails/graphql/request/event.rb +23 -8
  99. data/lib/rails/graphql/request/helpers/directives.rb +69 -27
  100. data/lib/rails/graphql/request/helpers/selection_set.rb +57 -25
  101. data/lib/rails/graphql/request/helpers/value_writers.rb +24 -19
  102. data/lib/rails/graphql/request/prepared_data.rb +100 -0
  103. data/lib/rails/graphql/request/steps/authorizable.rb +24 -14
  104. data/lib/rails/graphql/request/steps/organizable.rb +111 -49
  105. data/lib/rails/graphql/request/steps/{prepareable.rb → preparable.rb} +21 -8
  106. data/lib/rails/graphql/request/steps/{resolveable.rb → resolvable.rb} +16 -7
  107. data/lib/rails/graphql/request/strategy/cached_strategy.rb +64 -0
  108. data/lib/rails/graphql/request/strategy/dynamic_instance.rb +6 -6
  109. data/lib/rails/graphql/request/strategy/multi_query_strategy.rb +6 -13
  110. data/lib/rails/graphql/request/strategy/sequenced_strategy.rb +9 -9
  111. data/lib/rails/graphql/request/strategy.rb +147 -77
  112. data/lib/rails/graphql/request/subscription.rb +82 -0
  113. data/lib/rails/graphql/request.rb +353 -104
  114. data/lib/rails/graphql/schema.rb +251 -106
  115. data/lib/rails/graphql/shortcuts.rb +33 -8
  116. data/lib/rails/graphql/source/active_record/builders.rb +64 -51
  117. data/lib/rails/graphql/source/active_record_source.rb +158 -82
  118. data/lib/rails/graphql/source/base.rb +83 -0
  119. data/lib/rails/graphql/source/builder.rb +115 -0
  120. data/lib/rails/graphql/source/scoped_arguments.rb +39 -21
  121. data/lib/rails/graphql/source.rb +90 -228
  122. data/lib/rails/graphql/subscription/provider/action_cable.rb +113 -0
  123. data/lib/rails/graphql/subscription/provider/base.rb +192 -0
  124. data/lib/rails/graphql/subscription/provider.rb +18 -0
  125. data/lib/rails/graphql/subscription/store/base.rb +141 -0
  126. data/lib/rails/graphql/subscription/store/memory.rb +136 -0
  127. data/lib/rails/graphql/subscription/store.rb +19 -0
  128. data/lib/rails/graphql/subscription.rb +17 -0
  129. data/lib/rails/graphql/to_gql.rb +29 -32
  130. data/lib/rails/graphql/type/creator.rb +196 -0
  131. data/lib/rails/graphql/type/enum/directive_location_enum.rb +11 -11
  132. data/lib/rails/graphql/type/enum/type_kind_enum.rb +3 -3
  133. data/lib/rails/graphql/type/enum.rb +44 -50
  134. data/lib/rails/graphql/type/input.rb +92 -25
  135. data/lib/rails/graphql/type/interface.rb +29 -28
  136. data/lib/rails/graphql/type/object/directive_object.rb +10 -9
  137. data/lib/rails/graphql/type/object/enum_value_object.rb +3 -3
  138. data/lib/rails/graphql/type/object/field_object.rb +24 -6
  139. data/lib/rails/graphql/type/object/input_value_object.rb +6 -7
  140. data/lib/rails/graphql/type/object/schema_object.rb +5 -8
  141. data/lib/rails/graphql/type/object/type_object.rb +62 -25
  142. data/lib/rails/graphql/type/object.rb +34 -26
  143. data/lib/rails/graphql/type/scalar/any_scalar.rb +30 -0
  144. data/lib/rails/graphql/type/scalar/bigint_scalar.rb +5 -5
  145. data/lib/rails/graphql/type/scalar/binary_scalar.rb +5 -3
  146. data/lib/rails/graphql/type/scalar/boolean_scalar.rb +8 -8
  147. data/lib/rails/graphql/type/scalar/date_scalar.rb +5 -3
  148. data/lib/rails/graphql/type/scalar/date_time_scalar.rb +5 -3
  149. data/lib/rails/graphql/type/scalar/decimal_scalar.rb +5 -3
  150. data/lib/rails/graphql/type/scalar/float_scalar.rb +5 -5
  151. data/lib/rails/graphql/type/scalar/id_scalar.rb +6 -5
  152. data/lib/rails/graphql/type/scalar/int_scalar.rb +6 -5
  153. data/lib/rails/graphql/type/scalar/json_scalar.rb +41 -0
  154. data/lib/rails/graphql/type/scalar/string_scalar.rb +18 -4
  155. data/lib/rails/graphql/type/scalar/time_scalar.rb +8 -6
  156. data/lib/rails/graphql/type/scalar.rb +26 -23
  157. data/lib/rails/graphql/type/union.rb +21 -18
  158. data/lib/rails/graphql/type.rb +43 -26
  159. data/lib/rails/graphql/type_map.rb +268 -165
  160. data/lib/rails/graphql/uri.rb +167 -0
  161. data/lib/rails/graphql/version.rb +19 -3
  162. data/lib/rails/graphql.rake +3 -0
  163. data/lib/rails/graphql.rb +91 -56
  164. data/lib/rails-graphql.rb +1 -1
  165. data/test/assets/en.yml +29 -0
  166. data/test/assets/introspection-mem.txt +1 -1
  167. data/test/assets/introspection.gql +2 -0
  168. data/test/assets/mem.gql +86 -99
  169. data/test/assets/mysql.gql +406 -0
  170. data/test/assets/sqlite.gql +96 -73
  171. data/test/assets/translate.gql +346 -0
  172. data/test/config.rb +19 -8
  173. data/test/graphql/schema_test.rb +14 -50
  174. data/test/graphql/source_test.rb +8 -85
  175. data/test/graphql/type/enum_test.rb +207 -203
  176. data/test/graphql/type/input_test.rb +14 -9
  177. data/test/graphql/type/interface_test.rb +12 -9
  178. data/test/graphql/type/object_test.rb +8 -2
  179. data/test/graphql/type/scalar/any_scalar_test.rb +38 -0
  180. data/test/graphql/type/scalar/boolean_scalar_test.rb +6 -3
  181. data/test/graphql/type/scalar/json_scalar_test.rb +23 -0
  182. data/test/graphql/type_map_test.rb +63 -81
  183. data/test/graphql/type_test.rb +0 -19
  184. data/test/graphql_test.rb +1 -1
  185. data/test/integration/{authorization/authorization_test.rb → authorization_test.rb} +40 -14
  186. data/test/integration/config.rb +36 -3
  187. data/test/integration/customization_test.rb +39 -0
  188. data/test/integration/global_id_test.rb +99 -0
  189. data/test/integration/memory/star_wars_introspection_test.rb +24 -16
  190. data/test/integration/memory/star_wars_query_test.rb +54 -3
  191. data/test/integration/memory/star_wars_validation_test.rb +3 -3
  192. data/test/integration/mysql/star_wars_introspection_test.rb +25 -0
  193. data/test/integration/persisted_query_test.rb +87 -0
  194. data/test/integration/resolver_precedence_test.rb +154 -0
  195. data/test/integration/schemas/memory.rb +24 -10
  196. data/test/integration/schemas/mysql.rb +62 -0
  197. data/test/integration/schemas/sqlite.rb +21 -12
  198. data/test/integration/sqlite/star_wars_global_id_test.rb +89 -0
  199. data/test/integration/sqlite/star_wars_introspection_test.rb +10 -0
  200. data/test/integration/sqlite/star_wars_query_test.rb +14 -1
  201. data/test/integration/translate_test.rb +73 -0
  202. data/test/test_ext.rb +16 -13
  203. metadata +125 -161
  204. data/ext/depend +0 -3
  205. data/ext/graphqlparser/Ast.cpp +0 -346
  206. data/ext/graphqlparser/Ast.h +0 -1214
  207. data/ext/graphqlparser/AstNode.h +0 -36
  208. data/ext/graphqlparser/AstVisitor.h +0 -137
  209. data/ext/graphqlparser/GraphQLParser.cpp +0 -76
  210. data/ext/graphqlparser/GraphQLParser.h +0 -55
  211. data/ext/graphqlparser/JsonVisitor.cpp +0 -161
  212. data/ext/graphqlparser/JsonVisitor.cpp.inc +0 -456
  213. data/ext/graphqlparser/JsonVisitor.h +0 -121
  214. data/ext/graphqlparser/JsonVisitor.h.inc +0 -110
  215. data/ext/graphqlparser/VERSION +0 -1
  216. data/ext/graphqlparser/c/GraphQLAst.cpp +0 -324
  217. data/ext/graphqlparser/c/GraphQLAst.h +0 -180
  218. data/ext/graphqlparser/c/GraphQLAstForEachConcreteType.h +0 -44
  219. data/ext/graphqlparser/c/GraphQLAstNode.cpp +0 -25
  220. data/ext/graphqlparser/c/GraphQLAstNode.h +0 -33
  221. data/ext/graphqlparser/c/GraphQLAstToJSON.cpp +0 -21
  222. data/ext/graphqlparser/c/GraphQLAstToJSON.h +0 -24
  223. data/ext/graphqlparser/c/GraphQLAstVisitor.cpp +0 -55
  224. data/ext/graphqlparser/c/GraphQLAstVisitor.h +0 -53
  225. data/ext/graphqlparser/c/GraphQLParser.cpp +0 -35
  226. data/ext/graphqlparser/c/GraphQLParser.h +0 -54
  227. data/ext/graphqlparser/dump_json_ast.cpp +0 -48
  228. data/ext/graphqlparser/lexer.lpp +0 -324
  229. data/ext/graphqlparser/parser.ypp +0 -693
  230. data/ext/graphqlparser/parsergen/lexer.cpp +0 -2633
  231. data/ext/graphqlparser/parsergen/lexer.h +0 -528
  232. data/ext/graphqlparser/parsergen/location.hh +0 -189
  233. data/ext/graphqlparser/parsergen/parser.tab.cpp +0 -3300
  234. data/ext/graphqlparser/parsergen/parser.tab.hpp +0 -646
  235. data/ext/graphqlparser/parsergen/position.hh +0 -179
  236. data/ext/graphqlparser/parsergen/stack.hh +0 -156
  237. data/ext/graphqlparser/syntaxdefs.h +0 -19
  238. data/ext/libgraphqlparser/AstNode.h +0 -36
  239. data/ext/libgraphqlparser/CMakeLists.txt +0 -148
  240. data/ext/libgraphqlparser/CONTRIBUTING.md +0 -23
  241. data/ext/libgraphqlparser/GraphQLParser.cpp +0 -76
  242. data/ext/libgraphqlparser/GraphQLParser.h +0 -55
  243. data/ext/libgraphqlparser/JsonVisitor.cpp +0 -161
  244. data/ext/libgraphqlparser/JsonVisitor.h +0 -121
  245. data/ext/libgraphqlparser/LICENSE +0 -22
  246. data/ext/libgraphqlparser/README.clang-tidy +0 -7
  247. data/ext/libgraphqlparser/README.md +0 -84
  248. data/ext/libgraphqlparser/ast/ast.ast +0 -203
  249. data/ext/libgraphqlparser/ast/ast.py +0 -61
  250. data/ext/libgraphqlparser/ast/c.py +0 -100
  251. data/ext/libgraphqlparser/ast/c.pyc +0 -0
  252. data/ext/libgraphqlparser/ast/c_impl.py +0 -61
  253. data/ext/libgraphqlparser/ast/c_impl.pyc +0 -0
  254. data/ext/libgraphqlparser/ast/c_visitor_impl.py +0 -39
  255. data/ext/libgraphqlparser/ast/c_visitor_impl.pyc +0 -0
  256. data/ext/libgraphqlparser/ast/casing.py +0 -26
  257. data/ext/libgraphqlparser/ast/casing.pyc +0 -0
  258. data/ext/libgraphqlparser/ast/cxx.py +0 -197
  259. data/ext/libgraphqlparser/ast/cxx.pyc +0 -0
  260. data/ext/libgraphqlparser/ast/cxx_impl.py +0 -61
  261. data/ext/libgraphqlparser/ast/cxx_impl.pyc +0 -0
  262. data/ext/libgraphqlparser/ast/cxx_json_visitor_header.py +0 -42
  263. data/ext/libgraphqlparser/ast/cxx_json_visitor_header.pyc +0 -0
  264. data/ext/libgraphqlparser/ast/cxx_json_visitor_impl.py +0 -80
  265. data/ext/libgraphqlparser/ast/cxx_json_visitor_impl.pyc +0 -0
  266. data/ext/libgraphqlparser/ast/cxx_visitor.py +0 -64
  267. data/ext/libgraphqlparser/ast/cxx_visitor.pyc +0 -0
  268. data/ext/libgraphqlparser/ast/js.py +0 -65
  269. data/ext/libgraphqlparser/ast/license.py +0 -10
  270. data/ext/libgraphqlparser/ast/license.pyc +0 -0
  271. data/ext/libgraphqlparser/c/GraphQLAstNode.cpp +0 -25
  272. data/ext/libgraphqlparser/c/GraphQLAstNode.h +0 -33
  273. data/ext/libgraphqlparser/c/GraphQLAstToJSON.cpp +0 -21
  274. data/ext/libgraphqlparser/c/GraphQLAstToJSON.h +0 -24
  275. data/ext/libgraphqlparser/c/GraphQLAstVisitor.cpp +0 -55
  276. data/ext/libgraphqlparser/c/GraphQLAstVisitor.h +0 -53
  277. data/ext/libgraphqlparser/c/GraphQLParser.cpp +0 -35
  278. data/ext/libgraphqlparser/c/GraphQLParser.h +0 -54
  279. data/ext/libgraphqlparser/clang-tidy-all.sh +0 -3
  280. data/ext/libgraphqlparser/cmake/version.cmake +0 -16
  281. data/ext/libgraphqlparser/dump_json_ast.cpp +0 -48
  282. data/ext/libgraphqlparser/go/README.md +0 -20
  283. data/ext/libgraphqlparser/go/callbacks.go +0 -18
  284. data/ext/libgraphqlparser/go/gotest.go +0 -64
  285. data/ext/libgraphqlparser/lexer.lpp +0 -324
  286. data/ext/libgraphqlparser/libgraphqlparser.pc.in +0 -11
  287. data/ext/libgraphqlparser/parser.ypp +0 -693
  288. data/ext/libgraphqlparser/parsergen/lexer.cpp +0 -2633
  289. data/ext/libgraphqlparser/parsergen/lexer.h +0 -528
  290. data/ext/libgraphqlparser/parsergen/location.hh +0 -189
  291. data/ext/libgraphqlparser/parsergen/parser.tab.cpp +0 -3300
  292. data/ext/libgraphqlparser/parsergen/parser.tab.hpp +0 -646
  293. data/ext/libgraphqlparser/parsergen/position.hh +0 -179
  294. data/ext/libgraphqlparser/parsergen/stack.hh +0 -156
  295. data/ext/libgraphqlparser/python/CMakeLists.txt +0 -14
  296. data/ext/libgraphqlparser/python/README.md +0 -5
  297. data/ext/libgraphqlparser/python/example.py +0 -31
  298. data/ext/libgraphqlparser/syntaxdefs.h +0 -19
  299. data/ext/libgraphqlparser/test/BuildCAPI.c +0 -5
  300. data/ext/libgraphqlparser/test/CMakeLists.txt +0 -25
  301. data/ext/libgraphqlparser/test/JsonVisitorTests.cpp +0 -28
  302. data/ext/libgraphqlparser/test/ParserTests.cpp +0 -352
  303. data/ext/libgraphqlparser/test/kitchen-sink.graphql +0 -59
  304. data/ext/libgraphqlparser/test/kitchen-sink.json +0 -1
  305. data/ext/libgraphqlparser/test/schema-kitchen-sink.graphql +0 -78
  306. data/ext/libgraphqlparser/test/schema-kitchen-sink.json +0 -1
  307. data/ext/libgraphqlparser/test/valgrind.supp +0 -33
  308. data/ext/version.cpp +0 -21
  309. data/lib/graphqlparser.so +0 -0
  310. data/lib/rails/graphql/native/functions.rb +0 -38
  311. data/lib/rails/graphql/native/location.rb +0 -41
  312. data/lib/rails/graphql/native/pointers.rb +0 -23
  313. data/lib/rails/graphql/native/visitor.rb +0 -349
  314. data/lib/rails/graphql/native.rb +0 -56
  315. data/test/integration/schemas/authorization.rb +0 -12
@@ -15,49 +15,24 @@ class GraphQL_TypeMapTest < GraphQL::TestCase
15
15
  @subject ||= DESCRIBED_CLASS.new
16
16
  end
17
17
 
18
- def test_loaded_bang
19
- DESCRIBED_CLASS.stub(:base_classes, { Type: false }) do
20
- refute(DESCRIBED_CLASS.base_classes[:Type])
21
- DESCRIBED_CLASS.loaded!(:Type)
22
- assert(DESCRIBED_CLASS.base_classes[:Type])
23
- end
24
-
25
- DESCRIBED_CLASS.stub(:base_classes, { Type: true }) do
26
- assert(DESCRIBED_CLASS.base_classes[:Type])
27
- end
28
- end
29
-
30
18
  def test_reset_bang
31
19
  checkpoint = registered_double
32
20
  subject.instance_variable_set(:@objects, 1)
33
- subject.instance_variable_set(:@pending, 2)
34
- subject.instance_variable_set(:@callbacks, 3)
21
+ subject.instance_variable_set(:@version, 2)
22
+ subject.instance_variable_set(:@pending, 3)
35
23
  subject.instance_variable_set(:@skip_register, 4)
36
- subject.instance_variable_set(:@index, 5)
37
- subject.instance_variable_set(:@checkpoint, [checkpoint])
24
+ subject.instance_variable_set(:@callbacks, 5)
25
+ subject.instance_variable_set(:@dependencies, 6)
26
+ subject.instance_variable_set(:@index, 7)
38
27
  subject.reset!
39
28
 
40
29
  refute_equal(1, subject.instance_variable_get(:@objects))
41
- refute_equal(2, subject.instance_variable_get(:@pending))
42
- refute_equal(3, subject.instance_variable_get(:@callbacks))
30
+ refute_equal(2, subject.instance_variable_get(:@version))
31
+ refute_equal(3, subject.instance_variable_get(:@pending))
43
32
  refute_equal(4, subject.instance_variable_get(:@skip_register))
44
- refute_equal(5, subject.instance_variable_get(:@index))
45
- assert_predicate(checkpoint, :registered?)
46
- end
47
-
48
- def test_use_checkpoint_bang
49
- subject.stub(:objects, [1]) do
50
- assert_registered do
51
- subject.use_checkpoint!
52
- assert_equal([1], subject.instance_variable_get(:@checkpoint))
53
- end
54
- end
55
-
56
- reset = false
57
- subject.stub(:reset!, -> { reset = true }) do
58
- subject.use_checkpoint!
59
- assert(reset)
60
- end
33
+ refute_equal(5, subject.instance_variable_get(:@callbacks))
34
+ refute_equal(6, subject.instance_variable_get(:@dependencies))
35
+ refute_equal(7, subject.instance_variable_get(:@index))
61
36
  end
62
37
 
63
38
  def test_objects
@@ -66,15 +41,23 @@ class GraphQL_TypeMapTest < GraphQL::TestCase
66
41
  assert_empty(subject.objects)
67
42
  end
68
43
 
69
- item = registered_double
70
- subject.stub_ivar(:@index, { a: { b: { c: -> { item } }, d: { e: -> { 1 } } } }) do
44
+ item = double(
45
+ gql_name: 'name',
46
+ is_a?: ->(klass) { klass == Rails::GraphQL::Helpers::Registerable },
47
+ )
48
+
49
+ other = double(gql_name: 'otherName')
50
+
51
+ checker = -> { item }
52
+ subject.stub_ivar(:@index, { a: { b: { c: checker }, d: { e: checker }, f: { g: other } } }) do
71
53
  assert_empty(subject.objects(namespaces: :z))
72
54
  assert_empty(subject.objects(namespaces: :a, base_classes: :z))
73
- assert_empty(subject.objects(namespaces: :a, base_classes: :d))
55
+ assert_empty(subject.objects(namespaces: :a, base_classes: :f))
74
56
 
75
- result = subject.objects
76
- refute_includes(result, 1)
77
- assert_includes(result, item)
57
+ subject.class.stub(:base_classes, %i[b d f]) do
58
+ result = subject.objects
59
+ assert_equal([item], result)
60
+ end
78
61
  end
79
62
  end
80
63
 
@@ -86,36 +69,29 @@ class GraphQL_TypeMapTest < GraphQL::TestCase
86
69
 
87
70
  loaded = false
88
71
  subject.stub(:fetch, ->(*x) { x if loaded }) do
89
- subject.stub(:base_classes, { Type: true }) do
90
- assert_raises(StandardError) { subject.fetch!(1) }
91
- end
72
+ assert_raises(StandardError) { subject.fetch!(1) }
92
73
 
93
- subject.stub(:base_classes, { Type: false }) do
94
- Rails::GraphQL.stub_const(:Type, double(eager_load!: -> { loaded = true })) do
95
- assert_equal([1, { base_class: :Type }], subject.fetch!(1))
96
- assert(loaded)
97
- end
74
+ subject.stub(:load_dependencies!, ->(*) { loaded = true }) do
75
+ assert_equal([1, { base_class: :Type }], subject.fetch!(1))
98
76
  end
99
77
  end
100
78
  end
101
79
 
102
80
  def test_fetch
103
81
  stub_dig do
104
- assert_registered(9) do
105
- assert_nil(subject.fetch(:number))
106
- assert_nil(subject.fetch(:number, base_class: :Other))
82
+ assert_nil(subject.fetch(:number))
83
+ assert_nil(subject.fetch(:number, base_class: :Other))
107
84
 
108
- assert_equal(1, subject.fetch(:string))
109
- assert_equal(1, subject.fetch(:string, prevent_register: true))
110
- assert_equal(1, subject.fetch(:number, fallback: :string))
85
+ assert_equal(1, subject.fetch(:string))
86
+ assert_equal(1, subject.fetch(:string, prevent_register: true))
87
+ assert_equal(1, subject.fetch(:number, fallback: :string))
111
88
 
112
- assert_equal(2, subject.fetch(:string, namespaces: :other))
113
- assert_equal(3, subject.fetch(:number, namespaces: Set[:other]))
89
+ assert_equal(2, subject.fetch(:string, namespaces: :other))
90
+ assert_equal(3, subject.fetch(:number, namespaces: Set[:other]))
114
91
 
115
- assert_equal(4, subject.fetch(:boolean))
116
- assert_equal(4, subject.fetch(:boolean, namespaces: :other))
117
- assert_nil(subject.fetch(:boolean, namespaces: :other, exclusive: true))
118
- end
92
+ assert_equal(4, subject.fetch(:boolean))
93
+ assert_equal(4, subject.fetch(:boolean, namespaces: :other))
94
+ assert_nil(subject.fetch(:boolean, namespaces: :other, exclusive: true))
119
95
  end
120
96
  end
121
97
 
@@ -167,10 +143,9 @@ class GraphQL_TypeMapTest < GraphQL::TestCase
167
143
  assert_equal([:base, object1, :string], added[0][0..-2])
168
144
  assert_equal([:base, object1, 'string'], added[1][0..-2])
169
145
 
170
- subject.stub(:fetch, passallthrough) do
171
- xargs = { base_class: object1, namespaces: :base, exclusive: true }
172
- assert_equal([:string, xargs], added[1][-1].call)
173
- assert_equal(object1, added[0][-1].call)
146
+ subject.stub(:dig, passallthrough) do
147
+ assert_equal([:base, object1, :string], added[1][-1].call)
148
+ assert_equal(object1, added[0][-1])
174
149
  end
175
150
 
176
151
  assert_equal(1, subject.instance_variable_get(:@objects))
@@ -212,7 +187,7 @@ class GraphQL_TypeMapTest < GraphQL::TestCase
212
187
  assert_equal([:base, :Type, :a], added[0][0..-2])
213
188
 
214
189
  subject.stub(:fetch, passallthrough) do
215
- xargs = { base_class: :Type, namespaces: [:base], exclusive: true }
190
+ xargs = { base_class: :Type, namespaces: [:base].to_set, exclusive: true }
216
191
  assert_equal([:string, xargs], added[0][-1].call)
217
192
  end
218
193
 
@@ -229,13 +204,15 @@ class GraphQL_TypeMapTest < GraphQL::TestCase
229
204
 
230
205
  def test_each_from
231
206
  assert_registered(4) do
232
- subject.stub_ivar(:@index, SAMPLE_INDEX) do
233
- items = [1, 4]
234
- subject.each_from(:base) { |x| assert_equal(items.shift, x) }
235
-
236
- assert_equal([2, 3, 1, 4], subject.each_from(:other).entries)
237
- assert_equal([2, 3], subject.each_from(:other, exclusive: true).entries)
238
- assert_equal([], subject.each_from(:other, base_class: :Other).entries)
207
+ Integer.stub_imethod(:gql_name, -> { to_s }) do
208
+ subject.stub_ivar(:@index, SAMPLE_INDEX) do
209
+ items = [1, 4]
210
+ subject.each_from(:base) { |x| assert_equal(items.shift, x) }
211
+
212
+ assert_equal([2, 3, 1, 4], subject.each_from(:other).entries)
213
+ assert_equal([2, 3], subject.each_from(:other, exclusive: true).entries)
214
+ assert_equal([], subject.each_from(:other, base_class: :Other).entries)
215
+ end
239
216
  end
240
217
  end
241
218
  end
@@ -243,7 +220,7 @@ class GraphQL_TypeMapTest < GraphQL::TestCase
243
220
  def test_after_register
244
221
  subject.stub(:fetch, passallthrough) do
245
222
  result = subject.after_register(:a, &passthrough)
246
- xargs = { prevent_register: true, base_class: :Type, namespaces: :base }
223
+ xargs = { prevent_register: true, base_class: :Type }
247
224
  assert_equal([:a, xargs], result)
248
225
  end
249
226
 
@@ -268,15 +245,20 @@ class GraphQL_TypeMapTest < GraphQL::TestCase
268
245
  [:other, :Type],
269
246
  [:other, :Type],
270
247
  ].each_with_index do |(ns, bc), idx|
271
- assert_nil(register[:a][idx].call(:x, bc, :non_called))
272
- assert_nil(register[:a][idx].call(ns, :y, :non_called))
273
- assert_equal(idx, register[:a][idx].call(ns, bc, :called))
248
+ assert_nil(register[:a][3 - idx].call(:x, bc, :non_called))
249
+ assert_nil(register[:a][3 - idx].call(ns, :y, :non_called))
250
+ assert(register[:a][3 - idx].call(ns, bc, :called))
274
251
  end
275
252
  end
276
253
 
277
254
  def test_inspect
278
- assert_equal(<<~INFO.chomp, subject.inspect)
279
- #<Rails::GraphQL::TypeMap [index] @namespaces=0 @base_classes=3 @objects=0 @pending=0>
255
+ assert_equal(<<~INFO.squish, subject.inspect)
256
+ #<Rails::GraphQL::TypeMap [index]
257
+ @namespaces=0
258
+ @base_classes=3
259
+ @objects=0
260
+ @pending=0
261
+ @dependencies={base: 15}>
280
262
  INFO
281
263
  end
282
264
 
@@ -320,11 +302,11 @@ class GraphQL_TypeMapTest < GraphQL::TestCase
320
302
 
321
303
  def test_register_pending_bang
322
304
  registered = false
323
- object = double(register!: -> { -> { registered = true } }, registered?: false)
305
+ object = double(register!: -> { registered = true }, registered?: false)
324
306
  skipped = double(registered?: false)
325
307
  other = double(registered?: true)
326
308
 
327
- subject.stub(:skip_register, [skipped]) do
309
+ subject.stub(:skip_register, [[skipped].to_set]) do
328
310
  subject.stub_ivar(:@pending, [[skipped, :a], [object, :b], [other, :c]]) do
329
311
  subject.send(:register_pending!)
330
312
  assert(registered)
@@ -38,25 +38,6 @@ class GraphQL_TypeTest < GraphQL::TestCase
38
38
  assert_equal(1, DESCRIBED_CLASS.decorate(1))
39
39
  end
40
40
 
41
- def test_gql_resolver_ask
42
- DESCRIBED_CLASS.stub(:base_object?, false) do
43
- refute(DESCRIBED_CLASS.gql_resolver?(:calculate))
44
- DESCRIBED_CLASS.send(:define_method, :calculate) {}
45
-
46
- assert(DESCRIBED_CLASS.gql_resolver?(:calculate))
47
-
48
- other_class = unmapped_class(DESCRIBED_CLASS)
49
- assert(other_class.gql_resolver?(:calculate))
50
-
51
- other_class.stub(:base_object?, true) do
52
- refute(other_class.gql_resolver?(:calculate))
53
- end
54
-
55
- DESCRIBED_CLASS.send(:undef_method, :calculate)
56
- refute(DESCRIBED_CLASS.gql_resolver?(:calculate))
57
- end
58
- end
59
-
60
41
  def test_kind_ask
61
42
  assert_respond_to(DESCRIBED_CLASS, :scalar?)
62
43
  assert_respond_to(DESCRIBED_CLASS, :object?)
data/test/graphql_test.rb CHANGED
@@ -12,7 +12,7 @@ class GraphQLTest < GraphQL::TestCase
12
12
  end
13
13
 
14
14
  def test_ar_adapter_key
15
- DESCRIBED_CLASS.stub(:config, double(ar_adapters: { 'a' => 1 })) do
15
+ DESCRIBED_CLASS.stub(:config, double(ar_adapters: { 'a' => { key: 1 } })) do
16
16
  assert_equal(1, DESCRIBED_CLASS.ar_adapter_key('a'))
17
17
  assert_nil(DESCRIBED_CLASS.ar_adapter_key('b'))
18
18
  end
@@ -1,9 +1,20 @@
1
1
  require 'integration/config'
2
2
 
3
- class Integration_Memory_AuthorizationTest < GraphQL::IntegrationTestCase
4
- load_schema 'authorization'
3
+ class Integration_AuthorizationTest < GraphQL::IntegrationTestCase
4
+ class SCHEMA < GraphQL::Schema
5
+ namespace :authorization
6
+
7
+ configure do |config|
8
+ config.enable_string_collector = false
9
+ config.default_response_format = :json
10
+ end
11
+
12
+ query_fields do
13
+ field(:sample1, :string).resolve { 'Ok 1' }
14
+ field(:sample2, :string).authorize.resolve { 'Ok 2' }
15
+ end
16
+ end
5
17
 
6
- SCHEMA = ::AuthorizationSchema
7
18
  EXCEPTION_NAME = 'Rails::GraphQL::UnauthorizedFieldError'
8
19
  EXCEPTION_PATH = ['errors', 0, 'extensions', 'exception']
9
20
 
@@ -22,11 +33,11 @@ class Integration_Memory_AuthorizationTest < GraphQL::IntegrationTestCase
22
33
  assert_exception('{ sample2 }')
23
34
  assert_result({ sample1: 'Ok 1', sample2: nil }, '{ sample1 sample2 }', dig: 'data')
24
35
 
25
- SCHEMA.stub_imethod(:authorize!, &:authorize!).call do
36
+ SCHEMA.stub_imethod(:authorize!, -> { authorized! }) do
26
37
  assert_result(SAMPLE2, '{ sample2 }')
27
38
  end
28
39
 
29
- SCHEMA.stub_imethod(:authorize!, &:unauthorize!).call do
40
+ SCHEMA.stub_imethod(:authorize!, -> { unauthorized! }) do
30
41
  assert_exception('{ sample2 }')
31
42
  end
32
43
  end
@@ -38,7 +49,7 @@ class Integration_Memory_AuthorizationTest < GraphQL::IntegrationTestCase
38
49
  assert_executed { assert_result(SAMPLE1, '{ sample1 }') }
39
50
  end
40
51
 
41
- block = ->(ev) { executed! && ev.unauthorize! }
52
+ block = ->(ev) { executed! && ev.unauthorized! }
42
53
  field.stub_ivar(:@authorizer, [[], {}, block]) do
43
54
  assert_executed { assert_exception('{ sample1 }') }
44
55
  end
@@ -51,7 +62,7 @@ class Integration_Memory_AuthorizationTest < GraphQL::IntegrationTestCase
51
62
  assert_executed { assert_result(SAMPLE2, '{ sample2 }') }
52
63
 
53
64
  assert_executed do
54
- field.on(:authorize) { |event| event.unauthorize! }
65
+ field.on(:authorize) { |event| event.unauthorized! }
55
66
  assert_exception('{ sample2 }')
56
67
  end
57
68
  end
@@ -64,29 +75,44 @@ class Integration_Memory_AuthorizationTest < GraphQL::IntegrationTestCase
64
75
  auth_directive.on(:authorize, &method(:executed!))
65
76
 
66
77
  auth_directive.stub_ivar(:@gql_name, 'AuthDirective') do
67
- field.stub_ivar(:@directives, [auth_directive.new]) do
78
+ instance = auth_directive.new.tap { |dir| dir.instance_variable_set(:@owner, nil) }
79
+ field.stub_ivar(:@directives, [instance]) do
68
80
  assert_executed { assert_result(SAMPLE2, '{ sample2 }') }
69
81
  end
70
82
 
71
- SCHEMA.stub_ivar(:@directives, [auth_directive.new]) do
72
- assert_executed { assert_result(SAMPLE2, '{ sample2 }') }
83
+ instance = auth_directive.new.tap { |dir| dir.instance_variable_set(:@owner, nil) }
84
+ SCHEMA.stub_ivar(:@directives, [instance]) do
85
+ assert_executed(0) { assert_result(SAMPLE2, '{ sample2 }') }
86
+ end
87
+
88
+ auth_directive.events[:authorize][0].stub_ivar(:@exclusive, false) do
89
+ SCHEMA.stub_ivar(:@directives, [instance]) do
90
+ assert_executed { assert_result(SAMPLE2, '{ sample2 }') }
91
+ end
92
+ end
93
+
94
+ instance = auth_directive.new.tap { |dir| dir.instance_variable_set(:@owner, nil) }
95
+ method = ->(*) { @directives = Set.new([instance]) }
96
+ Rails::GraphQL::Request::Component::Field.stub_imethod(:parse_directives, method) do
97
+ assert_executed { assert_result(SAMPLE2, '{ sample2 @AuthDirective }') }
73
98
  end
74
99
  end
75
100
  end
76
101
 
77
102
  def test_authorize_bypass
78
103
  field = SCHEMA.query_field(:sample2)
79
- auth_block = ->(e, event) { e.call && event.authorize! }.curry(2)[method(:executed!)]
80
- unauth_block = ->(e, event) { e.call && event.unauthorize! }.curry(2)[method(:executed!)]
104
+ counter = method(:executed!)
105
+ auth_block = ->(ev = nil) { counter.call && (ev || itself).authorized! }
106
+ unauth_block = ->(ev = nil) { counter.call && (ev || itself).unauthorized! }
81
107
 
82
108
  field.stub_ivar(:@events, { authorize: [unauth_block] }) do
83
- SCHEMA.stub_imethod(:authorize!, &auth_block).call do
109
+ SCHEMA.stub_imethod(:authorize!, auth_block) do
84
110
  assert_executed { assert_result(SAMPLE2, '{ sample2 }') }
85
111
  end
86
112
  end
87
113
 
88
114
  field.stub_ivar(:@events, { authorize: [auth_block] }) do
89
- SCHEMA.stub_imethod(:authorize!, &unauth_block).call do
115
+ SCHEMA.stub_imethod(:authorize!, unauth_block) do
90
116
  assert_executed { assert_exception('{ sample2 }') }
91
117
  end
92
118
  end
@@ -7,8 +7,28 @@ module GraphQL
7
7
  SCHEMAS = Pathname.new(__dir__).join('schemas')
8
8
  ASSETS = Pathname.new(__dir__).join('../assets')
9
9
 
10
+ I18n.load_path << ASSETS.join("en.yml")
11
+
12
+ BASE_SCHEMA = ::Rails::GraphQL::Schema
13
+
14
+ def run(*)
15
+ BASE_SCHEMA.send(:introspection_dependencies!)
16
+ BASE_SCHEMA.type_map.send(:load_dependencies!)
17
+
18
+ super
19
+ end
20
+
10
21
  def setup
11
- reset_type_map!
22
+ BASE_SCHEMA.type_map.base_classes.each do |base_class|
23
+ ::GraphQL.const_get(base_class).descendants.each(&:register!)
24
+ end
25
+
26
+ index = BASE_SCHEMA.type_map.instance_variable_get(:@index)[:base][:Type]
27
+ remove_keys_form_type_map&.each(&index.method(:delete))
28
+ end
29
+
30
+ def teardown
31
+ BASE_SCHEMA.type_map.reset!
12
32
  end
13
33
 
14
34
  protected
@@ -17,8 +37,8 @@ module GraphQL
17
37
  require(SCHEMAS.join("#{name}"))
18
38
  end
19
39
 
20
- def reset_type_map!
21
- Rails::GraphQL.type_map.hard_reset!
40
+ def remove_keys_form_type_map
41
+ all_non_spec_keys
22
42
  end
23
43
 
24
44
  def named_list(*list, **extra)
@@ -52,5 +72,18 @@ module GraphQL
52
72
  obj = obj.map(&:deep_stringify_keys) if obj.is_a?(Array)
53
73
  obj.nil? ? assert_nil(result) : assert_equal(obj, result)
54
74
  end
75
+
76
+ def all_non_spec_keys
77
+ [
78
+ :any, 'Any',
79
+ :bigint, 'Bigint',
80
+ :binary, 'Binary', :file,
81
+ :date_time, 'DateTime', :datetime,
82
+ :date, 'Date',
83
+ :decimal, 'Decimal',
84
+ :time, 'Time',
85
+ :json, 'JSON',
86
+ ]
87
+ end
55
88
  end
56
89
  end
@@ -0,0 +1,39 @@
1
+ require 'integration/config'
2
+
3
+ class Integration_CustomizationTest < GraphQL::IntegrationTestCase
4
+ class SCHEMA < GraphQL::Schema
5
+ namespace :customization
6
+
7
+ configure do |config|
8
+ config.schema_type_names = {
9
+ query: 'A',
10
+ mutation: 'B',
11
+ subscription: 'C',
12
+ }
13
+ end
14
+
15
+ query_fields { field(:one, :string) }
16
+ mutation_fields { field(:two, :string) }
17
+ subscription_fields { field(:three, :string) }
18
+ end
19
+
20
+ def test_type_name_for
21
+ assert_equal('A', SCHEMA.type_name_for(:query))
22
+ assert_equal('B', SCHEMA.type_name_for(:mutation))
23
+ assert_equal('C', SCHEMA.type_name_for(:subscription))
24
+ end
25
+
26
+ def test_type_map
27
+ assert_equal(SCHEMA.query_type, SCHEMA.find_type('A'))
28
+ assert_equal(SCHEMA.mutation_type, SCHEMA.find_type('B'))
29
+ assert_equal(SCHEMA.subscription_type, SCHEMA.find_type('C'))
30
+ end
31
+
32
+ def test_cache_prefix
33
+ assert_equal('graphql/customization/', SCHEMA.config.cache_prefix)
34
+ SCHEMA.config.cache_prefix = 'banana'
35
+ assert_equal('banana', SCHEMA.config.cache_prefix)
36
+ SCHEMA.config.cache_prefix = nil
37
+ assert_equal('graphql/customization/', SCHEMA.config.cache_prefix)
38
+ end
39
+ end
@@ -0,0 +1,99 @@
1
+ require 'integration/config'
2
+
3
+ class Integration_GlobalIDTest < GraphQL::IntegrationTestCase
4
+ load_schema 'memory'
5
+
6
+ SCHEMA = ::StartWarsMemSchema
7
+
8
+ ## CREATE
9
+
10
+ def test_create_directive
11
+ obj = GraphQL::Directive::DeprecatedDirective
12
+ assert_gid_value('gql://base/Directive/deprecated', obj)
13
+ end
14
+
15
+ def test_create_directive_instance
16
+ obj = GraphQL::DeprecatedDirective()
17
+ assert_gid_value('gql://base/Directive/deprecated?', obj)
18
+
19
+ obj = GraphQL::DeprecatedDirective(reason: 'A B')
20
+ assert_gid_value('gql://base/Directive/deprecated?reason=A+B', obj)
21
+ end
22
+
23
+ def test_create_schema
24
+ assert_gid_value('gql://start-wars-mem/Schema', SCHEMA)
25
+ end
26
+
27
+ def test_create_query_field
28
+ obj = SCHEMA[:query][:hero]
29
+ assert_gid_value('gql://start-wars-mem/Schema/query/hero', obj)
30
+ end
31
+
32
+ def test_create_mutation_field
33
+ obj = SCHEMA[:mutation][:change_human]
34
+ assert_gid_value('gql://start-wars-mem/Schema/mutation/changeHuman', obj)
35
+ end
36
+
37
+ def test_create_object_field
38
+ obj = SCHEMA::NestedTypes::HumanObject[:name]
39
+ assert_gid_value('gql://start-wars-mem/Human/name', obj)
40
+ end
41
+
42
+ def test_create_scalar_type
43
+ obj = GraphQL.type_map.fetch(:string)
44
+ assert_gid_value('gql://base/Type/String', obj)
45
+ end
46
+
47
+ def assert_gid_value(result, object)
48
+ assert_equal(result, object.to_gid.to_s)
49
+ end
50
+
51
+ ## PARSE
52
+
53
+ def test_parse_directive
54
+ obj = find_gid('gql://base/Directive/deprecated')
55
+ assert_equal(GraphQL::Directive::DeprecatedDirective, obj)
56
+ end
57
+
58
+ def test_parse_directive_instance
59
+ obj = find_gid('gql://base/Directive/deprecated?')
60
+ assert_instance_of(GraphQL::Directive::DeprecatedDirective, obj)
61
+ assert_nil(obj.args[:reason])
62
+
63
+ obj = find_gid('gql://base/Directive/deprecated?reason=A+B')
64
+ assert_instance_of(GraphQL::Directive::DeprecatedDirective, obj)
65
+ assert_equal('A B', obj.args[:reason])
66
+
67
+ obj = find_gid('gql://base/Directive/skip?if=false')
68
+ assert_instance_of(GraphQL::Directive::SkipDirective, obj)
69
+ assert_equal(false, obj.args[:if])
70
+ end
71
+
72
+ def test_parse_schema
73
+ assert_equal(SCHEMA, find_gid('gql://start-wars-mem/Schema'))
74
+ end
75
+
76
+ def test_parse_query_field
77
+ obj = find_gid('gql://start-wars-mem/Schema/query/hero')
78
+ assert_equal(SCHEMA[:query][:hero], obj)
79
+ end
80
+
81
+ def test_parse_mutation_field
82
+ obj = find_gid('gql://start-wars-mem/Schema/mutation/changeHuman')
83
+ assert_equal(SCHEMA[:mutation][:change_human], obj)
84
+ end
85
+
86
+ def test_parse_object_field
87
+ obj = find_gid('gql://start-wars-mem/Human/name')
88
+ assert_equal(SCHEMA::NestedTypes::HumanObject[:name], obj)
89
+ end
90
+
91
+ def test_parse_scalar_type
92
+ obj = find_gid('gql://base/Type/String')
93
+ assert_equal(GraphQL.type_map.fetch(:string), obj)
94
+ end
95
+
96
+ def find_gid(gid)
97
+ GraphQL::GlobalID.find(gid)
98
+ end
99
+ end
@@ -6,13 +6,19 @@ class Integration_Memory_StarWarsIntrospectionTest < GraphQL::IntegrationTestCas
6
6
 
7
7
  SCHEMA = ::StartWarsMemSchema
8
8
 
9
+ def test_auto_introspection
10
+ assert(SCHEMA.introspection?)
11
+ assert(SCHEMA.has_field?(:query, :__schema))
12
+ assert(SCHEMA.has_field?(:query, :__type))
13
+ end
14
+
9
15
  def test_query_schema_types
10
- types = named_list(*%w[Bigint Binary Boolean Character Date DateTime Decimal Droid Episode
11
- Float Human ID Int String Time _Mutation _Query __Directive __DirectiveLocation
12
- __EnumValue __Field __InputValue __Schema __Type __TypeKind])
16
+ types = named_list(*%w[Boolean Character Droid Episode Float Human ID Int String
17
+ _Mutation _Query __Directive __DirectiveLocation __EnumValue __Field __InputValue
18
+ __Schema __Type __TypeKind])
13
19
 
14
20
  sort_items = ->(result) do
15
- result.dig('data', '__schema', 'types').sort_by! { |t| t['name'] }
21
+ result.dig('data', '__schema', 'types')&.sort_by! { |t| t['name'] }
16
22
  end
17
23
 
18
24
  assert_result({ data: { __schema: { types: types } } }, <<~GQL, &sort_items)
@@ -53,11 +59,11 @@ class Integration_Memory_StarWarsIntrospectionTest < GraphQL::IntegrationTestCas
53
59
  def test_query_object_fields
54
60
  fields = [
55
61
  { name: 'id', type: { name: nil, kind: 'NON_NULL' } },
56
- { name: 'name', type: { name: 'String', kind: 'SCALAR' } },
57
- { name: 'friends', type: { name: nil, kind: 'LIST' } },
58
62
  { name: 'appearsIn', type: { name: nil, kind: 'LIST' } },
59
- { name: 'secretBackstory', type: { name: 'String', kind: 'SCALAR' } },
63
+ { name: 'friends', type: { name: nil, kind: 'LIST' } },
64
+ { name: 'name', type: { name: 'String', kind: 'SCALAR' } },
60
65
  { name: 'primaryFunction', type: { name: 'String', kind: 'SCALAR' } },
66
+ { name: 'secretBackstory', type: { name: 'String', kind: 'SCALAR' } },
61
67
  ]
62
68
 
63
69
  assert_result({ data: { __type: { name: 'Droid', fields: fields } } }, <<~GQL)
@@ -68,11 +74,11 @@ class Integration_Memory_StarWarsIntrospectionTest < GraphQL::IntegrationTestCas
68
74
  def test_query_object_fields_with_nested_type
69
75
  fields = [
70
76
  { name: 'id', type: { name: nil, kind: 'NON_NULL', ofType: { name: 'ID', kind: 'SCALAR' } } },
71
- { name: 'name', type: { name: 'String', kind: 'SCALAR', ofType: nil } },
72
- { name: 'friends', type: { name: nil, kind: 'LIST', ofType: { name: 'Character', kind: 'INTERFACE' } } },
73
77
  { name: 'appearsIn', type: { name: nil, kind: 'LIST', ofType: { name: 'Episode', kind: 'ENUM' } } },
74
- { name: 'secretBackstory', type: { name: 'String', kind: 'SCALAR', ofType: nil } },
78
+ { name: 'friends', type: { name: nil, kind: 'LIST', ofType: { name: 'Character', kind: 'INTERFACE' } } },
79
+ { name: 'name', type: { name: 'String', kind: 'SCALAR', ofType: nil } },
75
80
  { name: 'primaryFunction', type: { name: 'String', kind: 'SCALAR', ofType: nil } },
81
+ { name: 'secretBackstory', type: { name: 'String', kind: 'SCALAR', ofType: nil } },
76
82
  ]
77
83
 
78
84
  assert_result({ data: { __type: { name: 'Droid', fields: fields } } }, <<~GQL)
@@ -98,11 +104,9 @@ class Integration_Memory_StarWarsIntrospectionTest < GraphQL::IntegrationTestCas
98
104
  }, defaultValue: nil }
99
105
 
100
106
  fields = [
101
- { name: '__schema', args: [] },
102
- { name: '__type', args: [name_arg] },
107
+ { name: 'droid', args: [id_arg.merge(description: 'ID of the droid')] },
103
108
  { name: 'hero', args: [epi_arg] },
104
109
  { name: 'human', args: [id_arg.merge(description: 'ID of the human')] },
105
- { name: 'droid', args: [id_arg.merge(description: 'ID of the droid')] },
106
110
  ]
107
111
 
108
112
  assert_result({ data: { __schema: { queryType: { fields: fields } } } }, <<~GQL)
@@ -128,6 +132,8 @@ class Integration_Memory_StarWarsIntrospectionTest < GraphQL::IntegrationTestCas
128
132
  # There are some issues with the end sorting, so compare the string result
129
133
  # with sorted characters, which will produce the exact match
130
134
  def test_query_full_introspection
135
+ SCHEMA.send(:enable_introspection!)
136
+
131
137
  query = gql_file('introspection')
132
138
  result = text_file('introspection-mem').split('').sort.join
133
139
  assert_result(result, query, as: :string) do |res|
@@ -137,8 +143,10 @@ class Integration_Memory_StarWarsIntrospectionTest < GraphQL::IntegrationTestCas
137
143
  end
138
144
 
139
145
  def test_gql_introspection
140
- # File.write('test/assets/mem.gql', SCHEMA.to_gql)
141
- result = gql_file('mem').split('').sort.join.squish
142
- assert_equal(result, SCHEMA.to_gql.split('').sort.join.squish)
146
+ result = SCHEMA.to_gql
147
+ expected = gql_file('mem').split('').sort.join.squish
148
+
149
+ # File.write('test/assets/mem.gql', result)
150
+ assert_equal(expected, result.split('').sort.join.squish)
143
151
  end
144
152
  end