rails-graphql 0.2.1 → 1.0.0.beta

Sign up to get free protection for your applications and to get access to all the features.
Files changed (297) 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 +646 -0
  6. data/ext/shared.c +482 -0
  7. data/ext/shared.h +177 -0
  8. data/lib/gql_parser.so +0 -0
  9. data/lib/rails/graphql/adapters/mysql_adapter.rb +59 -0
  10. data/lib/rails/graphql/adapters/pg_adapter.rb +25 -22
  11. data/lib/rails/graphql/adapters/sqlite_adapter.rb +17 -14
  12. data/lib/rails/graphql/alternative/field_set.rb +36 -0
  13. data/lib/rails/graphql/alternative/mutation.rb +17 -0
  14. data/lib/rails/graphql/alternative/query.rb +93 -0
  15. data/lib/rails/graphql/alternative/subscription.rb +17 -0
  16. data/lib/rails/graphql/alternative.rb +20 -0
  17. data/lib/rails/graphql/argument.rb +21 -24
  18. data/lib/rails/graphql/callback.rb +24 -9
  19. data/lib/rails/graphql/collectors/hash_collector.rb +14 -6
  20. data/lib/rails/graphql/collectors/idented_collector.rb +10 -7
  21. data/lib/rails/graphql/collectors/json_collector.rb +22 -17
  22. data/lib/rails/graphql/collectors.rb +4 -4
  23. data/lib/rails/graphql/config.rb +130 -15
  24. data/lib/rails/graphql/directive/cached_directive.rb +33 -0
  25. data/lib/rails/graphql/directive/deprecated_directive.rb +10 -10
  26. data/lib/rails/graphql/directive/include_directive.rb +5 -4
  27. data/lib/rails/graphql/directive/skip_directive.rb +5 -4
  28. data/lib/rails/graphql/directive.rb +118 -63
  29. data/lib/rails/graphql/errors.rb +33 -4
  30. data/lib/rails/graphql/event.rb +16 -5
  31. data/lib/rails/graphql/field/authorized_field.rb +19 -3
  32. data/lib/rails/graphql/field/input_field.rb +11 -10
  33. data/lib/rails/graphql/field/mutation_field.rb +42 -7
  34. data/lib/rails/graphql/field/output_field.rb +102 -13
  35. data/lib/rails/graphql/field/proxied_field.rb +31 -22
  36. data/lib/rails/graphql/field/resolved_field.rb +26 -24
  37. data/lib/rails/graphql/field/scoped_config.rb +10 -4
  38. data/lib/rails/graphql/field/subscription_field.rb +140 -0
  39. data/lib/rails/graphql/field/typed_field.rb +43 -22
  40. data/lib/rails/graphql/field.rb +70 -56
  41. data/lib/rails/graphql/global_id.rb +85 -0
  42. data/lib/rails/graphql/helpers/attribute_delegator.rb +5 -5
  43. data/lib/rails/graphql/helpers/inherited_collection/array.rb +50 -0
  44. data/lib/rails/graphql/helpers/inherited_collection/base.rb +43 -0
  45. data/lib/rails/graphql/helpers/inherited_collection/hash.rb +87 -0
  46. data/lib/rails/graphql/helpers/inherited_collection.rb +25 -76
  47. data/lib/rails/graphql/helpers/instantiable.rb +15 -0
  48. data/lib/rails/graphql/helpers/leaf_from_ar.rb +7 -7
  49. data/lib/rails/graphql/helpers/registerable.rb +44 -62
  50. data/lib/rails/graphql/helpers/unregisterable.rb +16 -0
  51. data/lib/rails/graphql/helpers/with_arguments.rb +31 -27
  52. data/lib/rails/graphql/helpers/with_assignment.rb +6 -6
  53. data/lib/rails/graphql/helpers/with_callbacks.rb +25 -8
  54. data/lib/rails/graphql/helpers/with_description.rb +71 -0
  55. data/lib/rails/graphql/helpers/with_directives.rb +54 -30
  56. data/lib/rails/graphql/helpers/with_events.rb +21 -23
  57. data/lib/rails/graphql/helpers/with_fields.rb +76 -22
  58. data/lib/rails/graphql/helpers/with_global_id.rb +22 -0
  59. data/lib/rails/graphql/helpers/with_name.rb +43 -0
  60. data/lib/rails/graphql/helpers/with_namespace.rb +7 -4
  61. data/lib/rails/graphql/helpers/with_owner.rb +8 -7
  62. data/lib/rails/graphql/helpers/with_schema_fields.rb +137 -55
  63. data/lib/rails/graphql/helpers/with_validator.rb +9 -9
  64. data/lib/rails/graphql/helpers.rb +10 -3
  65. data/lib/rails/graphql/introspection.rb +43 -36
  66. data/lib/rails/graphql/railtie.rb +88 -33
  67. data/lib/rails/graphql/railties/base_generator.rb +3 -9
  68. data/lib/rails/graphql/railties/channel.rb +157 -0
  69. data/lib/rails/graphql/railties/controller.rb +62 -17
  70. data/lib/rails/graphql/railties/controller_runtime.rb +5 -5
  71. data/lib/rails/graphql/railties/log_subscriber.rb +81 -14
  72. data/lib/rails/graphql/request/arguments.rb +24 -49
  73. data/lib/rails/graphql/request/backtrace.rb +191 -0
  74. data/lib/rails/graphql/request/component/field.rb +86 -65
  75. data/lib/rails/graphql/request/component/fragment.rb +72 -24
  76. data/lib/rails/graphql/request/component/operation/subscription.rb +164 -4
  77. data/lib/rails/graphql/request/component/operation.rb +63 -31
  78. data/lib/rails/graphql/request/component/spread.rb +68 -25
  79. data/lib/rails/graphql/request/component/typename.rb +27 -12
  80. data/lib/rails/graphql/request/component.rb +75 -36
  81. data/lib/rails/graphql/request/context.rb +18 -8
  82. data/lib/rails/graphql/request/errors.rb +16 -6
  83. data/lib/rails/graphql/request/event.rb +19 -8
  84. data/lib/rails/graphql/request/helpers/directives.rb +68 -27
  85. data/lib/rails/graphql/request/helpers/selection_set.rb +51 -25
  86. data/lib/rails/graphql/request/helpers/value_writers.rb +18 -16
  87. data/lib/rails/graphql/request/prepared_data.rb +98 -0
  88. data/lib/rails/graphql/request/steps/authorizable.rb +24 -14
  89. data/lib/rails/graphql/request/steps/organizable.rb +110 -48
  90. data/lib/rails/graphql/request/steps/{prepareable.rb → preparable.rb} +20 -7
  91. data/lib/rails/graphql/request/steps/{resolveable.rb → resolvable.rb} +15 -6
  92. data/lib/rails/graphql/request/strategy/cached_strategy.rb +64 -0
  93. data/lib/rails/graphql/request/strategy/dynamic_instance.rb +6 -6
  94. data/lib/rails/graphql/request/strategy/multi_query_strategy.rb +6 -13
  95. data/lib/rails/graphql/request/strategy/sequenced_strategy.rb +9 -9
  96. data/lib/rails/graphql/request/strategy.rb +131 -75
  97. data/lib/rails/graphql/request/subscription.rb +80 -0
  98. data/lib/rails/graphql/request.rb +305 -86
  99. data/lib/rails/graphql/schema.rb +240 -48
  100. data/lib/rails/graphql/shortcuts.rb +22 -3
  101. data/lib/rails/graphql/source/active_record/builders.rb +49 -35
  102. data/lib/rails/graphql/source/active_record_source.rb +70 -54
  103. data/lib/rails/graphql/source/base.rb +111 -0
  104. data/lib/rails/graphql/source/builder.rb +128 -0
  105. data/lib/rails/graphql/source/scoped_arguments.rb +31 -19
  106. data/lib/rails/graphql/source.rb +89 -213
  107. data/lib/rails/graphql/subscription/provider/action_cable.rb +112 -0
  108. data/lib/rails/graphql/subscription/provider/base.rb +191 -0
  109. data/lib/rails/graphql/subscription/provider.rb +18 -0
  110. data/lib/rails/graphql/subscription/store/base.rb +145 -0
  111. data/lib/rails/graphql/subscription/store/memory.rb +127 -0
  112. data/lib/rails/graphql/subscription/store.rb +19 -0
  113. data/lib/rails/graphql/subscription.rb +17 -0
  114. data/lib/rails/graphql/to_gql.rb +29 -32
  115. data/lib/rails/graphql/type/enum/directive_location_enum.rb +11 -11
  116. data/lib/rails/graphql/type/enum/type_kind_enum.rb +3 -3
  117. data/lib/rails/graphql/type/enum.rb +34 -48
  118. data/lib/rails/graphql/type/input.rb +74 -23
  119. data/lib/rails/graphql/type/interface.rb +16 -26
  120. data/lib/rails/graphql/type/object/directive_object.rb +4 -4
  121. data/lib/rails/graphql/type/object/enum_value_object.rb +3 -3
  122. data/lib/rails/graphql/type/object/field_object.rb +24 -6
  123. data/lib/rails/graphql/type/object/input_value_object.rb +3 -3
  124. data/lib/rails/graphql/type/object/schema_object.rb +5 -8
  125. data/lib/rails/graphql/type/object/type_object.rb +29 -19
  126. data/lib/rails/graphql/type/object.rb +26 -23
  127. data/lib/rails/graphql/type/scalar/any_scalar.rb +30 -0
  128. data/lib/rails/graphql/type/scalar/bigint_scalar.rb +5 -5
  129. data/lib/rails/graphql/type/scalar/binary_scalar.rb +3 -3
  130. data/lib/rails/graphql/type/scalar/boolean_scalar.rb +8 -8
  131. data/lib/rails/graphql/type/scalar/date_scalar.rb +3 -3
  132. data/lib/rails/graphql/type/scalar/date_time_scalar.rb +3 -3
  133. data/lib/rails/graphql/type/scalar/decimal_scalar.rb +3 -3
  134. data/lib/rails/graphql/type/scalar/float_scalar.rb +5 -5
  135. data/lib/rails/graphql/type/scalar/id_scalar.rb +6 -5
  136. data/lib/rails/graphql/type/scalar/int_scalar.rb +6 -5
  137. data/lib/rails/graphql/type/scalar/json_scalar.rb +39 -0
  138. data/lib/rails/graphql/type/scalar/string_scalar.rb +18 -4
  139. data/lib/rails/graphql/type/scalar/time_scalar.rb +5 -5
  140. data/lib/rails/graphql/type/scalar.rb +25 -22
  141. data/lib/rails/graphql/type/union.rb +14 -16
  142. data/lib/rails/graphql/type.rb +34 -25
  143. data/lib/rails/graphql/type_map.rb +256 -164
  144. data/lib/rails/graphql/uri.rb +166 -0
  145. data/lib/rails/graphql/version.rb +15 -3
  146. data/lib/rails/graphql.rake +3 -0
  147. data/lib/rails/graphql.rb +85 -52
  148. data/lib/rails-graphql.rb +1 -1
  149. data/test/assets/en.yml +29 -0
  150. data/test/assets/introspection-mem.txt +1 -1
  151. data/test/assets/mem.gql +18 -45
  152. data/test/assets/mysql.gql +392 -0
  153. data/test/assets/sqlite.gql +21 -12
  154. data/test/assets/translate.gql +335 -0
  155. data/test/config.rb +18 -8
  156. data/test/graphql/schema_test.rb +12 -19
  157. data/test/graphql/source_test.rb +8 -75
  158. data/test/graphql/type/enum_test.rb +207 -203
  159. data/test/graphql/type/input_test.rb +14 -9
  160. data/test/graphql/type/interface_test.rb +4 -4
  161. data/test/graphql/type/scalar/any_scalar_test.rb +38 -0
  162. data/test/graphql/type/scalar/boolean_scalar_test.rb +6 -3
  163. data/test/graphql/type/scalar/json_scalar_test.rb +23 -0
  164. data/test/graphql/type_map_test.rb +51 -66
  165. data/test/graphql/type_test.rb +0 -19
  166. data/test/graphql_test.rb +1 -1
  167. data/test/integration/{authorization/authorization_test.rb → authorization_test.rb} +40 -14
  168. data/test/integration/config.rb +36 -3
  169. data/test/integration/customization_test.rb +39 -0
  170. data/test/integration/global_id_test.rb +99 -0
  171. data/test/integration/memory/star_wars_introspection_test.rb +24 -16
  172. data/test/integration/memory/star_wars_query_test.rb +54 -3
  173. data/test/integration/memory/star_wars_validation_test.rb +1 -1
  174. data/test/integration/mysql/star_wars_introspection_test.rb +25 -0
  175. data/test/integration/persisted_query_test.rb +87 -0
  176. data/test/integration/resolver_precedence_test.rb +154 -0
  177. data/test/integration/schemas/memory.rb +22 -7
  178. data/test/integration/schemas/mysql.rb +62 -0
  179. data/test/integration/schemas/sqlite.rb +21 -12
  180. data/test/integration/sqlite/star_wars_global_id_test.rb +83 -0
  181. data/test/integration/sqlite/star_wars_introspection_test.rb +10 -0
  182. data/test/integration/sqlite/star_wars_query_test.rb +14 -1
  183. data/test/integration/translate_test.rb +61 -0
  184. data/test/test_ext.rb +16 -13
  185. metadata +108 -157
  186. data/ext/depend +0 -3
  187. data/ext/graphqlparser/Ast.cpp +0 -346
  188. data/ext/graphqlparser/Ast.h +0 -1214
  189. data/ext/graphqlparser/AstNode.h +0 -36
  190. data/ext/graphqlparser/AstVisitor.h +0 -137
  191. data/ext/graphqlparser/GraphQLParser.cpp +0 -76
  192. data/ext/graphqlparser/GraphQLParser.h +0 -55
  193. data/ext/graphqlparser/JsonVisitor.cpp +0 -161
  194. data/ext/graphqlparser/JsonVisitor.cpp.inc +0 -456
  195. data/ext/graphqlparser/JsonVisitor.h +0 -121
  196. data/ext/graphqlparser/JsonVisitor.h.inc +0 -110
  197. data/ext/graphqlparser/VERSION +0 -1
  198. data/ext/graphqlparser/c/GraphQLAst.cpp +0 -324
  199. data/ext/graphqlparser/c/GraphQLAst.h +0 -180
  200. data/ext/graphqlparser/c/GraphQLAstForEachConcreteType.h +0 -44
  201. data/ext/graphqlparser/c/GraphQLAstNode.cpp +0 -25
  202. data/ext/graphqlparser/c/GraphQLAstNode.h +0 -33
  203. data/ext/graphqlparser/c/GraphQLAstToJSON.cpp +0 -21
  204. data/ext/graphqlparser/c/GraphQLAstToJSON.h +0 -24
  205. data/ext/graphqlparser/c/GraphQLAstVisitor.cpp +0 -55
  206. data/ext/graphqlparser/c/GraphQLAstVisitor.h +0 -53
  207. data/ext/graphqlparser/c/GraphQLParser.cpp +0 -35
  208. data/ext/graphqlparser/c/GraphQLParser.h +0 -54
  209. data/ext/graphqlparser/dump_json_ast.cpp +0 -48
  210. data/ext/graphqlparser/lexer.lpp +0 -324
  211. data/ext/graphqlparser/parser.ypp +0 -693
  212. data/ext/graphqlparser/parsergen/lexer.cpp +0 -2633
  213. data/ext/graphqlparser/parsergen/lexer.h +0 -528
  214. data/ext/graphqlparser/parsergen/location.hh +0 -189
  215. data/ext/graphqlparser/parsergen/parser.tab.cpp +0 -3300
  216. data/ext/graphqlparser/parsergen/parser.tab.hpp +0 -646
  217. data/ext/graphqlparser/parsergen/position.hh +0 -179
  218. data/ext/graphqlparser/parsergen/stack.hh +0 -156
  219. data/ext/graphqlparser/syntaxdefs.h +0 -19
  220. data/ext/libgraphqlparser/AstNode.h +0 -36
  221. data/ext/libgraphqlparser/CMakeLists.txt +0 -148
  222. data/ext/libgraphqlparser/CONTRIBUTING.md +0 -23
  223. data/ext/libgraphqlparser/GraphQLParser.cpp +0 -76
  224. data/ext/libgraphqlparser/GraphQLParser.h +0 -55
  225. data/ext/libgraphqlparser/JsonVisitor.cpp +0 -161
  226. data/ext/libgraphqlparser/JsonVisitor.h +0 -121
  227. data/ext/libgraphqlparser/LICENSE +0 -22
  228. data/ext/libgraphqlparser/README.clang-tidy +0 -7
  229. data/ext/libgraphqlparser/README.md +0 -84
  230. data/ext/libgraphqlparser/ast/ast.ast +0 -203
  231. data/ext/libgraphqlparser/ast/ast.py +0 -61
  232. data/ext/libgraphqlparser/ast/c.py +0 -100
  233. data/ext/libgraphqlparser/ast/c.pyc +0 -0
  234. data/ext/libgraphqlparser/ast/c_impl.py +0 -61
  235. data/ext/libgraphqlparser/ast/c_impl.pyc +0 -0
  236. data/ext/libgraphqlparser/ast/c_visitor_impl.py +0 -39
  237. data/ext/libgraphqlparser/ast/c_visitor_impl.pyc +0 -0
  238. data/ext/libgraphqlparser/ast/casing.py +0 -26
  239. data/ext/libgraphqlparser/ast/casing.pyc +0 -0
  240. data/ext/libgraphqlparser/ast/cxx.py +0 -197
  241. data/ext/libgraphqlparser/ast/cxx.pyc +0 -0
  242. data/ext/libgraphqlparser/ast/cxx_impl.py +0 -61
  243. data/ext/libgraphqlparser/ast/cxx_impl.pyc +0 -0
  244. data/ext/libgraphqlparser/ast/cxx_json_visitor_header.py +0 -42
  245. data/ext/libgraphqlparser/ast/cxx_json_visitor_header.pyc +0 -0
  246. data/ext/libgraphqlparser/ast/cxx_json_visitor_impl.py +0 -80
  247. data/ext/libgraphqlparser/ast/cxx_json_visitor_impl.pyc +0 -0
  248. data/ext/libgraphqlparser/ast/cxx_visitor.py +0 -64
  249. data/ext/libgraphqlparser/ast/cxx_visitor.pyc +0 -0
  250. data/ext/libgraphqlparser/ast/js.py +0 -65
  251. data/ext/libgraphqlparser/ast/license.py +0 -10
  252. data/ext/libgraphqlparser/ast/license.pyc +0 -0
  253. data/ext/libgraphqlparser/c/GraphQLAstNode.cpp +0 -25
  254. data/ext/libgraphqlparser/c/GraphQLAstNode.h +0 -33
  255. data/ext/libgraphqlparser/c/GraphQLAstToJSON.cpp +0 -21
  256. data/ext/libgraphqlparser/c/GraphQLAstToJSON.h +0 -24
  257. data/ext/libgraphqlparser/c/GraphQLAstVisitor.cpp +0 -55
  258. data/ext/libgraphqlparser/c/GraphQLAstVisitor.h +0 -53
  259. data/ext/libgraphqlparser/c/GraphQLParser.cpp +0 -35
  260. data/ext/libgraphqlparser/c/GraphQLParser.h +0 -54
  261. data/ext/libgraphqlparser/clang-tidy-all.sh +0 -3
  262. data/ext/libgraphqlparser/cmake/version.cmake +0 -16
  263. data/ext/libgraphqlparser/dump_json_ast.cpp +0 -48
  264. data/ext/libgraphqlparser/go/README.md +0 -20
  265. data/ext/libgraphqlparser/go/callbacks.go +0 -18
  266. data/ext/libgraphqlparser/go/gotest.go +0 -64
  267. data/ext/libgraphqlparser/lexer.lpp +0 -324
  268. data/ext/libgraphqlparser/libgraphqlparser.pc.in +0 -11
  269. data/ext/libgraphqlparser/parser.ypp +0 -693
  270. data/ext/libgraphqlparser/parsergen/lexer.cpp +0 -2633
  271. data/ext/libgraphqlparser/parsergen/lexer.h +0 -528
  272. data/ext/libgraphqlparser/parsergen/location.hh +0 -189
  273. data/ext/libgraphqlparser/parsergen/parser.tab.cpp +0 -3300
  274. data/ext/libgraphqlparser/parsergen/parser.tab.hpp +0 -646
  275. data/ext/libgraphqlparser/parsergen/position.hh +0 -179
  276. data/ext/libgraphqlparser/parsergen/stack.hh +0 -156
  277. data/ext/libgraphqlparser/python/CMakeLists.txt +0 -14
  278. data/ext/libgraphqlparser/python/README.md +0 -5
  279. data/ext/libgraphqlparser/python/example.py +0 -31
  280. data/ext/libgraphqlparser/syntaxdefs.h +0 -19
  281. data/ext/libgraphqlparser/test/BuildCAPI.c +0 -5
  282. data/ext/libgraphqlparser/test/CMakeLists.txt +0 -25
  283. data/ext/libgraphqlparser/test/JsonVisitorTests.cpp +0 -28
  284. data/ext/libgraphqlparser/test/ParserTests.cpp +0 -352
  285. data/ext/libgraphqlparser/test/kitchen-sink.graphql +0 -59
  286. data/ext/libgraphqlparser/test/kitchen-sink.json +0 -1
  287. data/ext/libgraphqlparser/test/schema-kitchen-sink.graphql +0 -78
  288. data/ext/libgraphqlparser/test/schema-kitchen-sink.json +0 -1
  289. data/ext/libgraphqlparser/test/valgrind.supp +0 -33
  290. data/ext/version.cpp +0 -21
  291. data/lib/graphqlparser.so +0 -0
  292. data/lib/rails/graphql/native/functions.rb +0 -38
  293. data/lib/rails/graphql/native/location.rb +0 -41
  294. data/lib/rails/graphql/native/pointers.rb +0 -23
  295. data/lib/rails/graphql/native/visitor.rb +0 -349
  296. data/lib/rails/graphql/native.rb +0 -56
  297. 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,15 +69,10 @@ 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
