rails-graphql 0.2.0 → 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 +10 -8
  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 +50 -36
  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 +257 -165
  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
@@ -1,16 +1,18 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- module Rails # :nodoc:
4
- module GraphQL # :nodoc:
5
- module Collectors # :nodoc:
3
+ module Rails
4
+ module GraphQL
5
+ module Collectors
6
+ # = GraphQL JSON Collector
7
+ #
6
8
  # This collector helps building a JSON response using the string approach,
7
9
  # which has better performance, since all the encoding is performed up
8
- # front. The drawback is that it can't return an hash.
10
+ # front. The drawback is that it can't return a hash.
9
11
  class JsonCollector
10
12
  def initialize(request)
11
13
  @request = request
12
14
 
13
- @current_value = String.new
15
+ @current_value = StringIO.new
14
16
  @stack_value = []
15
17
 
16
18
  @current_array = false
@@ -33,7 +35,7 @@ module Rails # :nodoc:
33
35
  raise
34
36
  end
35
37
 
36
- # Append to the responsa data all the errors that happened during the
38
+ # Append to the response data all the errors that happened during the
37
39
  # request process.
38
40
  def append_errors(errors)
39
41
  return if errors.empty?
@@ -43,15 +45,12 @@ module Rails # :nodoc:
43
45
  # Add the given +value+ to the given +key+. Ensure to encode the value
44
46
  # before calling this function.
45
47
  def add(key, value)
46
- (@current_value << ',') unless @current_value.blank?
48
+ (@current_value << ',') if @current_value.pos > 0
47
49
 
48
50
  if @current_array
49
51
  @current_value << value
50
52
  else
51
- @current_value << '"'
52
- @current_value << key.to_s
53
- @current_value << '":'
54
- @current_value << value.to_s
53
+ @current_value << '"' << +key.to_s << '"' << ':' << +value.to_s
55
54
  end
56
55
  end
57
56
 
@@ -68,31 +67,37 @@ module Rails # :nodoc:
68
67
  # Mark the start of a new element on the array.
69
68
  def next
70
69
  return unless @stack_array.last === :complex
71
- (@stack_value.last << ',') unless @stack_value.last.blank?
70
+ (@stack_value.last << ',') if @stack_value.last.pos > 0
72
71
  @stack_value.last << to_s
73
- @current_value = String.new
72
+ @current_value = StringIO.new
74
73
  end
75
74
 
76
75
  # Get the current result
77
76
  def to_s
78
- @current_array ? "[#{@current_value}]" : "{#{@current_value}}"
77
+ if @current_array
78
+ +'[' << @current_value.string << ']'
79
+ else
80
+ +'{' << @current_value.string << '}'
81
+ end
79
82
  end
80
83
 
84
+ alias to_json to_s
85
+
81
86
  private
82
87
 
83
88
  # Start a new part of the collector. When set +as_array+, the result
84
- # of the stack will be encolsed by +[]+.
89
+ # of the stack will be enclosed by +[]+.
85
90
  def start_stack(as_array = false, plain_array = false)
86
91
  @stack_value << @current_value
87
92
  @stack_array << @current_array
88
93
 
89
94
  if as_array && !plain_array
90
- @stack_value << String.new
95
+ @stack_value << StringIO.new
91
96
  @stack_array << :complex
92
97
  as_array = false
93
98
  end
94
99
 
95
- @current_value = String.new
100
+ @current_value = StringIO.new
96
101
  @current_array = as_array
97
102
  end
98
103
 
@@ -1,14 +1,14 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- module Rails # :nodoc:
4
- module GraphQL # :nodoc:
5
- module Collectors # :nodoc:
3
+ module Rails
4
+ module GraphQL
5
+ # All the possible collectors that uses the reverse visit approach
6
+ module Collectors
6
7
  extend ActiveSupport::Autoload
7
8
 
8
9
  autoload :HashCollector
9
10
  autoload :IdentedCollector
10
11
  autoload :JsonCollector
11
-
12
12
  end
13
13
  end
14
14
  end
@@ -1,61 +1,176 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- module Rails # :nodoc:
4
- module GraphQL # :nodoc:
3
+ module Rails
4
+ module GraphQL
5
5
  configure do |config|
