graphql 1.7.6 → 1.8.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (289) hide show
  1. checksums.yaml +4 -4
  2. data/lib/generators/graphql/function_generator.rb +1 -1
  3. data/lib/generators/graphql/install_generator.rb +14 -8
  4. data/lib/generators/graphql/loader_generator.rb +1 -1
  5. data/lib/generators/graphql/mutation_generator.rb +6 -1
  6. data/lib/generators/graphql/templates/function.erb +2 -2
  7. data/lib/generators/graphql/templates/loader.erb +2 -2
  8. data/lib/generators/graphql/templates/schema.erb +1 -1
  9. data/lib/graphql/argument.rb +25 -19
  10. data/lib/graphql/backtrace/tracer.rb +16 -22
  11. data/lib/graphql/backtrace.rb +1 -1
  12. data/lib/graphql/backwards_compatibility.rb +2 -3
  13. data/lib/graphql/base_type.rb +31 -31
  14. data/lib/graphql/compatibility/query_parser_specification/parse_error_specification.rb +14 -0
  15. data/lib/graphql/compatibility/query_parser_specification.rb +117 -0
  16. data/lib/graphql/define/assign_object_field.rb +5 -12
  17. data/lib/graphql/deprecated_dsl.rb +42 -0
  18. data/lib/graphql/directive.rb +1 -0
  19. data/lib/graphql/enum_type.rb +3 -1
  20. data/lib/graphql/execution/execute.rb +21 -13
  21. data/lib/graphql/execution/instrumentation.rb +82 -0
  22. data/lib/graphql/execution/lazy/lazy_method_map.rb +1 -1
  23. data/lib/graphql/execution/lazy/resolve.rb +1 -3
  24. data/lib/graphql/execution/multiplex.rb +12 -29
  25. data/lib/graphql/execution.rb +1 -0
  26. data/lib/graphql/field.rb +21 -4
  27. data/lib/graphql/function.rb +14 -0
  28. data/lib/graphql/input_object_type.rb +3 -1
  29. data/lib/graphql/interface_type.rb +5 -3
  30. data/lib/graphql/internal_representation/node.rb +26 -14
  31. data/lib/graphql/internal_representation/visit.rb +3 -6
  32. data/lib/graphql/introspection/base_object.rb +16 -0
  33. data/lib/graphql/introspection/directive_location_enum.rb +11 -7
  34. data/lib/graphql/introspection/directive_type.rb +23 -16
  35. data/lib/graphql/introspection/dynamic_fields.rb +11 -0
  36. data/lib/graphql/introspection/entry_points.rb +29 -0
  37. data/lib/graphql/introspection/enum_value_type.rb +16 -11
  38. data/lib/graphql/introspection/field_type.rb +21 -12
  39. data/lib/graphql/introspection/input_value_type.rb +26 -23
  40. data/lib/graphql/introspection/schema_field.rb +7 -2
  41. data/lib/graphql/introspection/schema_type.rb +36 -22
  42. data/lib/graphql/introspection/type_by_name_field.rb +10 -2
  43. data/lib/graphql/introspection/type_kind_enum.rb +10 -6
  44. data/lib/graphql/introspection/type_type.rb +85 -23
  45. data/lib/graphql/introspection/typename_field.rb +1 -0
  46. data/lib/graphql/introspection.rb +3 -10
  47. data/lib/graphql/language/block_string.rb +47 -0
  48. data/lib/graphql/language/document_from_schema_definition.rb +280 -0
  49. data/lib/graphql/language/generation.rb +3 -182
  50. data/lib/graphql/language/lexer.rb +144 -69
  51. data/lib/graphql/language/lexer.rl +15 -4
  52. data/lib/graphql/language/nodes.rb +141 -78
  53. data/lib/graphql/language/parser.rb +677 -630
  54. data/lib/graphql/language/parser.y +18 -12
  55. data/lib/graphql/language/printer.rb +361 -0
  56. data/lib/graphql/language/token.rb +10 -3
  57. data/lib/graphql/language.rb +3 -0
  58. data/lib/graphql/non_null_type.rb +1 -1
  59. data/lib/graphql/object_type.rb +1 -6
  60. data/lib/graphql/query/arguments.rb +63 -32
  61. data/lib/graphql/query/context.rb +32 -2
  62. data/lib/graphql/query/literal_input.rb +4 -1
  63. data/lib/graphql/query/null_context.rb +1 -1
  64. data/lib/graphql/query/result.rb +1 -1
  65. data/lib/graphql/query/variables.rb +21 -3
  66. data/lib/graphql/query.rb +19 -6
  67. data/lib/graphql/railtie.rb +109 -0
  68. data/lib/graphql/relay/connection_resolve.rb +3 -0
  69. data/lib/graphql/relay/connection_type.rb +5 -3
  70. data/lib/graphql/relay/edge_type.rb +2 -1
  71. data/lib/graphql/relay/global_id_resolve.rb +5 -1
  72. data/lib/graphql/relay/mongo_relation_connection.rb +40 -0
  73. data/lib/graphql/relay/mutation/instrumentation.rb +1 -1
  74. data/lib/graphql/relay/mutation/resolve.rb +5 -1
  75. data/lib/graphql/relay/relation_connection.rb +14 -19
  76. data/lib/graphql/relay/type_extensions.rb +30 -0
  77. data/lib/graphql/relay.rb +2 -0
  78. data/lib/graphql/scalar_type.rb +14 -2
  79. data/lib/graphql/schema/argument.rb +92 -0
  80. data/lib/graphql/schema/build_from_definition.rb +64 -18
  81. data/lib/graphql/schema/enum.rb +85 -0
  82. data/lib/graphql/schema/enum_value.rb +74 -0
  83. data/lib/graphql/schema/field.rb +372 -0
  84. data/lib/graphql/schema/finder.rb +153 -0
  85. data/lib/graphql/schema/input_object.rb +87 -0
  86. data/lib/graphql/schema/interface.rb +105 -0
  87. data/lib/graphql/schema/introspection_system.rb +93 -0
  88. data/lib/graphql/schema/late_bound_type.rb +32 -0
  89. data/lib/graphql/schema/list.rb +32 -0
  90. data/lib/graphql/schema/loader.rb +2 -2
  91. data/lib/graphql/schema/member/accepts_definition.rb +152 -0
  92. data/lib/graphql/schema/member/base_dsl_methods.rb +100 -0
  93. data/lib/graphql/schema/member/build_type.rb +137 -0
  94. data/lib/graphql/schema/member/cached_graphql_definition.rb +26 -0
  95. data/lib/graphql/schema/member/graphql_type_names.rb +21 -0
  96. data/lib/graphql/schema/member/has_arguments.rb +50 -0
  97. data/lib/graphql/schema/member/has_fields.rb +130 -0
  98. data/lib/graphql/schema/member/instrumentation.rb +115 -0
  99. data/lib/graphql/schema/member/type_system_helpers.rb +34 -0
  100. data/lib/graphql/schema/member.rb +28 -0
  101. data/lib/graphql/schema/middleware_chain.rb +5 -1
  102. data/lib/graphql/schema/mutation.rb +138 -0
  103. data/lib/graphql/schema/non_null.rb +38 -0
  104. data/lib/graphql/schema/object.rb +81 -0
  105. data/lib/graphql/schema/printer.rb +33 -266
  106. data/lib/graphql/schema/relay_classic_mutation.rb +87 -0
  107. data/lib/graphql/schema/rescue_middleware.rb +8 -7
  108. data/lib/graphql/schema/resolver.rb +122 -0
  109. data/lib/graphql/schema/scalar.rb +35 -0
  110. data/lib/graphql/schema/traversal.rb +102 -22
  111. data/lib/graphql/schema/union.rb +36 -0
  112. data/lib/graphql/schema/validation.rb +3 -2
  113. data/lib/graphql/schema.rb +381 -12
  114. data/lib/graphql/static_validation/definition_dependencies.rb +1 -1
  115. data/lib/graphql/static_validation/literal_validator.rb +16 -4
  116. data/lib/graphql/static_validation/rules/fields_are_defined_on_type.rb +6 -6
  117. data/lib/graphql/static_validation/rules/fields_have_appropriate_selections.rb +5 -1
  118. data/lib/graphql/static_validation/rules/fields_will_merge.rb +15 -8
  119. data/lib/graphql/static_validation/rules/variables_are_used_and_defined.rb +11 -1
  120. data/lib/graphql/static_validation/validation_context.rb +1 -1
  121. data/lib/graphql/subscriptions/action_cable_subscriptions.rb +7 -5
  122. data/lib/graphql/subscriptions/instrumentation.rb +5 -1
  123. data/lib/graphql/subscriptions/serialize.rb +2 -0
  124. data/lib/graphql/subscriptions.rb +90 -16
  125. data/lib/graphql/tracing/data_dog_tracing.rb +49 -0
  126. data/lib/graphql/tracing/new_relic_tracing.rb +26 -0
  127. data/lib/graphql/tracing/platform_tracing.rb +20 -7
  128. data/lib/graphql/tracing/scout_tracing.rb +2 -2
  129. data/lib/graphql/tracing.rb +1 -0
  130. data/lib/graphql/unresolved_type_error.rb +3 -2
  131. data/lib/graphql/upgrader/member.rb +894 -0
  132. data/lib/graphql/upgrader/schema.rb +37 -0
  133. data/lib/graphql/version.rb +1 -1
  134. data/lib/graphql.rb +5 -25
  135. data/readme.md +2 -2
  136. data/spec/dummy/app/channels/graphql_channel.rb +23 -2
  137. data/spec/dummy/log/development.log +239 -0
  138. data/spec/dummy/log/test.log +410 -0
  139. data/spec/dummy/test/system/action_cable_subscription_test.rb +4 -0
  140. data/spec/dummy/tmp/cache/assets/sprockets/v3.0/-x/-xYZjAnuuzgR79fcznLTQtSdh6AARxu8FcQ_J6p7L3U.cache +0 -0
  141. data/spec/dummy/tmp/cache/assets/sprockets/v3.0/13/13HiV12xyoQvT-1L39ZzLwMZxjyaGMiENmfw7f-QTIc.cache +0 -0
  142. data/spec/dummy/tmp/cache/assets/sprockets/v3.0/3W/3Wtf5pCWdqq0AB-iB0Y9uUNrTkruRxIEf1XFn_BETU0.cache +1 -0
  143. data/spec/dummy/tmp/cache/assets/sprockets/v3.0/5i/5iguGafb4hOn8262Kn8Q37ogNN9MxxQKGKNzHAzUcvI.cache +1 -0
  144. data/spec/dummy/tmp/cache/assets/sprockets/v3.0/8m/8mj2T6yy847Mc2Z7k3Xzh8O91hhVJt3NrPe8ASNDlIA.cache +1 -0
  145. data/spec/dummy/tmp/cache/assets/sprockets/v3.0/DT/DTQyMpr4ABZYQetsdRJ5A7S4jf1r3ie4FGOR7GZBNSs.cache +3 -0
  146. data/spec/dummy/tmp/cache/assets/sprockets/v3.0/Dq/DqJ5_yJPrP5iLlOQyTQsjAVI5FE5LCVDkED0f7GgsSo.cache +3 -0
  147. data/spec/dummy/tmp/cache/assets/sprockets/v3.0/F8/F8MUNRzORGFgr329fNM0xLaoWCXdv3BIalT7dsvLfjs.cache +0 -0
  148. data/spec/dummy/tmp/cache/assets/sprockets/v3.0/KB/KB07ZaKNC5uXJ7TjLi-WqnY6g7dq8wWp_8N3HNjBNxg.cache +0 -0
  149. data/spec/dummy/tmp/cache/assets/sprockets/v3.0/Rw/RwDuCV-XpnCtjNkvhpJfBuxXMk0b5AD3L9eR6M-wcy0.cache +3 -0
  150. data/spec/dummy/tmp/cache/assets/sprockets/v3.0/UL/ULdjhhb0bRuqmaG7XSZlFYzGYCXTDnqZuJBTWRlzqgw.cache +0 -0
  151. data/spec/dummy/tmp/cache/assets/sprockets/v3.0/Up/UpPNgh0yYoUsyMDh5zWqe_U6qJIyTC6-dxMMAs1vvlM.cache +1 -0
  152. data/spec/dummy/tmp/cache/assets/sprockets/v3.0/Wg/Wguh-szFGTI1gaL6npYwPekMXflugRei7F_mOyRucXg.cache +0 -0
  153. data/spec/dummy/tmp/cache/assets/sprockets/v3.0/X-/X-khLYMA9mqFRPg3zAi86mREDxpKl4bdKYp3uF6WHos.cache +0 -0
  154. data/spec/dummy/tmp/cache/assets/sprockets/v3.0/bi/BIkdhfxsezxM4q-HZ4oCNTq97WEJTigcq0tpX2cDvbY.cache +0 -0
  155. data/spec/dummy/tmp/cache/assets/sprockets/v3.0/ff/FfxmA4CMHQZT7exx0G7NS1Wpcnny0vzp-Jhc2H36bp8.cache +1 -0
  156. data/spec/dummy/tmp/cache/assets/sprockets/v3.0/gE/gEiiG4GZNy_djEjK2pHm_NgA-gyhLZhdQvo0Yt96GqE.cache +0 -0
  157. data/spec/dummy/tmp/cache/assets/sprockets/v3.0/gn/gnA9ZSqpjccNL2m8pe_jBvY6SinXlCzXDWyop83Od8s.cache +1 -0
  158. data/spec/dummy/tmp/cache/assets/sprockets/v3.0/lO/lOAan3cMwCE_Hli6gsDML88xFNfn0nxPmvrSkW7eEOw.cache +1 -0
  159. data/spec/dummy/tmp/cache/assets/sprockets/v3.0/m1/M1pv8MJEPLXGLvS8QxVh3DSO9cI4mRt5FHFWdrvUj6o.cache +2 -0
  160. data/spec/dummy/tmp/cache/assets/sprockets/v3.0/m7/m77qH7ZqH0_0SmwJbiKGDd-aLau1Dav847DC6ge46zY.cache +1 -0
  161. data/spec/dummy/tmp/cache/assets/sprockets/v3.0/sj/sjRjnjRB37lH2vrgtkdJ8Cz84__IJ978IuKTM7HcztI.cache +0 -0
  162. data/spec/dummy/tmp/cache/assets/sprockets/v3.0/um/um1JrirR4hJhK-1rE-HywlyCi5ibgxHVrReiujZBWJM.cache +1 -0
  163. data/spec/dummy/tmp/cache/assets/sprockets/v3.0/v4/v4fwVytD7ITcE0_GDbslZEYud8a5Okm85fV1o7SDl6g.cache +0 -0
  164. data/spec/dummy/tmp/cache/assets/sprockets/v3.0/v_/v_0PAQt0iipQjFP5zjgkkk9Stnpf4VzvnMv67d1Keuw.cache +1 -0
  165. data/spec/dummy/tmp/cache/assets/sprockets/v3.0/wd/wdT9U4MKxe1PyqNjVuCKMpCl3dxGCIRJIlwUTfh2DQU.cache +1 -0
  166. data/spec/dummy/tmp/cache/assets/sprockets/v3.0/xI/xIaxut_fEIhKBDqljTNwYaADK9kj3gG0ESrfHs-5_og.cache +3 -0
  167. data/spec/dummy/tmp/cache/assets/sprockets/v3.0/y0/y0SJOqIx2fn1SKqOkAihsQow0trRJrSIyAswufVuoA8.cache +0 -0
  168. data/spec/dummy/tmp/cache/assets/sprockets/v3.0/zg/zgpzeaX-KZErHyGJ1aBH3ZusweNXMneVZule88XsIJI.cache +1 -0
  169. data/spec/dummy/tmp/cache/assets/sprockets/v3.0/zy/zYFltDy-8VC-uKq2BVEiJJyYXNFvVzAKuMlR3ZIYZsk.cache +0 -0
  170. data/spec/dummy/tmp/screenshots/failures_test_it_handles_subscriptions.png +0 -0
  171. data/spec/fixtures/upgrader/account.original.rb +19 -0
  172. data/spec/fixtures/upgrader/account.transformed.rb +20 -0
  173. data/spec/fixtures/upgrader/blame_range.original.rb +43 -0
  174. data/spec/fixtures/upgrader/blame_range.transformed.rb +30 -0
  175. data/spec/fixtures/upgrader/date_time.original.rb +24 -0
  176. data/spec/fixtures/upgrader/date_time.transformed.rb +23 -0
  177. data/spec/fixtures/upgrader/delete_project.original.rb +28 -0
  178. data/spec/fixtures/upgrader/delete_project.transformed.rb +27 -0
  179. data/spec/fixtures/upgrader/gist_order_field.original.rb +14 -0
  180. data/spec/fixtures/upgrader/gist_order_field.transformed.rb +13 -0
  181. data/spec/fixtures/upgrader/increment_count.original.rb +59 -0
  182. data/spec/fixtures/upgrader/increment_count.transformed.rb +50 -0
  183. data/spec/fixtures/upgrader/photo.original.rb +10 -0
  184. data/spec/fixtures/upgrader/photo.transformed.rb +12 -0
  185. data/spec/fixtures/upgrader/release_order.original.rb +15 -0
  186. data/spec/fixtures/upgrader/release_order.transformed.rb +14 -0
  187. data/spec/fixtures/upgrader/starrable.original.rb +49 -0
  188. data/spec/fixtures/upgrader/starrable.transformed.rb +46 -0
  189. data/spec/fixtures/upgrader/subscribable.original.rb +55 -0
  190. data/spec/fixtures/upgrader/subscribable.transformed.rb +51 -0
  191. data/spec/fixtures/upgrader/type_x.original.rb +65 -0
  192. data/spec/fixtures/upgrader/type_x.transformed.rb +56 -0
  193. data/spec/generators/graphql/function_generator_spec.rb +26 -0
  194. data/spec/generators/graphql/install_generator_spec.rb +1 -1
  195. data/spec/generators/graphql/loader_generator_spec.rb +24 -0
  196. data/spec/graphql/analysis/max_query_complexity_spec.rb +3 -3
  197. data/spec/graphql/analysis/max_query_depth_spec.rb +3 -3
  198. data/spec/graphql/argument_spec.rb +21 -0
  199. data/spec/graphql/backtrace_spec.rb +10 -0
  200. data/spec/graphql/base_type_spec.rb +42 -0
  201. data/spec/graphql/boolean_type_spec.rb +3 -3
  202. data/spec/graphql/directive_spec.rb +3 -1
  203. data/spec/graphql/enum_type_spec.rb +18 -5
  204. data/spec/graphql/execution/execute_spec.rb +4 -4
  205. data/spec/graphql/execution/instrumentation_spec.rb +165 -0
  206. data/spec/graphql/execution/multiplex_spec.rb +2 -2
  207. data/spec/graphql/execution_error_spec.rb +18 -0
  208. data/spec/graphql/float_type_spec.rb +2 -2
  209. data/spec/graphql/id_type_spec.rb +1 -1
  210. data/spec/graphql/input_object_type_spec.rb +15 -2
  211. data/spec/graphql/int_type_spec.rb +2 -2
  212. data/spec/graphql/interface_type_spec.rb +12 -0
  213. data/spec/graphql/internal_representation/rewrite_spec.rb +2 -2
  214. data/spec/graphql/introspection/schema_type_spec.rb +2 -0
  215. data/spec/graphql/language/block_string_spec.rb +70 -0
  216. data/spec/graphql/language/document_from_schema_definition_spec.rb +770 -0
  217. data/spec/graphql/language/generation_spec.rb +21 -186
  218. data/spec/graphql/language/lexer_spec.rb +21 -1
  219. data/spec/graphql/language/nodes_spec.rb +21 -12
  220. data/spec/graphql/language/parser_spec.rb +1 -1
  221. data/spec/graphql/language/printer_spec.rb +203 -0
  222. data/spec/graphql/object_type_spec.rb +22 -0
  223. data/spec/graphql/query/arguments_spec.rb +25 -15
  224. data/spec/graphql/query/context_spec.rb +18 -0
  225. data/spec/graphql/query/executor_spec.rb +2 -1
  226. data/spec/graphql/query/serial_execution/value_resolution_spec.rb +2 -8
  227. data/spec/graphql/query/variables_spec.rb +42 -1
  228. data/spec/graphql/query_spec.rb +31 -5
  229. data/spec/graphql/rake_task_spec.rb +3 -1
  230. data/spec/graphql/relay/base_connection_spec.rb +1 -1
  231. data/spec/graphql/relay/connection_instrumentation_spec.rb +2 -2
  232. data/spec/graphql/relay/connection_resolve_spec.rb +1 -1
  233. data/spec/graphql/relay/connection_type_spec.rb +1 -1
  234. data/spec/graphql/relay/mongo_relation_connection_spec.rb +474 -0
  235. data/spec/graphql/relay/mutation_spec.rb +9 -7
  236. data/spec/graphql/relay/range_add_spec.rb +5 -1
  237. data/spec/graphql/relay/relation_connection_spec.rb +65 -1
  238. data/spec/graphql/schema/argument_spec.rb +87 -0
  239. data/spec/graphql/schema/build_from_definition_spec.rb +89 -5
  240. data/spec/graphql/schema/enum_spec.rb +74 -0
  241. data/spec/graphql/schema/field_spec.rb +225 -0
  242. data/spec/graphql/schema/finder_spec.rb +135 -0
  243. data/spec/graphql/schema/input_object_spec.rb +111 -0
  244. data/spec/graphql/schema/instrumentation_spec.rb +40 -0
  245. data/spec/graphql/schema/interface_spec.rb +185 -0
  246. data/spec/graphql/schema/introspection_system_spec.rb +39 -0
  247. data/spec/graphql/schema/member/accepts_definition_spec.rb +111 -0
  248. data/spec/graphql/schema/member/build_type_spec.rb +17 -0
  249. data/spec/graphql/schema/member/has_fields_spec.rb +129 -0
  250. data/spec/graphql/schema/member/type_system_helpers_spec.rb +63 -0
  251. data/spec/graphql/schema/mutation_spec.rb +148 -0
  252. data/spec/graphql/schema/object_spec.rb +175 -0
  253. data/spec/graphql/schema/printer_spec.rb +111 -15
  254. data/spec/graphql/schema/relay_classic_mutation_spec.rb +38 -0
  255. data/spec/graphql/schema/rescue_middleware_spec.rb +11 -0
  256. data/spec/graphql/schema/resolver_spec.rb +131 -0
  257. data/spec/graphql/schema/scalar_spec.rb +95 -0
  258. data/spec/graphql/schema/traversal_spec.rb +31 -0
  259. data/spec/graphql/schema/union_spec.rb +65 -0
  260. data/spec/graphql/schema/validation_spec.rb +1 -1
  261. data/spec/graphql/schema/warden_spec.rb +11 -11
  262. data/spec/graphql/schema_spec.rb +55 -12
  263. data/spec/graphql/static_validation/rules/fields_have_appropriate_selections_spec.rb +10 -2
  264. data/spec/graphql/static_validation/rules/fields_will_merge_spec.rb +2 -2
  265. data/spec/graphql/string_type_spec.rb +3 -3
  266. data/spec/graphql/subscriptions_spec.rb +273 -184
  267. data/spec/graphql/tracing/active_support_notifications_tracing_spec.rb +1 -1
  268. data/spec/graphql/tracing/new_relic_tracing_spec.rb +47 -0
  269. data/spec/graphql/tracing/platform_tracing_spec.rb +60 -1
  270. data/spec/graphql/union_type_spec.rb +1 -1
  271. data/spec/graphql/upgrader/member_spec.rb +516 -0
  272. data/spec/graphql/upgrader/schema_spec.rb +82 -0
  273. data/spec/spec_helper.rb +8 -0
  274. data/spec/support/dummy/schema.rb +53 -24
  275. data/spec/support/jazz.rb +544 -0
  276. data/spec/support/lazy_helpers.rb +21 -23
  277. data/spec/support/new_relic.rb +24 -0
  278. data/spec/support/star_trek/data.rb +109 -0
  279. data/spec/support/star_trek/schema.rb +388 -0
  280. data/spec/support/star_wars/data.rb +6 -7
  281. data/spec/support/star_wars/schema.rb +127 -171
  282. metadata +233 -11
  283. data/lib/graphql/introspection/arguments_field.rb +0 -7
  284. data/lib/graphql/introspection/enum_values_field.rb +0 -18
  285. data/lib/graphql/introspection/fields_field.rb +0 -13
  286. data/lib/graphql/introspection/input_fields_field.rb +0 -12
  287. data/lib/graphql/introspection/interfaces_field.rb +0 -11
  288. data/lib/graphql/introspection/of_type_field.rb +0 -6
  289. data/lib/graphql/introspection/possible_types_field.rb +0 -11