@@ -170,7 +148,7 @@ class GraphQL_TypeMapTest < GraphQL::TestCase
170
148
  subject.stub(:fetch, passallthrough) do
171
149
  xargs = { base_class: object1, namespaces: :base, exclusive: true }
172
150
  assert_equal([:string, xargs], added[1][-1].call)
173
- assert_equal(object1, added[0][-1].call)
151
+ assert_equal(object1, added[0][-1])
174
152
  end
175
153
 
176
154
  assert_equal(1, subject.instance_variable_get(:@objects))
@@ -212,7 +190,7 @@ class GraphQL_TypeMapTest < GraphQL::TestCase
212
190
  assert_equal([:base, :Type, :a], added[0][0..-2])
213
191
 
214
192
  subject.stub(:fetch, passallthrough) do
215
- xargs = { base_class: :Type, namespaces: [:base], exclusive: true }
193
+ xargs = { base_class: :Type, namespaces: [:base].to_set, exclusive: true }
216
194
  assert_equal([:string, xargs], added[0][-1].call)
217
195
  end
218
196
 
@@ -229,13 +207,15 @@ class GraphQL_TypeMapTest < GraphQL::TestCase
229
207
 
230
208
  def test_each_from
231
209
  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)
210
+ Integer.stub_imethod(:gql_name, -> { to_s }) do
211
+ subject.stub_ivar(:@index, SAMPLE_INDEX) do
212
+ items = [1, 4]
213
+ subject.each_from(:base) { |x| assert_equal(items.shift, x) }
214
+
215
+ assert_equal([2, 3, 1, 4], subject.each_from(:other).entries)
216
+ assert_equal([2, 3], subject.each_from(:other, exclusive: true).entries)
217
+ assert_equal([], subject.each_from(:other, base_class: :Other).entries)
218
+ end
239
219
  end