6
- # This exposes the clean path from where a GraphQL request was started
6
+ # This helps to keep track of when things were cached and registered.
7
+ # Cached objects with mismatching versions needs to be upgraded or simply
8
+ # reloaded. A good way to use this is to set to the commit hash, but
9
+ # beware to stick to 8 characters.
10
+ config.version = nil
11
+
12
+ # This will be automatically mapped to +Rails.cache+. Manually setting
13
+ # this property means that the object in it complies with
14
+ # +ActiveSupport::Cache::Store+.
15
+ config.cache = nil
16
+
17
+ # If Rails cache is not properly defined, by default it is set to a
18
+ # NullStore, than fallback to this option to get a memory store because
19
+ # cache is extremely important, especially for subscriptions
20
+ config.cache_fallback = -> do
21
+ ::ActiveSupport::Cache::MemoryStore.new(max_prune_time: nil)
22
+ end
23
+
24
+ # This is the prefix key of all the cache entries for the GraphQL cached
25
+ # things.
26
+ config.cache_prefix = 'graphql/'
27
+
28
+ # The list of nested paths inside of the graphql folder that does not
29
+ # require to be in their own namespace.
30
+ config.paths = %w[directives fields sources enums inputs interfaces object
31
+ scalars unions].to_set
32
+
33
+ # This exposes the clean path from where a GraphQL request was started.
7
34
  config.verbose_logs = true
8
35
 
36
+ # The list of parameters to omit from logger when running a GraphQL
37
+ # request. Those values will be better displayed in the internal runtime
38
+ # logger controller.
39
+ config.omit_parameters = %w[query operationName operation_name variables graphql]
40
+
41
+ # This list will actually affect what is displayed in the logs. When it is
42
+ # set to nil, it will copy its value from Rails +filter_parameters+.
43
+ config.filter_parameters = nil
44
+
9
45
  # A list of ActiveRecord adapters and their specific internal naming used
10
- # to compound the accessors for direct query serialization
46
+ # to compound the accessors for direct query serialization.
11
47
  config.ar_adapters = {
12
- 'Mysql2' => :mysql,
13
- 'PostgreSQL' => :pg,
14
- 'SQLite' => :sqlite,
48
+ 'Mysql2' => { key: :mysql, path: "#{__dir__}/adapters/mysql_adapter" },
49
+ 'PostgreSQL' => { key: :pg, path: "#{__dir__}/adapters/pg_adapter" },
50
+ 'SQLite' => { key: :sqlite, path: "#{__dir__}/adapters/sqlite_adapter" },
15
51
  }
16
52
 
17
53
  # For all the input object type defined, auto add the following prefix to
18
54
  # their name, so we don't have to define classes like +PointInputInput+.
19
55
  config.auto_suffix_input_objects = 'Input'
20
56
 
57
+ # Introspection is enabled by default. Changing this will affect all the
58
+ # schemas off the application and reduce memory usage. This can also be
59
+ # set at per schema.
60
+ config.enable_introspection = true
61
+
62
+ # Define the names of the schema/operations types. The single "_" is a
63
+ # suggestion so that in an application that has, most likely, a
64
+ # Subscription type, it does not generate a conflict. Plus, it is easy to
65
+ # spot that it is something internal.
66
+ config.schema_type_names = {
67
+ query: '_Query',
68
+ mutation: '_Mutation',
69
+ subscription: '_Subscription',
70
+ }
71
+
21
72
  # For performance purposes, this gem implements a
22
73
  # {JsonCollector}[rdoc-ref:Rails::GraphQL::Collectors::JsonCollector].
23
74
  # If you prefer to use the normal hash to string serialization, you can
24
75
  # disable this option.
25
76
  config.enable_string_collector = true
26
77
 
78
+ # Set what is de default expected output type of GraphQL requests. String
79
+ # combined with the previous setting has the best performance. On console,
80
+ # it will automatically shift to hash.
81
+ config.default_response_format = :string
82
+
27
83
  # Specifies if the results of operations should be encoded with
28
84
  # +ActiveSupport::JSON#encode+ instead of the default +JSON#generate+.
29
85
  # See also https://github.com/rails/rails/blob/master/activesupport/lib/active_support/json/encoding.rb
30
86
  config.encode_with_active_support = false
31
87
 
32
- # Enable the ability of a callback to dynamically inject argumnets to the
88
+ # Enable the ability of a callback to dynamically inject arguments to the
33
89
  # calling method.
34
90
  config.callback_inject_arguments = true
35
91
 
36
- # Enable the ability of a callback to dynamically inject named argumnets
92
+ # Enable the ability of a callback to dynamically inject named arguments
37
93
  # to the calling method.
38
94
  config.callback_inject_named_arguments = true
39
95
 
