graphiti 2.0.0.beta.2 → 2.0.0.beta.4

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (269) hide show
  1. checksums.yaml +4 -4
  2. data/.github/workflows/ci.yml +30 -86
  3. data/.github/workflows/docs.yml +60 -0
  4. data/.github/workflows/release.yml +8 -8
  5. data/.gitignore +7 -0
  6. data/.npmrc +9 -0
  7. data/.standard.yml +4 -1
  8. data/Appraisals +33 -32
  9. data/CHANGELOG.md +41 -0
  10. data/README.md +13 -2
  11. data/UPGRADING.md +2 -68
  12. data/docs/concepts/backends-and-models.md +122 -0
  13. data/docs/concepts/endpoints.md +183 -0
  14. data/docs/concepts/links.md +212 -0
  15. data/docs/concepts/overview.md +80 -0
  16. data/docs/concepts/persisting.md +376 -0
  17. data/docs/concepts/relationships.md +527 -0
  18. data/docs/concepts/resources.md +677 -0
  19. data/docs/getting-started/first-api.md +289 -0
  20. data/docs/getting-started/installation.md +185 -0
  21. data/docs/intro.md +307 -0
  22. data/docs/js/authentication.md +63 -0
  23. data/docs/js/ddau.md +20 -0
  24. data/docs/js/extra-params.md +41 -0
  25. data/docs/js/index.md +112 -0
  26. data/docs/js/installation.md +120 -0
  27. data/docs/js/middleware.md +72 -0
  28. data/docs/js/models.md +202 -0
  29. data/docs/js/reads.md +494 -0
  30. data/docs/js/state-syncing.md +100 -0
  31. data/docs/js/writes.md +373 -0
  32. data/docs/reference/vandal.md +63 -0
  33. data/docs/reference/why.md +13 -0
  34. data/docs/topics/authorization.md +155 -0
  35. data/docs/topics/caching.md +55 -0
  36. data/docs/topics/customizing-sideloads.md +156 -0
  37. data/docs/topics/debugging.md +216 -0
  38. data/docs/topics/error-handling.md +210 -0
  39. data/docs/topics/etags.md +46 -0
  40. data/docs/topics/hopping-relationships.md +149 -0
  41. data/docs/topics/json-attributes.md +77 -0
  42. data/docs/topics/openstruct-models.md +50 -0
  43. data/docs/topics/remote-resources.md +291 -0
  44. data/docs/topics/testing.md +894 -0
  45. data/docs/topics/without-activerecord.md +324 -0
  46. data/docs/tutorial/index.md +58 -0
  47. data/docs/tutorial/step_0.md +107 -0
  48. data/docs/tutorial/step_1.md +199 -0
  49. data/docs/tutorial/step_2.md +312 -0
  50. data/docs/tutorial/step_3.md +142 -0
  51. data/docs/tutorial/step_4.md +135 -0
  52. data/docs/tutorial/step_5.md +69 -0
  53. data/docs/tutorial/step_6.md +82 -0
  54. data/docs/tutorial/step_7.md +205 -0
  55. data/docs/tutorial/step_8.md +128 -0
  56. data/docs/tutorial/step_9.md +171 -0
  57. data/docs/upgrading.md +265 -0
  58. data/gemfiles/rails_7_1.gemfile +4 -3
  59. data/gemfiles/{rails_7_2_graphiti_rails.gemfile → rails_7_2.gemfile} +3 -3
  60. data/gemfiles/{rails_8_1_graphiti_rails.gemfile → rails_8_0.gemfile} +3 -3
  61. data/gemfiles/{rails_8_0_graphiti_rails.gemfile → rails_8_1.gemfile} +3 -3
  62. data/graphiti.gemspec +7 -5
  63. data/{deprecated_generators → lib/generators}/graphiti/api_test_generator.rb +7 -1
  64. data/{deprecated_generators → lib/generators}/graphiti/generator_mixin.rb +14 -1
  65. data/{deprecated_generators → lib/generators}/graphiti/install_generator.rb +19 -13
  66. data/{deprecated_generators → lib/generators}/graphiti/resource_generator.rb +43 -6
  67. data/{deprecated_generators → lib/generators}/graphiti/templates/index_request_spec.rb.erb +1 -1
  68. data/{deprecated_generators → lib/generators}/graphiti/templates/resource_reads_spec.rb.erb +6 -6
  69. data/{deprecated_generators → lib/generators}/graphiti/templates/show_request_spec.rb.erb +1 -1
  70. data/lib/graphiti/configuration.rb +2 -2
  71. data/lib/graphiti/error_serializers/conflict_request.rb +19 -0
  72. data/lib/graphiti/error_serializers/deprecated_constants.rb +48 -0
  73. data/lib/graphiti/error_serializers/invalid_request.rb +56 -0
  74. data/lib/graphiti/error_serializers/validation.rb +143 -0
  75. data/lib/graphiti/errors.rb +4 -23
  76. data/lib/graphiti/query.rb +1 -1
  77. data/lib/graphiti/rails/context.rb +33 -0
  78. data/lib/graphiti/rails/controller.rb +41 -0
  79. data/lib/graphiti/rails/debugging.rb +18 -0
  80. data/lib/graphiti/rails/exception_handlers.rb +77 -0
  81. data/lib/graphiti/rails/railtie.rb +139 -0
  82. data/lib/graphiti/rails/responders.rb +21 -0
  83. data/lib/graphiti/rails/test_helpers.rb +22 -0
  84. data/lib/graphiti/rails.rb +47 -29
  85. data/lib/graphiti/resource/configuration.rb +1 -0
  86. data/lib/graphiti/resource/interface.rb +2 -2
  87. data/lib/graphiti/resource/persistence.rb +14 -2
  88. data/lib/graphiti/resource/remote.rb +2 -2
  89. data/lib/graphiti/resource/sideloading.rb +1 -1
  90. data/lib/graphiti/resource.rb +13 -1
  91. data/lib/graphiti/responders.rb +7 -20
  92. data/lib/graphiti/schema.rb +5 -1
  93. data/lib/graphiti/schema_diff.rb +4 -0
  94. data/lib/graphiti/scope.rb +45 -37
  95. data/lib/graphiti/serializer.rb +6 -0
  96. data/lib/graphiti/sideload/belongs_to.rb +38 -5
  97. data/lib/graphiti/sideload/polymorphic_belongs_to.rb +27 -23
  98. data/lib/graphiti/sideload.rb +54 -35
  99. data/lib/graphiti/spec_helpers/errors.rb +73 -0
  100. data/lib/graphiti/spec_helpers/errors_proxy.rb +75 -0
  101. data/lib/graphiti/spec_helpers/helpers.rb +107 -0
  102. data/lib/graphiti/spec_helpers/node.rb +88 -0
  103. data/lib/graphiti/spec_helpers/rspec.rb +147 -0
  104. data/lib/graphiti/spec_helpers.rb +53 -0
  105. data/lib/graphiti/util/include_params.rb +2 -2
  106. data/lib/graphiti/util/persistence.rb +10 -11
  107. data/lib/graphiti/util/serializer_relationships.rb +41 -5
  108. data/lib/graphiti/version.rb +1 -1
  109. data/lib/graphiti-rails.rb +11 -0
  110. data/lib/graphiti.rb +34 -10
  111. data/lib/graphiti_errors.rb +11 -0
  112. data/lib/graphiti_spec_helpers/rspec.rb +3 -0
  113. data/lib/graphiti_spec_helpers.rb +11 -0
  114. data/lib/{graphiti/deprecated_tasks.rb → tasks/graphiti.rake} +6 -1
  115. data/package-lock.json +6199 -0
  116. data/package.json +5 -4
  117. data/website/.gitignore +20 -0
  118. data/website/README.md +43 -0
  119. data/website/docusaurus.config.js +141 -0
  120. data/website/package-lock.json +19474 -0
  121. data/website/package.json +46 -0
  122. data/website/sidebars.js +82 -0
  123. data/website/src/css/custom.css +58 -0
  124. data/website/src/pages/markdown-page.mdx +7 -0
  125. data/website/static/.nojekyll +0 -0
  126. data/website/static/1.13/2019/03/31/graphiti-1-0.html +205 -0
  127. data/website/static/1.13/2019/05/08/graphiti-1-1.html +212 -0
  128. data/website/static/1.13/2019/05/20/graphiti-1-2.html +214 -0
  129. data/website/static/1.13/2019/10/14/tutorial.html +198 -0
  130. data/website/static/1.13/CNAME +1 -0
  131. data/website/static/1.13/README.md +16 -0
  132. data/website/static/1.13/assets/css/syntax.css +60 -0
  133. data/website/static/1.13/assets/favicons/android-chrome-192x192.png +0 -0
  134. data/website/static/1.13/assets/favicons/android-chrome-256x256.png +0 -0
  135. data/website/static/1.13/assets/favicons/apple-touch-icon.png +0 -0
  136. data/website/static/1.13/assets/favicons/browserconfig.xml +9 -0
  137. data/website/static/1.13/assets/favicons/favicon-16x16.png +0 -0
  138. data/website/static/1.13/assets/favicons/favicon-32x32.png +0 -0
  139. data/website/static/1.13/assets/favicons/favicon.ico +0 -0
  140. data/website/static/1.13/assets/favicons/mstile-150x150.png +0 -0
  141. data/website/static/1.13/assets/favicons/safari-pinned-tab.svg +1 -0
  142. data/website/static/1.13/assets/favicons/site.webmanifest +19 -0
  143. data/website/static/1.13/assets/img/backend.gif +0 -0
  144. data/website/static/1.13/assets/img/conformity.png +0 -0
  145. data/website/static/1.13/assets/img/error_payload.png +0 -0
  146. data/website/static/1.13/assets/img/gh.png +0 -0
  147. data/website/static/1.13/assets/img/lifecycle.gif +0 -0
  148. data/website/static/1.13/assets/img/logo-500.png +0 -0
  149. data/website/static/1.13/assets/img/logo.png +0 -0
  150. data/website/static/1.13/assets/img/love-graffiti.jpg +0 -0
  151. data/website/static/1.13/assets/img/meta_total_count.png +0 -0
  152. data/website/static/1.13/assets/img/persist.jpg +0 -0
  153. data/website/static/1.13/assets/img/resource.gif +0 -0
  154. data/website/static/1.13/assets/img/rest-graffiti.jpg +0 -0
  155. data/website/static/1.13/assets/img/rest1.gif +0 -0
  156. data/website/static/1.13/assets/img/rest2.gif +0 -0
  157. data/website/static/1.13/assets/img/rest3.gif +0 -0
  158. data/website/static/1.13/assets/img/rethink-rest-graffiti.jpg +0 -0
  159. data/website/static/1.13/assets/img/why.png +0 -0
  160. data/website/static/1.13/assets/js/highlight.pack.js +2 -0
  161. data/website/static/1.13/assets/main.css +15518 -0
  162. data/website/static/1.13/assets/main.css.map +1 -0
  163. data/website/static/1.13/bin/bundle +109 -0
  164. data/website/static/1.13/bin/jekyll +27 -0
  165. data/website/static/1.13/bin/kramdown +27 -0
  166. data/website/static/1.13/bin/listen +27 -0
  167. data/website/static/1.13/bin/rake +27 -0
  168. data/website/static/1.13/bin/rougify +27 -0
  169. data/website/static/1.13/bin/safe_yaml +27 -0
  170. data/website/static/1.13/bin/sass +27 -0
  171. data/website/static/1.13/bin/sass-convert +27 -0
  172. data/website/static/1.13/bin/scss +27 -0
  173. data/website/static/1.13/blog.html +259 -0
  174. data/website/static/1.13/cheatsheet.html +316 -0
  175. data/website/static/1.13/cookbooks/authorization.md +0 -0
  176. data/website/static/1.13/cookbooks/caching.md +0 -0
  177. data/website/static/1.13/cookbooks/customizing-sideloads.html +325 -0
  178. data/website/static/1.13/cookbooks/etags.md +0 -0
  179. data/website/static/1.13/cookbooks/hopping-relationships.html +324 -0
  180. data/website/static/1.13/cookbooks/json_attributes.md +0 -0
  181. data/website/static/1.13/cookbooks/openstruct-models.md +0 -0
  182. data/website/static/1.13/cookbooks/remote-resources.md +0 -0
  183. data/website/static/1.13/cookbooks/without-activerecord.html +510 -0
  184. data/website/static/1.13/features.html +249 -0
  185. data/website/static/1.13/feed.xml +106 -0
  186. data/website/static/1.13/guides/concepts/backends-and-models.html +467 -0
  187. data/website/static/1.13/guides/concepts/debugging.html +440 -0
  188. data/website/static/1.13/guides/concepts/endpoints.html +432 -0
  189. data/website/static/1.13/guides/concepts/error-handling.html +396 -0
  190. data/website/static/1.13/guides/concepts/links.html +501 -0
  191. data/website/static/1.13/guides/concepts/remote-resources.html +536 -0
  192. data/website/static/1.13/guides/concepts/resources.html +2176 -0
  193. data/website/static/1.13/guides/concepts/testing.html +1469 -0
  194. data/website/static/1.13/guides/getting-started/installation.html +420 -0
  195. data/website/static/1.13/guides/graphiti-rails-migration.html +242 -0
  196. data/website/static/1.13/guides/index.html +269 -0
  197. data/website/static/1.13/guides/overview.html +325 -0
  198. data/website/static/1.13/guides/upgrading-2-0.html +193 -0
  199. data/website/static/1.13/guides/upgrading.html +314 -0
  200. data/website/static/1.13/guides/vandal.html +282 -0
  201. data/website/static/1.13/guides/why.html +1121 -0
  202. data/website/static/1.13/index.html +72 -0
  203. data/website/static/1.13/js/authentication.html +295 -0
  204. data/website/static/1.13/js/ddau.html +238 -0
  205. data/website/static/1.13/js/extra-params.html +270 -0
  206. data/website/static/1.13/js/index.html +321 -0
  207. data/website/static/1.13/js/installation.html +637 -0
  208. data/website/static/1.13/js/introduction.html +257 -0
  209. data/website/static/1.13/js/middleware.html +318 -0
  210. data/website/static/1.13/js/reads/fieldsets.html +271 -0
  211. data/website/static/1.13/js/reads/filtering.html +289 -0
  212. data/website/static/1.13/js/reads/includes.html +260 -0
  213. data/website/static/1.13/js/reads/index.html +497 -0
  214. data/website/static/1.13/js/reads/nested-queries.html +353 -0
  215. data/website/static/1.13/js/reads/pagination.html +260 -0
  216. data/website/static/1.13/js/reads/sorting.html +265 -0
  217. data/website/static/1.13/js/reads/statistics.html +289 -0
  218. data/website/static/1.13/js/state-syncing.html +340 -0
  219. data/website/static/1.13/js/writes/deferred.html +296 -0
  220. data/website/static/1.13/js/writes/dirty-tracking.html +399 -0
  221. data/website/static/1.13/js/writes/index.html +391 -0
  222. data/website/static/1.13/js/writes/nested.html +330 -0
  223. data/website/static/1.13/js/writes/validations.html +272 -0
  224. data/website/static/1.13/quickstart.html +660 -0
  225. data/website/static/1.13/template +161 -0
  226. data/website/static/1.13/tutorial/index.html +250 -0
  227. data/website/static/1.13/tutorial/step_0.html +292 -0
  228. data/website/static/1.13/tutorial/step_1.html +517 -0
  229. data/website/static/1.13/tutorial/step_2.html +481 -0
  230. data/website/static/1.13/tutorial/step_3.html +323 -0
  231. data/website/static/1.13/tutorial/step_4.html +318 -0
  232. data/website/static/1.13/tutorial/step_5.html +265 -0
  233. data/website/static/1.13/tutorial/step_6.html +276 -0
  234. data/website/static/1.13/tutorial/step_7.html +390 -0
  235. data/website/static/1.13/tutorial/step_8.html +316 -0
  236. data/website/static/1.13/tutorial/step_9.html +365 -0
  237. data/website/static/assets/img/error_payload.png +0 -0
  238. data/website/static/assets/img/legacy/legacy-0378a3bb39.png +0 -0
  239. data/website/static/assets/img/legacy/legacy-05bbd3e5fd.png +0 -0
  240. data/website/static/assets/img/legacy/legacy-07aa104495.png +0 -0
  241. data/website/static/assets/img/legacy/legacy-0c75a16b3a.gif +0 -0
  242. data/website/static/assets/img/legacy/legacy-3076df6209.png +0 -0
  243. data/website/static/assets/img/legacy/legacy-7f6889bc89.png +0 -0
  244. data/website/static/assets/img/legacy/legacy-a2cc4363c3.png +0 -0
  245. data/website/static/assets/img/legacy/legacy-f67cfa89ab.png +0 -0
  246. data/website/static/assets/img/meta_total_count.png +0 -0
  247. data/website/static/img/docusaurus-social-card.jpg +0 -0
  248. data/website/static/img/docusaurus.png +0 -0
  249. data/website/static/img/favicon.ico +0 -0
  250. data/website/static/img/logo.png +0 -0
  251. data/website/static/img/logo.svg +1 -0
  252. data/website/static/img/undraw_docusaurus_mountain.svg +171 -0
  253. data/website/static/img/undraw_docusaurus_react.svg +170 -0
  254. data/website/static/img/undraw_docusaurus_tree.svg +40 -0
  255. metadata +245 -46
  256. data/gemfiles/rails_6.gemfile +0 -18
  257. data/gemfiles/rails_6_graphiti_rails.gemfile +0 -19
  258. data/gemfiles/rails_7.gemfile +0 -18
  259. data/gemfiles/rails_7_1_graphiti_rails.gemfile +0 -19
  260. data/gemfiles/rails_7_graphiti_rails.gemfile +0 -19
  261. data/lib/graphiti/railtie.rb +0 -121
  262. /data/{deprecated_generators → lib/generators}/graphiti/resource_test_generator.rb +0 -0
  263. /data/{deprecated_generators → lib/generators}/graphiti/templates/application_resource.rb.erb +0 -0
  264. /data/{deprecated_generators → lib/generators}/graphiti/templates/controller.rb.erb +0 -0
  265. /data/{deprecated_generators → lib/generators}/graphiti/templates/create_request_spec.rb.erb +0 -0
  266. /data/{deprecated_generators → lib/generators}/graphiti/templates/destroy_request_spec.rb.erb +0 -0
  267. /data/{deprecated_generators → lib/generators}/graphiti/templates/resource.rb.erb +0 -0
  268. /data/{deprecated_generators → lib/generators}/graphiti/templates/resource_writes_spec.rb.erb +0 -0
  269. /data/{deprecated_generators → lib/generators}/graphiti/templates/update_request_spec.rb.erb +0 -0