240
220
  end
241
221
  end
@@ -243,7 +223,7 @@ class GraphQL_TypeMapTest < GraphQL::TestCase
243
223
  def test_after_register
244
224
  subject.stub(:fetch, passallthrough) do
245
225
  result = subject.after_register(:a, &passthrough)
246
- xargs = { prevent_register: true, base_class: :Type, namespaces: :base }
226
+ xargs = { prevent_register: true, base_class: :Type }
247
227
  assert_equal([:a, xargs], result)
248
228
  end
249
229
 
@@ -268,15 +248,20 @@ class GraphQL_TypeMapTest < GraphQL::TestCase
268
248
  [:other, :Type],
269
249
  [:other, :Type],
270
250
  ].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))
251
+ assert_nil(register[:a][3 - idx].call(:x, bc, :non_called))
252
+ assert_nil(register[:a][3 - idx].call(ns, :y, :non_called))
253
+ assert(register[:a][3 - idx].call(ns, bc, :called))
274
254
  end
275
255
  end
276
256
 
277
257
  def test_inspect
278
- assert_equal(<<~INFO.chomp, subject.inspect)
279
- #<Rails::GraphQL::TypeMap [index] @namespaces=0 @base_classes=3 @objects=0 @pending=0>
258
+ assert_equal(<<~INFO.squish, subject.inspect)
259
+ #<Rails::GraphQL::TypeMap [index]
260
+ @namespaces=0
261
+ @base_classes=3
262
+ @objects=0
263
+ @pending=0
264
+ @dependencies={base: 14}>
280
265
  INFO
281
266
  end
282
267
 
@@ -320,11 +305,11 @@ class GraphQL_TypeMapTest < GraphQL::TestCase
320
305
 
321
306
  def test_register_pending_bang
322
307
  registered = false
323
- object = double(register!: -> { -> { registered = true } }, registered?: false)
308
+ object = double(register!: -> { registered = true }, registered?: false)
324
309
  skipped = double(registered?: false)
325
310
  other = double(registered?: true)
326
311
 
327
- subject.stub(:skip_register, [skipped]) do
312
+ subject.stub(:skip_register, [[skipped].to_set]) do
328
313
  subject.stub_ivar(:@pending, [[skipped, :a], [object, :b], [other, :c]]) do
329
314
  subject.send(:register_pending!)
330
315
  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 = GraphQL::HumanObject[:name]
39
+ assert_gid_value('gql://start-wars-mem/HumanObject/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/HumanObject/name')
88
+ assert_equal(GraphQL::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