96
+ # When importing fields into other places, if the given class is
97
+ # incompatible it will display an warning. This can make such warning be
98
+ # silenced.
99
+ config.silence_import_warnings = false
100
+
101
+ # Enable the ability to active custom descriptions using i18n
102
+ config.enable_i18n_descriptions = true
103
+
104
+ # Specify the scopes for I18n translations
105
+ config.i18n_scopes = [
106
+ 'graphql.%{namespace}.%{kind}.%{parent}.%{name}',
107
+ 'graphql.%{namespace}.%{kind}.%{name}',
108
+ 'graphql.%{namespace}.%{name}',
109
+ 'graphql.%{kind}.%{parent}.%{name}',
110
+ 'graphql.%{kind}.%{name}',
111
+ 'graphql.%{name}'
112
+ ]
113
+
40
114
  # A list of execution strategies. Each application can add their own by
41
115
  # simply append a class name, preferable as string, in this list.
42
116
  config.request_strategies = [
43
117
  'Rails::GraphQL::Request::Strategy::MultiQueryStrategy',
44
118
  'Rails::GraphQL::Request::Strategy::SequencedStrategy',
119
+ # 'Rails::GraphQL::Request::Strategy::CachedStrategy',
120
+ ]
121
+
122
+ # A list of all possible rails-graphql-compatible sources.
123
+ config.sources = [
124
+ 'Rails::GraphQL::Source::ActiveRecordSource',
125
+ ]
126
+
127
+ # A list of all available subscription providers which bases on
128
+ # Rails::GraphQL::SubscriptionProvider::Base
129
+ config.subscription_providers = [
130
+ 'Rails::GraphQL::Subscription::Provider::ActionCable',
45
131
  ]
46
132
 
133
+ # The default subscription provider for all the schemas
134
+ config.default_subscription_provider = config.subscription_providers.first
135
+
136
+ # The default value for fields about their ability of being broadcasted
137
+ config.default_subscription_broadcastable = nil
138
+
139
+ # A list of known dependencies that can be requested and included in any
140
+ # schema. This is the best place for other gems to add their own
141
+ # dependencies and allow users to pick them.
142
+ config.known_dependencies = {
143
+ scalar: {
144
+ any: "#{__dir__}/type/scalar/any_scalar",
145
+ bigint: "#{__dir__}/type/scalar/bigint_scalar",
146
+ binary: "#{__dir__}/type/scalar/binary_scalar",
147
+ date_time: "#{__dir__}/type/scalar/date_time_scalar",
148
+ date: "#{__dir__}/type/scalar/date_scalar",
149
+ decimal: "#{__dir__}/type/scalar/decimal_scalar",
150
+ time: "#{__dir__}/type/scalar/time_scalar",
151
+ json: "#{__dir__}/type/scalar/json_scalar",
152
+ },
153
+ directive: {
154
+ # cached: "#{__dir__}/directive/cached_directive",
155
+ },
156
+ }
157
+
158
+ # The method that should be used to parse literal input values when they
159
+ # are provided as hash. +JSON.parse+ only supports keys wrapped in quotes,
160
+ # to support keys without quotes, you can use +Psych.method(:safe_load)+,
161
+ # which behaves closer to YAML, but the received value is ensure to be
162
+ # wrapped in "{}". If that produces unexpected results, you can assign a
163
+ # proc and then parse the value in any other way, like
164
+ # +->(value) { anything }+
165
+ config.literal_input_parser = JSON.method(:parse)
166
+
47
167
  # TODO: To be implemented
48
- # enable_i18n_descriptions
49
- # enable_auto_descriptions
50
168
  # allow_query_serialization
51
- # source_generate_dependencies
52
169
  end
53
170
 
54
171
  # This is the logger for all the operations for GraphQL
55
172
  def self.logger
56
- config.logger ||= ActiveSupport::TaggedLogging.new(
57
- ActiveSupport::Logger.new(STDOUT),
58
- )
173
+ config.logger ||= ActiveSupport::TaggedLogging.new(ActiveSupport::Logger.new(STDOUT))
59
174
  end
60
175
  end
61
176
  end