@@ -0,0 +1,19 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Platform
4
+ module Unions
5
+ Account = GraphQL::UnionType.define do
6
+ name "Account"
7
+ description "Users and organizations."
8
+ visibility :internal
9
+
10
+ possible_types [
11
+ Objects::User,
12
+ Objects::Organization,
13
+ Objects::Bot
14
+ ]
15
+
16
+ resolve_type ->(obj, ctx) { :stand_in }
17
+ end
18
+ end
19
+ end
@@ -0,0 +1,20 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Platform
4
+ module Unions
5
+ class Account < Platform::Unions::Base
6
+ description "Users and organizations."
7
+ visibility :internal
8
+
9
+ possible_types(
10
+ Objects::User,
11
+ Objects::Organization,
12
+ Objects::Bot,
13
+ )
14
+
15
+ def self.resolve_type(obj, ctx)
16
+ :stand_in
17
+ end
18
+ end
19
+ end
20
+ end
@@ -0,0 +1,43 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Platform
4
+ module Objects
5
+ BlameRange = GraphQL::ObjectType.define do
6
+ name "BlameRange"
7
+ description "Represents a range of information from a Git blame."
8
+
9
+ scopeless_tokens_as_minimum
10
+
11
+
12
+ interfaces [
13
+ Interfaces::A,
14
+ Interfaces::B,
15
+ ]
16
+
17
+ field :startingLine, !types.Int do
18
+ description "The starting line for the range"
19
+
20
+ resolve ->(range, args, context) {
21
+ range.lines.first[:lineno]
22
+ }
23
+ end
24
+
25
+ field :endingLine, !types.Int do
26
+ description "The ending line for the range"
27
+
28
+ resolve ->(range, args, context) {
29
+ range.lines.first[:lineno] + (range.lines.length - 1)
30
+ }
31
+ end
32
+
33
+ field :commit, -> { !Objects::Commit } do
34
+ description "Identifies the line author"
35
+ end
36
+
37
+ field :age, !types.Int do
38
+ description "Identifies the recency of the change, from 1 (new) to 10 (old). This is calculated as a 2-quantile and determines the length of distance between the median age of all the changes in the file and the recency of the current range's change."
39
+ property :scale
40
+ end
41
+ end
42
+ end
43
+ end
@@ -0,0 +1,30 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Platform
4
+ module Objects
5
+ class BlameRange < Platform::Objects::Base
6
+ description "Represents a range of information from a Git blame."
7
+
8
+ scopeless_tokens_as_minimum
9
+
10
+ implements Interfaces::A
11
+ implements Interfaces::B
12
+
13
+ field :starting_line, Integer, description: "The starting line for the range", null: false
14
+
15
+ def starting_line
16
+ @object.lines.first[:lineno]
17
+ end
18
+
19
+ field :ending_line, Integer, description: "The ending line for the range", null: false
20
+
21
+ def ending_line
22
+ @object.lines.first[:lineno] + (@object.lines.length - 1)
23
+ end
24
+
25
+ field :commit, Objects::Commit, description: "Identifies the line author", null: false
26
+
27
+ field :age, Integer, method: :scale, description: "Identifies the recency of the change, from 1 (new) to 10 (old). This is calculated as a 2-quantile and determines the length of distance between the median age of all the changes in the file and the recency of the current range's change.", null: false
28
+ end
29
+ end
30
+ end
@@ -0,0 +1,24 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Platform
4
+ module Scalars
5
+ DateTime = GraphQL::ScalarType.define do
6
+ name "DateTime"
7
+ description "An ISO-8601 encoded UTC date string."
8
+
9
+ # rubocop:disable Layout/SpaceInLambdaLiteral
10
+ coerce_input -> (value, context) do
11
+ begin
12
+ Time.iso8601(value)
13
+ rescue ArgumentError, ::TypeError
14
+ end
15
+ end
16
+ # rubocop:enable Layout/SpaceInLambdaLiteral
17
+
18
+ coerce_result ->(value, context) do
19
+ return nil unless value
20
+ value.utc.iso8601
21
+ end
22
+ end
23
+ end
24
+ end
@@ -0,0 +1,23 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Platform
4
+ module Scalars
5
+ class DateTime < Platform::Scalars::Base
6
+ description "An ISO-8601 encoded UTC date string."
7
+
8
+ # rubocop:disable Layout/SpaceInLambdaLiteral
9
+ def self.coerce_input(value, context)
10
+ begin
11
+ Time.iso8601(value)
12
+ rescue ArgumentError, ::TypeError
13
+ end
14
+ end
15
+ # rubocop:enable Layout/SpaceInLambdaLiteral
16
+
17
+ def self.coerce_result(value, context)
18
+ return nil unless value
19
+ value.utc.iso8601
20
+ end
21
+ end
22
+ end
23
+ end
@@ -0,0 +1,28 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Platform
4
+ module Mutations
5
+ DeleteProject = GraphQL::Relay::Mutation.define do
6
+ name "DeleteProject"
7
+ description "Deletes a project."
8
+
9
+ minimum_accepted_scopes ["public_repo"]
10
+
11
+ input_field :projectId, !types.ID, "The Project ID to update."
12
+ return_field :owner, !Interfaces::ProjectOwner, "The repository or organization the project was removed from."
13
+
14
+ resolve ->(root_obj, inputs, context) do
15
+ project = Platform::Helpers::NodeIdentification.typed_object_from_id(
16
+ [Objects::Project], inputs[:projectId], context
17
+ )
18
+
19
+ context[:permission].can_modify?("DeleteProject", project).sync
20
+ context[:abilities].authorize_content(:project, :destroy, owner: project.owner)
21
+
22
+ project.enqueue_delete(actor: context[:viewer])
23
+
24
+ { owner: project.owner }
25
+ end
26
+ end
27
+ end
28
+ end
@@ -0,0 +1,27 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Platform
4
+ module Mutations
5
+ class DeleteProject < Mutations::BaseMutation
6
+ description "Deletes a project."
7
+
8
+ minimum_accepted_scopes ["public_repo"]
9
+
10
+ argument :project_id, ID, "The Project ID to update.", required: true
11
+ field :owner, Interfaces::ProjectOwner, "The repository or organization the project was removed from.", null: false
12
+
13
+ def resolve(**inputs)
14
+ project = Platform::Helpers::NodeIdentification.typed_object_from_id(
15
+ [Objects::Project], inputs[:project_id], @context
16
+ )
17
+
18
+ @context[:permission].can_modify?("DeleteProject", project).sync
19
+ @context[:abilities].authorize_content(:project, :destroy, owner: project.owner)
20
+
21
+ project.enqueue_delete(actor: @context[:viewer])
22
+
23
+ { owner: project.owner }
24
+ end
25
+ end
26
+ end
27
+ end
@@ -0,0 +1,14 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Platform
4
+ module Enums
5
+ GistOrderField = GraphQL::EnumType.define do
6
+ name "GistOrderField"
7
+ description "Properties by which gist connections can be ordered."
8
+
9
+ value "CREATED_AT", "Order gists by creation time", value: "created_at"
10
+ value "UPDATED_AT", "Order gists by update time", value: "updated_at"
11
+ value "PUSHED_AT", "Order gists by push time", value: "pushed_at"
12
+ end
13
+ end
14
+ end
@@ -0,0 +1,13 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Platform
4
+ module Enums
5
+ class GistOrderField < Platform::Enums::Base
6
+ description "Properties by which gist connections can be ordered."
7
+
8
+ value "CREATED_AT", "Order gists by creation time", value: "created_at"
9
+ value "UPDATED_AT", "Order gists by update time", value: "updated_at"
10
+ value "PUSHED_AT", "Order gists by push time", value: "pushed_at"
11
+ end
12
+ end
13
+ end
@@ -0,0 +1,59 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Platform
4
+ module Mutations
5
+ IncrementThing = GraphQL::Relay::Mutation.define do
6
+ name "IncrementThing"
7
+ description "increments the thing by 1."
8
+ visibility :internal
9
+ minimum_accepted_scopes ["repo"]
10
+
11
+ input_field(:thingId,
12
+ !types.ID,
13
+ "Thing ID to log.",
14
+ option: :setting)
15
+
16
+ return_field(
17
+ :thingId,
18
+ !types.ID,
19
+ "Thing ID to log."
20
+ )
21
+
22
+ resolve ->(root_obj, inputs, context) do
23
+ if some_early_check
24
+ return { thingId: "000" }
25
+ end
26
+
27
+ # These shouldn't be modified:
28
+ { abcDef: 1 }
29
+ some_method do { xyzAbc: 1 } end
30
+
31
+ thing = Platform::Helpers::NodeIdentification.typed_object_from_id(Objects::Thing, inputs[:thingId], context)
32
+ raise Errors::Validation.new("Thing not found.") unless thing
33
+
34
+ ThingActivity.track(thing.id, Time.now.change(min: 0, sec: 0))
35
+
36
+
37
+ if random_condition
38
+ { thingId: thing.global_relay_id }
39
+ elsif other_random_thing
40
+ { :thingId => "abc" }
41
+ elsif something_else
42
+ method_with_block {
43
+ { thingId: "pqr" }
44
+ }
45
+ elsif yet_another_thing
46
+ begin
47
+ { thingId: "987" }
48
+ rescue
49
+ { thingId: "789" }
50
+ end
51
+ else
52
+ return {
53
+ thingId: "xyz"
54
+ }
55
+ end
56
+ end
57
+ end
58
+ end
59
+ end
@@ -0,0 +1,50 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Platform
4
+ module Mutations
5
+ class IncrementThing < Mutations::BaseMutation
6
+ description "increments the thing by 1."
7
+ visibility :internal
8
+ minimum_accepted_scopes ["repo"]
9
+
10
+ argument :thing_id, ID, "Thing ID to log.", option: :setting, required: true
11
+
12
+ field :thing_id, ID, "Thing ID to log.", null: false
13
+
14
+ def resolve(**inputs)
15
+ if some_early_check
16
+ return { thing_id: "000" }
17
+ end
18
+
19
+ # These shouldn't be modified:
20
+ { abcDef: 1 }
21
+ some_method do { xyzAbc: 1 } end
22
+
23
+ thing = Platform::Helpers::NodeIdentification.typed_object_from_id(Objects::Thing, inputs[:thing_id], @context)
24
+ raise Errors::Validation.new("Thing not found.") unless thing
25
+
26
+ ThingActivity.track(thing.id, Time.now.change(min: 0, sec: 0))
27
+
28
+ if random_condition
29
+ { thing_id: thing.global_relay_id }
30
+ elsif other_random_thing
31
+ { :thing_id => "abc" }
32
+ elsif something_else
33
+ method_with_block {
34
+ { thing_id: "pqr" }
35
+ }
36
+ elsif yet_another_thing
37
+ begin
38
+ { thing_id: "987" }
39
+ rescue
40
+ { thing_id: "789" }
41
+ end
42
+ else
43
+ return {
44
+ thing_id: "xyz"
45
+ }
46
+ end
47
+ end
48
+ end
49
+ end
50
+ end
@@ -0,0 +1,10 @@
1
+ # frozen_string_literal: true
2
+ module Platform
3
+ module Objects
4
+ Photo = GraphQL::ObjectType.define do
5
+ field(:caption, types.String) do
6
+ resolve(->(obj, _args, _ctx) { obj.caption })
7
+ end
8
+ end
9
+ end
10
+ end
@@ -0,0 +1,12 @@
1
+ # frozen_string_literal: true
2
+ module Platform
3
+ module Objects
4
+ class Photo < Platform::Objects::Base
5
+ field :caption, String, null: true
6
+
7
+ def caption
8
+ @object.caption
9
+ end
10
+ end
11
+ end
12
+ end
@@ -0,0 +1,15 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Platform
4
+ module Inputs
5
+ ReleaseOrder = GraphQL::InputObjectType.define do
6
+ name "ReleaseOrder"
7
+ description "Ways in which lists of releases can be ordered upon return."
8
+
9
+ input_field :field, types[!Enums::ReleaseOrderField], <<-MD
10
+ The field in which to order releases by.
11
+ MD
12
+ input_field :direction, !Enums::OrderDirection, "The direction in which to order releases by the specified field."
13
+ end
14
+ end
15
+ end
@@ -0,0 +1,14 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Platform
4
+ module Inputs
5
+ class ReleaseOrder < Platform::Inputs::Base
6
+ description "Ways in which lists of releases can be ordered upon return."
7
+
8
+ argument :field, [Enums::ReleaseOrderField], <<-MD, required: false
9
+ The field in which to order releases by.
10
+ MD
11
+ argument :direction, Enums::OrderDirection, "The direction in which to order releases by the specified field.", required: true
12
+ end
13
+ end
14
+ end
@@ -0,0 +1,49 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Platform
4
+ module Interfaces
5
+ Starrable = GraphQL::InterfaceType.define do
6
+ name "Starrable"
7
+ description "Things that can be starred."
8
+
9
+ global_id_field :id
10
+
11
+ field :viewerHasStarred, !types.Boolean do
12
+ argument :preceedsConnectionMethod, types.Boolean
13
+ description "Returns a boolean indicating whether the viewing user has starred this starrable."
14
+
15
+ resolve ->(object, arguments, context) do
16
+ if context[:viewer]
17
+ ->(test_inner_proc) do
18
+ context[:viewer].starred?(object)
19
+ end
20
+ else
21
+ false
22
+ end
23
+ end
24
+ end
25
+
26
+ connection :stargazers, -> { !Connections::Stargazer } do
27
+ description "A list of users who have starred this starrable."
28
+
29
+ argument :orderBy, Inputs::StarOrder, "Order for connection"
30
+
31
+ resolve ->(object, arguments, context) do
32
+ scope = case object
33
+ when Repository
34
+ object.stars
35
+ when Gist
36
+ GistStar.where(gist_id: object.id)
37
+ end
38
+
39
+ table = scope.table_name
40
+ if order_by = arguments["orderBy"]
41
+ scope = scope.order("#{table}.#{order_by["field"]} #{order_by["direction"]}")
42
+ end
43
+
44
+ scope
45
+ end
46
+ end
47
+ end
48
+ end
49
+ end
@@ -0,0 +1,46 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Platform
4
+ module Interfaces
5
+ module Starrable
6
+ include Platform::Interfaces::Base
7
+ description "Things that can be starred."
8
+
9
+ global_id_field :id
10
+
11
+ field :viewer_has_starred, Boolean, description: "Returns a boolean indicating whether the viewing user has starred this starrable.", null: false do
12
+ argument :preceeds_connection_method, Boolean, required: false
13
+ end
14
+
15
+ def viewer_has_starred(**arguments)
16
+ if @context[:viewer]
17
+ ->(test_inner_proc) do
18
+ @context[:viewer].starred?(@object)
19
+ end
20
+ else
21
+ false
22
+ end
23
+ end
24
+
25
+ field :stargazers, Connections::Stargazer, description: "A list of users who have starred this starrable.", null: false, connection: true do
26
+ argument :order_by, Inputs::StarOrder, "Order for connection", required: false
27
+ end
28
+
29
+ def stargazers(**arguments)
30
+ scope = case @object
31
+ when Repository
32
+ @object.stars
33
+ when Gist
34
+ GistStar.where(gist_id: @object.id)
35
+ end
36
+
37
+ table = scope.table_name
38
+ if order_by = arguments[:order_by]
39
+ scope = scope.order("#{table}.#{order_by["field"]} #{order_by["direction"]}")
40
+ end
41
+
42
+ scope
43
+ end
44
+ end
45
+ end
46
+ end
@@ -0,0 +1,55 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Platform
4
+ module Interfaces
5
+ Subscribable = GraphQL::InterfaceType.define do
6
+ name "Subscribable"
7
+ description "Entities that can be subscribed to for web and email notifications."
8
+
9
+ field :id, !GraphQL::ID_TYPE, property: :global_relay_id
10
+
11
+ field :viewerSubscription, -> { !Enums::SubscriptionState } do
12
+ description "Identifies if the viewer is watching, not watching, or ignoring the subscribable entity."
13
+
14
+ resolve ->(subscribable, arguments, context) do
15
+ if context[:viewer].nil?
16
+ return "unsubscribed"
17
+ end
18
+
19
+ subscription_status_response = subscribable.async_subscription_status(context[:viewer]).sync
20
+
21
+ if subscription_status_response.failed?
22
+ error = Platform::Errors::ServiceUnavailable.new("Subscriptions are currently unavailable. Please try again later.")
23
+ error.ast_node = context.irep_node.ast_node
24
+ error.path = context.path
25
+ context.errors << error
26
+ return "unavailable"
27
+ end
28
+
29
+ subscription = subscription_status_response.value
30
+ if subscription.included?
31
+ "unsubscribed"
32
+ elsif subscription.subscribed?
33
+ "subscribed"
34
+ elsif subscription.ignored?
35
+ "ignored"
36
+ end
37
+ end
38
+ end
39
+
40
+ field :viewerCanSubscribe, !types.Boolean do
41
+ description "Check if the viewer is able to change their subscription status for the repository."
42
+
43
+ resolve ->(subscribable, arguments, context) do
44
+ return false if context[:viewer].nil?
45
+
46
+ subscribable.async_subscription_status(context[:viewer]).then(&:success?)
47
+ end
48
+ end
49
+
50
+ connection :issues, function: Platform::Functions::Issues.new, description: "A list of issues associated with the milestone."
51
+ connection :files, -> { !Connections.define(PackageFile) }, description: "List of files associated with this registry package version"
52
+ field :enabled, !types.Boolean, "Whether enabled for this project", property: :enabled?
53
+ end
54
+ end
55
+ end
@@ -0,0 +1,51 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Platform
4
+ module Interfaces
5
+ module Subscribable
6
+ include Platform::Interfaces::Base
7
+ description "Entities that can be subscribed to for web and email notifications."
8
+
9
+ field :id, GraphQL::ID_TYPE, method: :global_relay_id, null: false
10
+
11
+ field :viewer_subscription, Enums::SubscriptionState, description: "Identifies if the viewer is watching, not watching, or ignoring the subscribable entity.", null: false
12
+
13
+ def viewer_subscription
14
+ if @context[:viewer].nil?
15
+ return "unsubscribed"
16
+ end
17
+
18
+ subscription_status_response = @object.async_subscription_status(@context[:viewer]).sync
19
+
20
+ if subscription_status_response.failed?
21
+ error = Platform::Errors::ServiceUnavailable.new("Subscriptions are currently unavailable. Please try again later.")
22
+ error.ast_node = @context.irep_node.ast_node
23
+ error.path = @context.path
24
+ @context.errors << error
25
+ return "unavailable"
26
+ end
27
+
28
+ subscription = subscription_status_response.value
29
+ if subscription.included?
30
+ "unsubscribed"
31
+ elsif subscription.subscribed?
32
+ "subscribed"
33
+ elsif subscription.ignored?
34
+ "ignored"
35
+ end
36
+ end
37
+
38
+ field :viewer_can_subscribe, Boolean, description: "Check if the viewer is able to change their subscription status for the repository.", null: false
39
+
40
+ def viewer_can_subscribe
41
+ return false if @context[:viewer].nil?
42
+
43
+ @object.async_subscription_status(@context[:viewer]).then(&:success?)
44
+ end
45
+
46
+ field :issues, function: Platform::Functions::Issues.new, description: "A list of issues associated with the milestone.", connection: true
47
+ field :files, Connections.define(PackageFile), description: "List of files associated with this registry package version", null: false, connection: true
48
+ field :enabled, Boolean, "Whether enabled for this project", method: :enabled?, null: false
49
+ end
50
+ end
51
+ end