@@ -0,0 +1,440 @@
1
+ <!DOCTYPE html>
2
+ <html lang="en">
3
+
4
+ <head>
5
+ <meta charset="utf-8">
6
+ <meta http-equiv="X-UA-Compatible" content="IE=edge">
7
+ <meta name="viewport" content="width=device-width, initial-scale=1">
8
+ <link href="https://fonts.googleapis.com/css?family=Roboto+Mono" rel="stylesheet">
9
+ <link href="https://fonts.googleapis.com/css?family=Boogaloo" rel="stylesheet">
10
+
11
+ <link rel="apple-touch-icon" sizes="180x180" href="/1.13/assets/favicons/apple-touch-icon.png">
12
+ <link rel="icon" type="image/png" sizes="32x32" href="/1.13/assets/favicons/favicon-32x32.png">
13
+ <link rel="icon" type="image/png" sizes="16x16" href="/1.13/assets/favicons/favicon-16x16.png">
14
+ <link rel="manifest" href="/1.13/assets/favicons/site.webmanifest">
15
+ <link rel="mask-icon" href="/1.13/assets/favicons/safari-pinned-tab.svg" color="#F86DA7">
16
+ <link rel="shortcut icon" href="/1.13/assets/favicons/favicon.ico">
17
+ <meta name="msapplication-TileColor" content="#F86DA7">
18
+ <meta name="msapplication-config" content="/1.13/assets/favicons/browserconfig.xml">
19
+ <meta name="theme-color" content="#F86DA7">
20
+
21
+ <title>Graphiti</title>
22
+ <meta name="description" content="Stylish Graph APIs">
23
+
24
+ <link rel="stylesheet" href="/1.13/assets/main.css?ref=wh4t3v45">
25
+ <link rel="alternate" type="application/rss+xml" title="Graphiti" href="/1.13/feed.xml">
26
+
27
+ <!-- Global site tag (gtag.js) - Google Analytics -->
28
+ <script async src="https://www.googletagmanager.com/gtag/js?id=UA-127904727-1"></script>
29
+ <script>
30
+ window.dataLayer = window.dataLayer || [];
31
+ function gtag(){dataLayer.push(arguments);}
32
+ gtag('js', new Date());
33
+
34
+ gtag('config', 'UA-127904727-1');
35
+ </script>
36
+
37
+ <!-- javascript -->
38
+ <script src="https://ajax.googleapis.com/ajax/libs/jquery/1.10.2/jquery.min.js"></script>
39
+ <script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js" integrity="sha384-Tc5IQib027qvyjSMfHjOMaLkfuWVxZxUPnCJA7l2mCWNIpG9mGCD8wGNIcPD7Txa" crossorigin="anonymous"></script>
40
+
41
+
42
+ </head>
43
+
44
+
45
+ <body>
46
+ <main class="page-content" aria-label="Content">
47
+ <div class="wrapper">
48
+ <header class="navbar navbar-inverse normal" role="banner">
49
+ <div class="container">
50
+ <div class="navbar-header">
51
+ <a href="/1.13/1.13" class="navbar-brand">
52
+ <img alt="logo" src="/1.13/assets/img/logo.png">
53
+ </a>
54
+ </div>
55
+ <nav class="" role="navigation">
56
+ <ul class="nav navbar-nav nav-links">
57
+ <li>
58
+ <a class="quickstart nav-link" href="/1.13/quickstart">Quickstart</a>
59
+ </li>
60
+ <li>
61
+ <a class="guides nav-link" href="/1.13/guides">Guides</a>
62
+ </li>
63
+ <li>
64
+ <a class="tutorial nav-link" href="/1.13/tutorial">Tutorial</a>
65
+ </li>
66
+ <li>
67
+ <a class="spraypaint nav-link" href="/1.13/js">Spraypaint</a>
68
+ </li>
69
+ </ul>
70
+ <ul class="nav gh navbar-nav navbar-right visible-lg visible-md">
71
+ <li>
72
+ <span class="star">⭐</span>
73
+ <a href="https://github.com/graphiti-api/graphiti">
74
+ <img alt="github-star" style="margin-right: 65px;margin-top: -20px" src="/1.13/assets/img/gh.png">
75
+ </a>
76
+ </li>
77
+ </ul>
78
+ </nav>
79
+ </div>
80
+ </header>
81
+
82
+ <div class="container">
83
+ <div class="toc col-md-3">
84
+ <h1 id="debugging">Debugging</h1>
85
+
86
+ <ul>
87
+ <li>1 <a href="#debugger">Debugger</a>
88
+ <ul>
89
+ <li><a href="#json-output">JSON Output</a></li>
90
+ <li><a href="#configuration">Configuration</a></li>
91
+ </ul>
92
+ </li>
93
+ <li>2 <a href="#rake-tasks">Rake Tasks</a>
94
+ <ul>
95
+ <li><a href="#graphiti-request">graphiti:request</a></li>
96
+ <li><a href="#graphiti-benchmark">graphiti:benchmark</a></li>
97
+ <li><a href="#Authorization-headers">Authorization headers</a></li>
98
+ </ul>
99
+ </li>
100
+ <li>3 <a href="#tips">Tips</a></li>
101
+ </ul>
102
+
103
+ </div>
104
+
105
+ <div class="col-md-8">
106
+
107
+ <a class="anchor" id="debugger" />
108
+ <a class="header" href="#debugger">
109
+ <h2>
110
+ Debugger
111
+ </h2>
112
+ </a>
113
+
114
+ <p>Graphiti comes with a debugger that shows the queries executed for a
115
+ given request. Remember that Resources <a href="/1.13/guides/concepts/resources#query-interface">have a query interface</a> independent of a request or response. And Resources connect similar to ActiveRecord’s <code class="language-plaintext highlighter-rouge">includes</code>:</p>
116
+
117
+ <figure class="highlight"><pre><code class="language-ruby" data-lang="ruby"><span class="n">employees</span> <span class="o">=</span> <span class="no">EmployeeResource</span><span class="p">.</span><span class="nf">all</span>
118
+ <span class="no">PositionResource</span><span class="p">.</span><span class="nf">all</span><span class="p">(</span><span class="ss">filter: </span><span class="p">{</span> <span class="ss">employee_id: </span><span class="n">employees</span><span class="p">.</span><span class="nf">map</span><span class="p">(</span><span class="o">&amp;</span><span class="ss">:id</span><span class="p">)</span> <span class="p">})</span></code></pre></figure>
119
+
120
+ <blockquote>
121
+ <p><em>Remember, this is all <a href="/1.13/guides/concepts/resources#customizing-relationships">customizable</a></em>.</p>
122
+ </blockquote>
123
+
124
+ <p>That means we can log the requests made by individual Resources:</p>
125
+
126
+ <p><code class="language-plaintext highlighter-rouge">/api/v1/employees?include=notes,positions.department.teams</code></p>
127
+ <p align="center">
128
+ <img width="100%" src="https://user-images.githubusercontent.com/55264/46084994-f5425e00-c172-11e8-8c40-aa7074e6dc6d.png" />
129
+ </p>
130
+
131
+ <p>And even copy/paste these queries into a console session to debug:</p>
132
+
133
+ <figure class="highlight"><pre><code class="language-bash" data-lang="bash"><span class="nv">$ </span>bin/rails c
134
+ <span class="o">&gt;&gt;</span> TeamResource.all<span class="o">({</span>:filter<span class="o">=&gt;{</span>:department_id<span class="o">=&gt;</span><span class="s2">"1,2,3"</span><span class="o">}})</span></code></pre></figure>
135
+
136
+ <p>If you’re having trouble with a request, see if you can isolate to a
137
+ specific Resource, then test that Resource directly.</p>
138
+
139
+ <p>Finally: if an error occurs, we’ll note the query that caused it:</p>
140
+
141
+ <p align="center">
142
+ <img width="100%" src="https://user-images.githubusercontent.com/55264/46086595-6c2d2600-c176-11e8-9b57-1b27d380e9fe.png" />
143
+ </p>
144
+
145
+ <a class="anchor" id="json-output" />
146
+ <a class="header" href="#json-output">
147
+ <h3>
148
+ JSON Output
149
+ </h3>
150
+ </a>
151
+
152
+ <p>It can be helpful to have this debug output come back as part of the
153
+ JSON response. To enable this:</p>
154
+
155
+ <figure class="highlight"><pre><code class="language-ruby" data-lang="ruby"><span class="c1"># app/controllers/application_controller.rb</span>
156
+ <span class="k">def</span> <span class="nf">allow_graphiti_debug_json?</span>
157
+ <span class="kp">true</span>
158
+ <span class="c1"># or, current_user.admin?</span>
159
+ <span class="c1"># or, Rails.env.development?</span>
160
+ <span class="k">end</span></code></pre></figure>
161
+
162
+ <p>And request the debug output:</p>
163
+
164
+ <p><code class="language-plaintext highlighter-rouge">/your/url?debug=true</code></p>
165
+
166
+ <p>You should now see the debug output in <code class="language-plaintext highlighter-rouge">meta</code>:</p>
167
+
168
+ <p align="center">
169
+ <img width="100%" src="https://user-images.githubusercontent.com/55264/46085006-fe332f80-c172-11e8-946e-bf1386362a90.png" />
170
+ </p>
171
+
172
+ <p><br /></p>
173
+
174
+ <p>If there’s an error, and you’ve <a href="/1.13/guides/concepts/error-handling#displaying-raw-errors">enabled raw errors</a>, you’ll also see the query that caused the error in the JSON response:</p>
175
+
176
+ <p><br /></p>
177
+
178
+ <p align="center">
179
+ <img width="100%" src="https://user-images.githubusercontent.com/55264/46086370-ef01b100-c175-11e8-81b9-917d95e195c7.png" />
180
+ </p>
181
+
182
+ <p><br /></p>
183
+
184
+ <a class="anchor" id="configuration" />
185
+ <a class="header" href="#configuration">
186
+ <h3>
187
+ 1.2 Configuration
188
+ </h3>
189
+ </a>
190
+
191
+ <p>By default, we’ll log to <code class="language-plaintext highlighter-rouge">Rails.logger</code>, and only enable debugging (logs
192
+ or JSON) when <code class="language-plaintext highlighter-rouge">Rails.logger.level</code> is set to <code class="language-plaintext highlighter-rouge">debug</code>. Here are the
193
+ various ways to configure.</p>
194
+
195
+ <p>Use <code class="language-plaintext highlighter-rouge">config.debug</code> to explicitly toggle debugging:</p>
196
+
197
+ <figure class="highlight"><pre><code class="language-ruby" data-lang="ruby"><span class="c1"># config/initializers/graphiti.rb</span>
198
+ <span class="no">Graphiti</span><span class="p">.</span><span class="nf">configure</span> <span class="k">do</span> <span class="o">|</span><span class="n">c</span><span class="o">|</span>
199
+ <span class="n">c</span><span class="p">.</span><span class="nf">debug</span> <span class="o">=</span> <span class="kp">false</span>
200
+ <span class="k">end</span>
201
+
202
+ <span class="c1"># Or use environment variable</span>
203
+ <span class="c1"># GRAPHITI_DEBUG=false</span></code></pre></figure>
204
+
205
+ <p>Use <code class="language-plaintext highlighter-rouge">config.debug_models</code> to get additional (but verbose) output:</p>
206
+
207
+ <p align="center">
208
+ <img width="100%" src="https://user-images.githubusercontent.com/55264/46088701-ef507b00-c17a-11e8-8d26-af17b19b8ce9.png" />
209
+ </p>
210
+
211
+ <figure class="highlight"><pre><code class="language-ruby" data-lang="ruby"><span class="c1"># config/initializers/graphiti.rb</span>
212
+ <span class="no">Graphiti</span><span class="p">.</span><span class="nf">configure</span> <span class="k">do</span> <span class="o">|</span><span class="n">c</span><span class="o">|</span>
213
+ <span class="n">c</span><span class="p">.</span><span class="nf">debug_models</span> <span class="o">=</span> <span class="kp">true</span>
214
+ <span class="k">end</span>
215
+
216
+ <span class="c1"># Or use environment variable</span>
217
+ <span class="c1"># GRAPHITI_DEBUG_MODELS=true</span></code></pre></figure>
218
+
219
+ <p>As noted above, <code class="language-plaintext highlighter-rouge">allow_graphiti_debug_json?</code> must return <code class="language-plaintext highlighter-rouge">true</code> if you
220
+ want JSON output:</p>
221
+
222
+ <figure class="highlight"><pre><code class="language-ruby" data-lang="ruby"><span class="c1"># app/controllers/application_controller.rb</span>
223
+ <span class="k">def</span> <span class="nf">allow_graphiti_debug_json?</span>
224
+ <span class="kp">true</span>
225
+ <span class="c1"># or, current_user.admin?</span>
226
+ <span class="c1"># or, Rails.env.development?</span>
227
+ <span class="k">end</span></code></pre></figure>
228
+
229
+ <p>Note you need to explicitly pass <code class="language-plaintext highlighter-rouge">?debug=true</code> in the request.</p>
230
+
231
+ <p>Assign a different logger:</p>
232
+
233
+ <figure class="highlight"><pre><code class="language-ruby" data-lang="ruby"><span class="no">Graphiti</span><span class="p">.</span><span class="nf">logger</span> <span class="o">=</span> <span class="no">Logger</span><span class="p">.</span><span class="nf">new</span><span class="p">(</span><span class="o">...</span><span class="p">)</span>
234
+
235
+ <span class="c1"># Or the built-in STDOUT logger:</span>
236
+ <span class="no">Graphiti</span><span class="p">.</span><span class="nf">logger</span> <span class="o">=</span> <span class="no">Graphiti</span><span class="p">.</span><span class="nf">stdout_logger</span></code></pre></figure>
237
+
238
+ <p>Manually apply the debugging (when using Rails, this normally happens in
239
+ a <code class="language-plaintext highlighter-rouge">around_action</code>):</p>
240
+
241
+ <figure class="highlight"><pre><code class="language-ruby" data-lang="ruby"><span class="no">Graphiti</span><span class="o">::</span><span class="no">Debugger</span><span class="p">.</span><span class="nf">debug</span> <span class="k">do</span>
242
+ <span class="no">EmployeeResource</span><span class="p">.</span><span class="nf">all</span>
243
+ <span class="k">end</span></code></pre></figure>
244
+
245
+ <a class="anchor" id="rake-tasks" />
246
+ <a class="header" href="#rake-tasks">
247
+ <h3>
248
+ 2 Rake Tasks
249
+ </h3>
250
+ </a>
251
+
252
+ <p>There are some common debugging scenarios that are possible to do
253
+ manually, but their frequency warrants common patterns. For these, we
254
+ have rake tasks.</p>
255
+
256
+ <a class="anchor" id="graphiti-request" />
257
+ <a class="header" href="#graphiti-request">
258
+ <h4>
259
+ 2.1 graphiti:request
260
+ </h4>
261
+ </a>
262
+
263
+ <blockquote>
264
+ <p><code class="language-plaintext highlighter-rouge">bin/rake graphiti:request[PATH,DEBUG]</code></p>
265
+ </blockquote>
266
+
267
+ <p>Execute a request using <code class="language-plaintext highlighter-rouge">ActionDispatch::Integration::Session</code> (which
268
+ underlies request specs).</p>
269
+
270
+ <p>This can be helpful when you don’t have, or don’t want to spin up, a web
271
+ server. Imagine you want to debug something on production, so you shell
272
+ into a docker container and edit some files locally. Now you want to
273
+ execute a request and see if your changes worked:</p>
274
+
275
+ <figure class="highlight"><pre><code class="language-bash" data-lang="bash"><span class="nv">$ </span>bin/rake graphiti:request[/employees]</code></pre></figure>
276
+
277
+ <p>Will execute the request and spit out the JSON response. You may want to
278
+ run with the Debugger enabled:</p>
279
+
280
+ <figure class="highlight"><pre><code class="language-bash" data-lang="bash"><span class="nv">$ </span>bin/rake graphiti:request[/employees,true]</code></pre></figure>
281
+
282
+ <p>Which add Debugger output as well.</p>
283
+
284
+ <p>The <code class="language-plaintext highlighter-rouge">PATH</code> should not contain the domain unless you want to hit a live
285
+ API instead of a test server.</p>
286
+
287
+ <a class="anchor" id="graphiti-benchmark" />
288
+ <a class="header" href="#graphiti-benchmark">
289
+ <h4>
290
+ 2.2 graphiti:benchmark
291
+ </h4>
292
+ </a>
293
+
294
+ <blockquote>
295
+ <p><code class="language-plaintext highlighter-rouge">bin/rake graphiti:benchmark[PATH,NUM_REQUESTS]</code></p>
296
+ </blockquote>
297
+
298
+ <p>It can be helpful to run a quick benchmark without hitting a live web
299
+ server, to eliminate the vagaries of latency. To do this:</p>
300
+
301
+ <figure class="highlight"><pre><code class="language-bash" data-lang="bash"><span class="nv">$ </span>bin/rake graphiti:benchmark[/employees,100]</code></pre></figure>
302
+
303
+ <p>Which will return the average response time.</p>
304
+
305
+ <a class="anchor" id="Authorization-headers" />
306
+ <a class="header" href="#Authorization-headers">
307
+ <h4>
308
+ 2.3 Authorization headers
309
+ </h4>
310
+ </a>
311
+
312
+ <p>If you have an Authorization scheme implemented (for example <a href="https://api.rubyonrails.org/classes/ActionController/HttpAuthentication/Token.html">authenticate_or_request_with_http_token</a> in rails) you can supply the <code class="language-plaintext highlighter-rouge">Authorization</code> http header value with the <code class="language-plaintext highlighter-rouge">AUTHORIZATION_HEADER</code> environment variable:</p>
313
+
314
+ <figure class="highlight"><pre><code class="language-bash" data-lang="bash"><span class="nv">$ </span><span class="nb">export </span><span class="nv">AUTHORIZATION_HEADER</span><span class="o">=</span><span class="s2">"Token --PRIVATE_API_KEY--"</span>
315
+ <span class="nv">$ </span>bin/rake graphiti:request[/employees,true]</code></pre></figure>
316
+
317
+ <p>This also will work for <code class="language-plaintext highlighter-rouge">Basic</code> (<a href="https://api.rubyonrails.org/classes/ActionController/HttpAuthentication/Basic.html$$">request_http_basic_authentication</a>) and <code class="language-plaintext highlighter-rouge">Bearer</code> values</p>
318
+
319
+ <a class="anchor" id="tips" />
320
+ <a class="header" href="#tips">
321
+ <h2>
322
+ 3 Tips
323
+ </h2>
324
+ </a>
325
+
326
+ <p>When debugging an application, try to isolate the individual Resource
327
+ call and debug the Resource directly (instead of running the entire
328
+ request). This helps eliminate variables, and plain ruby code is easier
329
+ to work with. If possible, try to remove Graphiti entirely and focus on
330
+ your Models and Backends.</p>
331
+
332
+ <p>The most common scenario is debugging a query. We suggest overriding
333
+ <code class="language-plaintext highlighter-rouge">resolve</code> and using <a href="https://github.com/pry/pry">pry</a> (or equivalent):</p>
334
+
335
+ <figure class="highlight"><pre><code class="language-ruby" data-lang="ruby"><span class="c1"># Introspect the scope without firing a query</span>
336
+ <span class="c1"># Call 'super' to fire the query</span>
337
+ <span class="k">def</span> <span class="nf">resolve</span><span class="p">(</span><span class="n">scope</span><span class="p">)</span>
338
+ <span class="nb">binding</span><span class="p">.</span><span class="nf">pry</span>
339
+ <span class="k">end</span></code></pre></figure>
340
+
341
+ <p><br />
342
+ <br /></p>
343
+
344
+ </div>
345
+
346
+ </div>
347
+ </div>
348
+ </main>
349
+ <div class="main-footer main-footer--dark">
350
+ <div class="container">
351
+ <div class="row">
352
+ <div class="col-sm-4 menu">
353
+ <h3>Overview</h3>
354
+ <ul>
355
+ <li>
356
+ <a href="/1.13/quickstart">Quickstart</a>
357
+ </li>
358
+ <li>
359
+ <a href="/1.13/tutorial">Tutorial</a>
360
+ </li>
361
+ <li>
362
+ <a href="/1.13/guides">Guides</a>
363
+ </li>
364
+ </ul>
365
+ </div>
366
+ <div class="col-sm-4 menu">
367
+ <h3>Contact</h3>
368
+ <ul>
369
+ <li>
370
+ <a target="_blank" href="https://discord.gg/wgqkMBsSRV">Discord Chat</a>
371
+ </li>
372
+ <li>
373
+ <a href="mailto:richmolj@gmail.com">Email</a>
374
+ </li>
375
+ </ul>
376
+ </div>
377
+ <div class="col-sm-4 menu">
378
+ <h3>Related</h3>
379
+ <ul>
380
+ <li>
381
+ <a target="_blank" href="http://jsonapi.org">JSONAPI Spec</a>
382
+ </li>
383
+ <li>
384
+ <a target="_blank" href="http://jsonapi-rb.org">jsonapi-rb</a>
385
+ </li>
386
+ <li>
387
+ <a target="_blank" href="https://vuejs.org/">VueJS</a>
388
+ </li>
389
+ </ul>
390
+ </div>
391
+ </div>
392
+ </div>
393
+ </div>
394
+
395
+ <script type="text/javascript">
396
+ $(function () {
397
+
398
+ var flipTabs = function() {
399
+ var isTS = true;
400
+ if (localStorage.getItem('js-lang') === 'javascript') {
401
+ isTS = false;
402
+ }
403
+
404
+ $('.code-tabs').each(function(index, el) {
405
+ if (isTS) {
406
+ console.log('hiding js');
407
+ $($(el).children()[1]).hide();
408
+ $($(el).children()[0]).show();
409
+ } else {
410
+ console.log('hiding ts');
411
+ $($(el).children()[0]).hide();
412
+ $($(el).children()[1]).show();
413
+ }
414
+ });
415
+
416
+ if (isTS) {
417
+ $('.tab.typescript').addClass('active');
418
+ $('.tab.javascript').removeClass('active');
419
+ } else {
420
+ $('.tab.typescript').removeClass('active');
421
+ $('.tab.javascript').addClass('active');
422
+ }
423
+ }
424
+
425
+ $('.tab').click(function() {
426
+ if ($(this).hasClass('typescript')) {
427
+ localStorage.setItem('js-lang', 'typescript');
428
+ } else {
429
+ localStorage.setItem('js-lang', 'javascript');
430
+ }
431
+
432
+ flipTabs();
433
+ });
434
+
435
+ flipTabs();
436
+ })
437
+ </script>
438
+
439
+ </body>
440
+ </html>