@@ -0,0 +1,33 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Rails
4
+ module GraphQL
5
+ # = GraphQL Cached Directive
6
+ #
7
+ # Indicates that the request has hard cached operations that need to be
8
+ # collected
9
+ class Directive::CachedDirective < Directive
10
+ placed_on :query
11
+
12
+ desc 'Indicates that there are hard cached operations.'
13
+
14
+ argument :id, :ID, null: false, desc: <<~DESC
15
+ The unique identifier of the cached operation.
16
+ DESC
17
+
18
+ on(:attach) do |source, request|
19
+ source.data.selection = nil
20
+ # TODO: Add the request name back
21
+ # source.instance_variable_set(:@name, 'here')
22
+
23
+ # TODO: Add the arguments and variables
24
+ field = request.build(Request::Component::Field, source, nil, { name: 'a', alias: 'b' })
25
+ field.assing_to(ApplicationSchema[:query][:a])
26
+ field.check_authorization!
27
+
28
+ source.instance_variable_set(:@selection, { 'b' => field })
29
+ # puts source.inspect
30
+ end
31
+ end
32
+ end
33
+ end
@@ -1,7 +1,7 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- module Rails # :nodoc:
4
- module GraphQL # :nodoc:
3
+ module Rails
4
+ module GraphQL
5
5
  # = GraphQL Spec Deprecated Directive
6
6
  #
7
7
  # Mark fields or enum values as deprecated which will include an error
@@ -12,7 +12,7 @@ module Rails # :nodoc:
12
12
  placed_on :field_definition, :enum_value
13
13
 
14
14
  desc <<~DESC
15
- Indicate deprecated portions of a GraphQL services schema, such as deprecated
15
+ Indicate deprecated portions of a GraphQL service's schema, such as deprecated
16
16
  fields on a type or deprecated enum values.
17
17
  DESC
18
18
 
@@ -22,11 +22,11 @@ module Rails # :nodoc:
22
22
  using Markdown syntax (as specified by [CommonMark](http://commonmark.org/)).
23
23
  DESC
24
24
 
25
- on :organized do |event|
25
+ on(:organized) do |event|
26
26
  report_for_field(event)
27
27
  end
28
28
 
29
- on :finalize, for: Type::Enum do |event|
29
+ on(:finalize, for: Type::Enum) do |event|
30
30
  report_for_enum_value(event)
31
31
  end
32
32
 
@@ -35,7 +35,7 @@ module Rails # :nodoc:
35
35
  # Check if the requested field is marked as deprecated
36
36
  def report_for_field(event)
37
37
  return unless event.field.using?(self.class)
38
- item = "#{event.source.gql_name} field"
38
+ item = +"#{event.source.gql_name} field"
39
39
  event.request.report_error(build_message(item))
40
40
  end
41
41
 
@@ -44,15 +44,15 @@ module Rails # :nodoc:
44
44
  return unless event.current_value.deprecated?
45
45
 
46
46
  value = event.current_value.to_s
47
- item = "#{value} value for the #{event.source.gql_name} field"
47
+ item = +"#{value} value for the #{event.source.gql_name} field"
48
48
  event.request.report_error(build_message(item))
49
49
  end
50
50
 
51
51
  # Build the error message to display on the result
52
52
  def build_message(item)
53
- result = "The #{item} is deprecated"
54
- result += ", reason: #{args.reason}" if args.reason.present?
55
- result + '.'
53
+ result = +"The #{item} is deprecated"
54
+ result << ", reason: #{args.reason}" if args.reason.present?
55
+ result << '.'
56
56
  end
57
57
  end
58
58
  end
@@ -1,7 +1,7 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- module Rails # :nodoc:
4
- module GraphQL # :nodoc:
3
+ module Rails
4
+ module GraphQL
5
5
  # = GraphQL Spec Include Directive
6
6
  #
7
7
  # Allow including fields only +if+ condition is true
@@ -16,8 +16,9 @@ module Rails # :nodoc:
16
16
  When false, the underlying element will be automatically marked as null.
17
17
  DESC
18
18
 
19
- on :attach do |source|
20
- source.invalidate! unless args[:if]
19
+ # TODO: On attach does not covers default value per operation variable scenario
20
+ on(:attach) do |source|
21
+ source.skip! unless args[:if]
21
22
  end
22
23
  end
23
24
  end
@@ -1,7 +1,7 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- module Rails # :nodoc:
4
- module GraphQL # :nodoc:
3
+ module Rails
4
+ module GraphQL
5
5
  # = GraphQL Spec Skip Directive
6
6
  #
7
7
  # Allow skipping fields given an +if+ condition
@@ -16,8 +16,9 @@ module Rails # :nodoc:
16
16
  When true, the underlying element will be automatically marked as null.
17
17
  DESC
18
18
 
19
- on :attach do |source|
20
- source.invalidate! if args[:if]
19
+ # TODO: On attach does not covers default value per operation variable scenario
20
+ on(:attach) do |source|
21
+ source.skip! if args[:if]
21
22
  end
22
23
  end
23
24
  end