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.
- checksums.yaml +4 -4
- data/.github/workflows/ci.yml +30 -86
- data/.github/workflows/docs.yml +60 -0
- data/.github/workflows/release.yml +8 -8
- data/.gitignore +7 -0
- data/.npmrc +9 -0
- data/.standard.yml +4 -1
- data/Appraisals +33 -32
- data/CHANGELOG.md +41 -0
- data/README.md +13 -2
- data/UPGRADING.md +2 -68
- data/docs/concepts/backends-and-models.md +122 -0
- data/docs/concepts/endpoints.md +183 -0
- data/docs/concepts/links.md +212 -0
- data/docs/concepts/overview.md +80 -0
- data/docs/concepts/persisting.md +376 -0
- data/docs/concepts/relationships.md +527 -0
- data/docs/concepts/resources.md +677 -0
- data/docs/getting-started/first-api.md +289 -0
- data/docs/getting-started/installation.md +185 -0
- data/docs/intro.md +307 -0
- data/docs/js/authentication.md +63 -0
- data/docs/js/ddau.md +20 -0
- data/docs/js/extra-params.md +41 -0
- data/docs/js/index.md +112 -0
- data/docs/js/installation.md +120 -0
- data/docs/js/middleware.md +72 -0
- data/docs/js/models.md +202 -0
- data/docs/js/reads.md +494 -0
- data/docs/js/state-syncing.md +100 -0
- data/docs/js/writes.md +373 -0
- data/docs/reference/vandal.md +63 -0
- data/docs/reference/why.md +13 -0
- data/docs/topics/authorization.md +155 -0
- data/docs/topics/caching.md +55 -0
- data/docs/topics/customizing-sideloads.md +156 -0
- data/docs/topics/debugging.md +216 -0
- data/docs/topics/error-handling.md +210 -0
- data/docs/topics/etags.md +46 -0
- data/docs/topics/hopping-relationships.md +149 -0
- data/docs/topics/json-attributes.md +77 -0
- data/docs/topics/openstruct-models.md +50 -0
- data/docs/topics/remote-resources.md +291 -0
- data/docs/topics/testing.md +894 -0
- data/docs/topics/without-activerecord.md +324 -0
- data/docs/tutorial/index.md +58 -0
- data/docs/tutorial/step_0.md +107 -0
- data/docs/tutorial/step_1.md +199 -0
- data/docs/tutorial/step_2.md +312 -0
- data/docs/tutorial/step_3.md +142 -0
- data/docs/tutorial/step_4.md +135 -0
- data/docs/tutorial/step_5.md +69 -0
- data/docs/tutorial/step_6.md +82 -0
- data/docs/tutorial/step_7.md +205 -0
- data/docs/tutorial/step_8.md +128 -0
- data/docs/tutorial/step_9.md +171 -0
- data/docs/upgrading.md +265 -0
- data/gemfiles/rails_7_1.gemfile +4 -3
- data/gemfiles/{rails_7_2_graphiti_rails.gemfile → rails_7_2.gemfile} +3 -3
- data/gemfiles/{rails_8_1_graphiti_rails.gemfile → rails_8_0.gemfile} +3 -3
- data/gemfiles/{rails_8_0_graphiti_rails.gemfile → rails_8_1.gemfile} +3 -3
- data/graphiti.gemspec +7 -5
- data/{deprecated_generators → lib/generators}/graphiti/api_test_generator.rb +7 -1
- data/{deprecated_generators → lib/generators}/graphiti/generator_mixin.rb +14 -1
- data/{deprecated_generators → lib/generators}/graphiti/install_generator.rb +19 -13
- data/{deprecated_generators → lib/generators}/graphiti/resource_generator.rb +43 -6
- data/{deprecated_generators → lib/generators}/graphiti/templates/index_request_spec.rb.erb +1 -1
- data/{deprecated_generators → lib/generators}/graphiti/templates/resource_reads_spec.rb.erb +6 -6
- data/{deprecated_generators → lib/generators}/graphiti/templates/show_request_spec.rb.erb +1 -1
- data/lib/graphiti/configuration.rb +2 -2
- data/lib/graphiti/error_serializers/conflict_request.rb +19 -0
- data/lib/graphiti/error_serializers/deprecated_constants.rb +48 -0
- data/lib/graphiti/error_serializers/invalid_request.rb +56 -0
- data/lib/graphiti/error_serializers/validation.rb +143 -0
- data/lib/graphiti/errors.rb +4 -23
- data/lib/graphiti/query.rb +1 -1
- data/lib/graphiti/rails/context.rb +33 -0
- data/lib/graphiti/rails/controller.rb +41 -0
- data/lib/graphiti/rails/debugging.rb +18 -0
- data/lib/graphiti/rails/exception_handlers.rb +77 -0
- data/lib/graphiti/rails/railtie.rb +139 -0
- data/lib/graphiti/rails/responders.rb +21 -0
- data/lib/graphiti/rails/test_helpers.rb +22 -0
- data/lib/graphiti/rails.rb +47 -29
- data/lib/graphiti/resource/configuration.rb +1 -0
- data/lib/graphiti/resource/interface.rb +2 -2
- data/lib/graphiti/resource/persistence.rb +14 -2
- data/lib/graphiti/resource/remote.rb +2 -2
- data/lib/graphiti/resource/sideloading.rb +1 -1
- data/lib/graphiti/resource.rb +13 -1
- data/lib/graphiti/responders.rb +7 -20
- data/lib/graphiti/schema.rb +5 -1
- data/lib/graphiti/schema_diff.rb +4 -0
- data/lib/graphiti/scope.rb +45 -37
- data/lib/graphiti/serializer.rb +6 -0
- data/lib/graphiti/sideload/belongs_to.rb +38 -5
- data/lib/graphiti/sideload/polymorphic_belongs_to.rb +27 -23
- data/lib/graphiti/sideload.rb +54 -35
- data/lib/graphiti/spec_helpers/errors.rb +73 -0
- data/lib/graphiti/spec_helpers/errors_proxy.rb +75 -0
- data/lib/graphiti/spec_helpers/helpers.rb +107 -0
- data/lib/graphiti/spec_helpers/node.rb +88 -0
- data/lib/graphiti/spec_helpers/rspec.rb +147 -0
- data/lib/graphiti/spec_helpers.rb +53 -0
- data/lib/graphiti/util/include_params.rb +2 -2
- data/lib/graphiti/util/persistence.rb +10 -11
- data/lib/graphiti/util/serializer_relationships.rb +41 -5
- data/lib/graphiti/version.rb +1 -1
- data/lib/graphiti-rails.rb +11 -0
- data/lib/graphiti.rb +34 -10
- data/lib/graphiti_errors.rb +11 -0
- data/lib/graphiti_spec_helpers/rspec.rb +3 -0
- data/lib/graphiti_spec_helpers.rb +11 -0
- data/lib/{graphiti/deprecated_tasks.rb → tasks/graphiti.rake} +6 -1
- data/package-lock.json +6199 -0
- data/package.json +5 -4
- data/website/.gitignore +20 -0
- data/website/README.md +43 -0
- data/website/docusaurus.config.js +141 -0
- data/website/package-lock.json +19474 -0
- data/website/package.json +46 -0
- data/website/sidebars.js +82 -0
- data/website/src/css/custom.css +58 -0
- data/website/src/pages/markdown-page.mdx +7 -0
- data/website/static/.nojekyll +0 -0
- data/website/static/1.13/2019/03/31/graphiti-1-0.html +205 -0
- data/website/static/1.13/2019/05/08/graphiti-1-1.html +212 -0
- data/website/static/1.13/2019/05/20/graphiti-1-2.html +214 -0
- data/website/static/1.13/2019/10/14/tutorial.html +198 -0
- data/website/static/1.13/CNAME +1 -0
- data/website/static/1.13/README.md +16 -0
- data/website/static/1.13/assets/css/syntax.css +60 -0
- data/website/static/1.13/assets/favicons/android-chrome-192x192.png +0 -0
- data/website/static/1.13/assets/favicons/android-chrome-256x256.png +0 -0
- data/website/static/1.13/assets/favicons/apple-touch-icon.png +0 -0
- data/website/static/1.13/assets/favicons/browserconfig.xml +9 -0
- data/website/static/1.13/assets/favicons/favicon-16x16.png +0 -0
- data/website/static/1.13/assets/favicons/favicon-32x32.png +0 -0
- data/website/static/1.13/assets/favicons/favicon.ico +0 -0
- data/website/static/1.13/assets/favicons/mstile-150x150.png +0 -0
- data/website/static/1.13/assets/favicons/safari-pinned-tab.svg +1 -0
- data/website/static/1.13/assets/favicons/site.webmanifest +19 -0
- data/website/static/1.13/assets/img/backend.gif +0 -0
- data/website/static/1.13/assets/img/conformity.png +0 -0
- data/website/static/1.13/assets/img/error_payload.png +0 -0
- data/website/static/1.13/assets/img/gh.png +0 -0
- data/website/static/1.13/assets/img/lifecycle.gif +0 -0
- data/website/static/1.13/assets/img/logo-500.png +0 -0
- data/website/static/1.13/assets/img/logo.png +0 -0
- data/website/static/1.13/assets/img/love-graffiti.jpg +0 -0
- data/website/static/1.13/assets/img/meta_total_count.png +0 -0
- data/website/static/1.13/assets/img/persist.jpg +0 -0
- data/website/static/1.13/assets/img/resource.gif +0 -0
- data/website/static/1.13/assets/img/rest-graffiti.jpg +0 -0
- data/website/static/1.13/assets/img/rest1.gif +0 -0
- data/website/static/1.13/assets/img/rest2.gif +0 -0
- data/website/static/1.13/assets/img/rest3.gif +0 -0
- data/website/static/1.13/assets/img/rethink-rest-graffiti.jpg +0 -0
- data/website/static/1.13/assets/img/why.png +0 -0
- data/website/static/1.13/assets/js/highlight.pack.js +2 -0
- data/website/static/1.13/assets/main.css +15518 -0
- data/website/static/1.13/assets/main.css.map +1 -0
- data/website/static/1.13/bin/bundle +109 -0
- data/website/static/1.13/bin/jekyll +27 -0
- data/website/static/1.13/bin/kramdown +27 -0
- data/website/static/1.13/bin/listen +27 -0
- data/website/static/1.13/bin/rake +27 -0
- data/website/static/1.13/bin/rougify +27 -0
- data/website/static/1.13/bin/safe_yaml +27 -0
- data/website/static/1.13/bin/sass +27 -0
- data/website/static/1.13/bin/sass-convert +27 -0
- data/website/static/1.13/bin/scss +27 -0
- data/website/static/1.13/blog.html +259 -0
- data/website/static/1.13/cheatsheet.html +316 -0
- data/website/static/1.13/cookbooks/authorization.md +0 -0
- data/website/static/1.13/cookbooks/caching.md +0 -0
- data/website/static/1.13/cookbooks/customizing-sideloads.html +325 -0
- data/website/static/1.13/cookbooks/etags.md +0 -0
- data/website/static/1.13/cookbooks/hopping-relationships.html +324 -0
- data/website/static/1.13/cookbooks/json_attributes.md +0 -0
- data/website/static/1.13/cookbooks/openstruct-models.md +0 -0
- data/website/static/1.13/cookbooks/remote-resources.md +0 -0
- data/website/static/1.13/cookbooks/without-activerecord.html +510 -0
- data/website/static/1.13/features.html +249 -0
- data/website/static/1.13/feed.xml +106 -0
- data/website/static/1.13/guides/concepts/backends-and-models.html +467 -0
- data/website/static/1.13/guides/concepts/debugging.html +440 -0
- data/website/static/1.13/guides/concepts/endpoints.html +432 -0
- data/website/static/1.13/guides/concepts/error-handling.html +396 -0
- data/website/static/1.13/guides/concepts/links.html +501 -0
- data/website/static/1.13/guides/concepts/remote-resources.html +536 -0
- data/website/static/1.13/guides/concepts/resources.html +2176 -0
- data/website/static/1.13/guides/concepts/testing.html +1469 -0
- data/website/static/1.13/guides/getting-started/installation.html +420 -0
- data/website/static/1.13/guides/graphiti-rails-migration.html +242 -0
- data/website/static/1.13/guides/index.html +269 -0
- data/website/static/1.13/guides/overview.html +325 -0
- data/website/static/1.13/guides/upgrading-2-0.html +193 -0
- data/website/static/1.13/guides/upgrading.html +314 -0
- data/website/static/1.13/guides/vandal.html +282 -0
- data/website/static/1.13/guides/why.html +1121 -0
- data/website/static/1.13/index.html +72 -0
- data/website/static/1.13/js/authentication.html +295 -0
- data/website/static/1.13/js/ddau.html +238 -0
- data/website/static/1.13/js/extra-params.html +270 -0
- data/website/static/1.13/js/index.html +321 -0
- data/website/static/1.13/js/installation.html +637 -0
- data/website/static/1.13/js/introduction.html +257 -0
- data/website/static/1.13/js/middleware.html +318 -0
- data/website/static/1.13/js/reads/fieldsets.html +271 -0
- data/website/static/1.13/js/reads/filtering.html +289 -0
- data/website/static/1.13/js/reads/includes.html +260 -0
- data/website/static/1.13/js/reads/index.html +497 -0
- data/website/static/1.13/js/reads/nested-queries.html +353 -0
- data/website/static/1.13/js/reads/pagination.html +260 -0
- data/website/static/1.13/js/reads/sorting.html +265 -0
- data/website/static/1.13/js/reads/statistics.html +289 -0
- data/website/static/1.13/js/state-syncing.html +340 -0
- data/website/static/1.13/js/writes/deferred.html +296 -0
- data/website/static/1.13/js/writes/dirty-tracking.html +399 -0
- data/website/static/1.13/js/writes/index.html +391 -0
- data/website/static/1.13/js/writes/nested.html +330 -0
- data/website/static/1.13/js/writes/validations.html +272 -0
- data/website/static/1.13/quickstart.html +660 -0
- data/website/static/1.13/template +161 -0
- data/website/static/1.13/tutorial/index.html +250 -0
- data/website/static/1.13/tutorial/step_0.html +292 -0
- data/website/static/1.13/tutorial/step_1.html +517 -0
- data/website/static/1.13/tutorial/step_2.html +481 -0
- data/website/static/1.13/tutorial/step_3.html +323 -0
- data/website/static/1.13/tutorial/step_4.html +318 -0
- data/website/static/1.13/tutorial/step_5.html +265 -0
- data/website/static/1.13/tutorial/step_6.html +276 -0
- data/website/static/1.13/tutorial/step_7.html +390 -0
- data/website/static/1.13/tutorial/step_8.html +316 -0
- data/website/static/1.13/tutorial/step_9.html +365 -0
- data/website/static/assets/img/error_payload.png +0 -0
- data/website/static/assets/img/legacy/legacy-0378a3bb39.png +0 -0
- data/website/static/assets/img/legacy/legacy-05bbd3e5fd.png +0 -0
- data/website/static/assets/img/legacy/legacy-07aa104495.png +0 -0
- data/website/static/assets/img/legacy/legacy-0c75a16b3a.gif +0 -0
- data/website/static/assets/img/legacy/legacy-3076df6209.png +0 -0
- data/website/static/assets/img/legacy/legacy-7f6889bc89.png +0 -0
- data/website/static/assets/img/legacy/legacy-a2cc4363c3.png +0 -0
- data/website/static/assets/img/legacy/legacy-f67cfa89ab.png +0 -0
- data/website/static/assets/img/meta_total_count.png +0 -0
- data/website/static/img/docusaurus-social-card.jpg +0 -0
- data/website/static/img/docusaurus.png +0 -0
- data/website/static/img/favicon.ico +0 -0
- data/website/static/img/logo.png +0 -0
- data/website/static/img/logo.svg +1 -0
- data/website/static/img/undraw_docusaurus_mountain.svg +171 -0
- data/website/static/img/undraw_docusaurus_react.svg +170 -0
- data/website/static/img/undraw_docusaurus_tree.svg +40 -0
- metadata +245 -46
- data/gemfiles/rails_6.gemfile +0 -18
- data/gemfiles/rails_6_graphiti_rails.gemfile +0 -19
- data/gemfiles/rails_7.gemfile +0 -18
- data/gemfiles/rails_7_1_graphiti_rails.gemfile +0 -19
- data/gemfiles/rails_7_graphiti_rails.gemfile +0 -19
- data/lib/graphiti/railtie.rb +0 -121
- /data/{deprecated_generators → lib/generators}/graphiti/resource_test_generator.rb +0 -0
- /data/{deprecated_generators → lib/generators}/graphiti/templates/application_resource.rb.erb +0 -0
- /data/{deprecated_generators → lib/generators}/graphiti/templates/controller.rb.erb +0 -0
- /data/{deprecated_generators → lib/generators}/graphiti/templates/create_request_spec.rb.erb +0 -0
- /data/{deprecated_generators → lib/generators}/graphiti/templates/destroy_request_spec.rb.erb +0 -0
- /data/{deprecated_generators → lib/generators}/graphiti/templates/resource.rb.erb +0 -0
- /data/{deprecated_generators → lib/generators}/graphiti/templates/resource_writes_spec.rb.erb +0 -0
- /data/{deprecated_generators → lib/generators}/graphiti/templates/update_request_spec.rb.erb +0 -0
|
@@ -0,0 +1,325 @@
|
|
|
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
|
+
<h2 id="2-lifecycle-of-a-graphiti-request">2 Lifecycle of a Graphiti Request</h2>
|
|
84
|
+
|
|
85
|
+
<p align="center">
|
|
86
|
+
<img width="100%" src="/1.13/assets/img/lifecycle.gif" />
|
|
87
|
+
</p>
|
|
88
|
+
|
|
89
|
+
<p><br /></p>
|
|
90
|
+
|
|
91
|
+
<p>The key concept here is a <strong>Resource</strong>. <a href="/1.13/guides/concepts/resources">Resources</a> sit between a Request and a Backend, defining how to <strong><em>query</em></strong>, <strong><em>persist</em></strong>, and <strong><em>serialize</em></strong> data. They are accessible through <strong><a href="/1.13/guides/concepts/endpoints">Endpoints</a></strong>, which customize Resource behavior based on context.</p>
|
|
92
|
+
|
|
93
|
+
<p><br /></p>
|
|
94
|
+
|
|
95
|
+
<p align="center">
|
|
96
|
+
<img width="100%" src="/1.13/assets/img/resource.gif" />
|
|
97
|
+
</p>
|
|
98
|
+
|
|
99
|
+
<p>Each Resource is comprised of <strong>Attributes</strong>. Each Attribute corresponds to behavior for:</p>
|
|
100
|
+
|
|
101
|
+
<ul>
|
|
102
|
+
<li><strong>Reading</strong>: The fields rendered in the response, e.g. <code class="language-plaintext highlighter-rouge">{ "first_name": "Jane" }</code></li>
|
|
103
|
+
<li><strong>Writing</strong>: The fields accepted in the payload, e.g. a POST or PUT request.</li>
|
|
104
|
+
<li><strong>Filtering</strong>: The fields we can query, e.g. <code class="language-plaintext highlighter-rouge">/employees?filter[first_name]=Jane</code></li>
|
|
105
|
+
<li><strong>Sorting</strong>: The fields we can sort on, e.g. <code class="language-plaintext highlighter-rouge">/employees?sort=age</code></li>
|
|
106
|
+
</ul>
|
|
107
|
+
|
|
108
|
+
<p>Each Attribute has a <strong>Type</strong>, which will be coerced and checked at runtime.</p>
|
|
109
|
+
|
|
110
|
+
<p align="center">
|
|
111
|
+
<img width="100%" src="/1.13/assets/img/backend.gif" />
|
|
112
|
+
</p>
|
|
113
|
+
|
|
114
|
+
<p>A Resource does not mean “a database table”, though the two have a lot in common and often match. A Resource is a generic interface wrapping a <strong>Backend</strong>. That Backend could be a relational database, a No-SQL database, or even a third-party service call. And you can use whichever client or ORM you’d like for a given Backend (<code class="language-plaintext highlighter-rouge">ActiveRecord</code>, <code class="language-plaintext highlighter-rouge">Sequel</code>, <code class="language-plaintext highlighter-rouge">Mongoid</code>, <code class="language-plaintext highlighter-rouge">Net::HTTP</code>, etc).</p>
|
|
115
|
+
|
|
116
|
+
<p>Resources define an interface for <strong>querying</strong> from and <strong>persisting</strong> to a given Backend. The generic, common, cross-Resource logic for connecting a Resource to a Backend is defined in an <strong>Adapter</strong>; individual Resources can override Adapter logic. The default adapter is <code class="language-plaintext highlighter-rouge">ActiveRecord</code> (<code class="language-plaintext highlighter-rouge">Graphiti::Adapters::ActiveRecord</code>).</p>
|
|
117
|
+
|
|
118
|
+
<p>From the raw backend results, the Resource builds <strong>Models</strong>, which hold
|
|
119
|
+
business logic. In other words you might <strong>query</strong> using <code class="language-plaintext highlighter-rouge">elasticsearch-ruby</code>, but return POROs as the result of that query. In the case of ActiveRecord, <strong>Backend</strong> and <strong>Model</strong> are the same thing.</p>
|
|
120
|
+
|
|
121
|
+
<p>Finally, these Models are <em>serialized</em> when we actually render a response. You’ll still use <code class="language-plaintext highlighter-rouge">Rails</code>, <code class="language-plaintext highlighter-rouge">Sinatra</code>, or whatever-else to manage routing, HTTP codes, etc.</p>
|
|
122
|
+
|
|
123
|
+
<p align="center">
|
|
124
|
+
<img width="100%" src="/1.13/assets/img/rest3.gif" />
|
|
125
|
+
</p>
|
|
126
|
+
|
|
127
|
+
<p>Critically, <strong>each Resource can connect to other Resources</strong>. This can occur through <strong><em>Sideloading</em></strong> (“fetch the employee, her positions, and the departments for those positions in a single request”), <strong><em>Sideposting</em></strong> (“<em>save</em> the employee and her positions/departments in a single request), and <strong><em>Links</em></strong> (“here’s a URL to lazy-load positions in a separate request”). Because <code class="language-plaintext highlighter-rouge">Resource</code>s connect to each other, this is why we often refer to a Resource as a “node in the graph”.</p>
|
|
128
|
+
|
|
129
|
+
<p><strong>Any logic used for fetching a single Resource can be re-used when fetching multiple Resources</strong>. In other words, you can say “fetch me the Employee, and her last three Positions ordered by <code class="language-plaintext highlighter-rouge">created_at</code>”. Applying query logic to nested levels of the graph is called <strong>Deep Querying</strong>.</p>
|
|
130
|
+
|
|
131
|
+
<p>Graphiti does not depend on Rails, but it <em>is</em> a first-class citizen.
|
|
132
|
+
Given the code:</p>
|
|
133
|
+
|
|
134
|
+
<figure class="highlight"><pre><code class="language-ruby" data-lang="ruby"><span class="c1"># config/routes.rb</span>
|
|
135
|
+
<span class="n">resources</span> <span class="ss">:employees</span></code></pre></figure>
|
|
136
|
+
|
|
137
|
+
<figure class="highlight"><pre><code class="language-ruby" data-lang="ruby"><span class="c1"># app/controllers/employees_controller.rb</span>
|
|
138
|
+
<span class="k">class</span> <span class="nc">EmployeesController</span> <span class="o"><</span> <span class="no">ApplicationController</span>
|
|
139
|
+
<span class="k">def</span> <span class="nf">index</span>
|
|
140
|
+
<span class="n">employees</span> <span class="o">=</span> <span class="no">EmployeeResource</span><span class="p">.</span><span class="nf">all</span><span class="p">(</span><span class="n">params</span><span class="p">)</span>
|
|
141
|
+
<span class="n">respond_with</span><span class="p">(</span><span class="n">employees</span><span class="p">)</span>
|
|
142
|
+
<span class="k">end</span>
|
|
143
|
+
<span class="k">end</span></code></pre></figure>
|
|
144
|
+
|
|
145
|
+
<figure class="highlight"><pre><code class="language-ruby" data-lang="ruby"><span class="c1"># app/models/employee.rb</span>
|
|
146
|
+
<span class="k">class</span> <span class="nc">Employee</span> <span class="o"><</span> <span class="no">ApplicationRecord</span>
|
|
147
|
+
<span class="k">end</span></code></pre></figure>
|
|
148
|
+
|
|
149
|
+
<figure class="highlight"><pre><code class="language-ruby" data-lang="ruby"><span class="c1"># app/resources/employee_resource.rb</span>
|
|
150
|
+
<span class="k">class</span> <span class="nc">EmployeeResource</span> <span class="o"><</span> <span class="no">ApplicationResource</span>
|
|
151
|
+
<span class="n">attribute</span> <span class="ss">:name</span><span class="p">,</span> <span class="ss">:string</span>
|
|
152
|
+
<span class="n">attribute</span> <span class="ss">:age</span><span class="p">,</span> <span class="ss">:integer</span>
|
|
153
|
+
<span class="k">end</span></code></pre></figure>
|
|
154
|
+
|
|
155
|
+
<p>We can now</p>
|
|
156
|
+
|
|
157
|
+
<ul>
|
|
158
|
+
<li>Fetch JSONAPI, Simple JSON, or XML
|
|
159
|
+
<ul>
|
|
160
|
+
<li><code class="language-plaintext highlighter-rouge">/employees.jsonapi</code></li>
|
|
161
|
+
<li><code class="language-plaintext highlighter-rouge">/employees.json</code></li>
|
|
162
|
+
<li><code class="language-plaintext highlighter-rouge">/employees.xml</code></li>
|
|
163
|
+
</ul>
|
|
164
|
+
</li>
|
|
165
|
+
<li>Paginate:
|
|
166
|
+
<ul>
|
|
167
|
+
<li><code class="language-plaintext highlighter-rouge">/employees?page[size]=10&page[number]=2</code></li>
|
|
168
|
+
</ul>
|
|
169
|
+
</li>
|
|
170
|
+
<li>Sort:
|
|
171
|
+
<ul>
|
|
172
|
+
<li>Ascending: <code class="language-plaintext highlighter-rouge">/employees?sort=age</code></li>
|
|
173
|
+
<li>Descending: <code class="language-plaintext highlighter-rouge">/employees?sort=-age</code></li>
|
|
174
|
+
</ul>
|
|
175
|
+
</li>
|
|
176
|
+
<li>Filter:
|
|
177
|
+
<ul>
|
|
178
|
+
<li>Case Insensitive: <code class="language-plaintext highlighter-rouge">/employees?filter[name]=jane doe</code></li>
|
|
179
|
+
<li>Case Sensitive: <code class="language-plaintext highlighter-rouge">/employees?filter[name][eql]=Jane Doe</code></li>
|
|
180
|
+
<li>Prefix: <code class="language-plaintext highlighter-rouge">/employees?filter[name][prefix]=graph</code></li>
|
|
181
|
+
<li>Suffix: <code class="language-plaintext highlighter-rouge">/employees?filter[name][suffix]=rocks</code></li>
|
|
182
|
+
<li>Contains: <code class="language-plaintext highlighter-rouge">/employees?filter[name][match]=iti</code></li>
|
|
183
|
+
<li>Equal: <code class="language-plaintext highlighter-rouge">/employees?filter[age]=100</code></li>
|
|
184
|
+
<li>Greater Than: <code class="language-plaintext highlighter-rouge">/employees?filter[age][gt]=100</code></li>
|
|
185
|
+
<li>Greater Than or Equal To: <code class="language-plaintext highlighter-rouge">/employees?filter[age][gte]=100</code></li>
|
|
186
|
+
<li>Less Than: <code class="language-plaintext highlighter-rouge">/employees?filter[age][lt]=100</code></li>
|
|
187
|
+
<li>Less Than or Equal To: <code class="language-plaintext highlighter-rouge">/employees?filter[age][lte]=100</code></li>
|
|
188
|
+
</ul>
|
|
189
|
+
</li>
|
|
190
|
+
<li>Only return specific fields:
|
|
191
|
+
<ul>
|
|
192
|
+
<li><code class="language-plaintext highlighter-rouge">/employees?fields[employees]=name,age</code></li>
|
|
193
|
+
</ul>
|
|
194
|
+
</li>
|
|
195
|
+
<li>Get total count:
|
|
196
|
+
<ul>
|
|
197
|
+
<li><code class="language-plaintext highlighter-rouge">/employees?stats[total]=count</code></li>
|
|
198
|
+
</ul>
|
|
199
|
+
</li>
|
|
200
|
+
</ul>
|
|
201
|
+
|
|
202
|
+
<p>To add a relationship:</p>
|
|
203
|
+
|
|
204
|
+
<figure class="highlight"><pre><code class="language-ruby" data-lang="ruby"><span class="c1"># app/models/employee.rb</span>
|
|
205
|
+
<span class="n">has_many</span> <span class="ss">:positions</span></code></pre></figure>
|
|
206
|
+
|
|
207
|
+
<figure class="highlight"><pre><code class="language-ruby" data-lang="ruby"><span class="c1"># app/models/position.rb</span>
|
|
208
|
+
<span class="k">class</span> <span class="nc">Position</span> <span class="o"><</span> <span class="no">ApplicationRecord</span>
|
|
209
|
+
<span class="n">belongs_to</span> <span class="ss">:employee</span>
|
|
210
|
+
<span class="k">end</span></code></pre></figure>
|
|
211
|
+
|
|
212
|
+
<figure class="highlight"><pre><code class="language-ruby" data-lang="ruby"><span class="c1"># app/resources/employee_resource.rb</span>
|
|
213
|
+
<span class="n">has_many</span> <span class="ss">:positions</span></code></pre></figure>
|
|
214
|
+
|
|
215
|
+
<figure class="highlight"><pre><code class="language-ruby" data-lang="ruby"><span class="c1"># app/resources/position_resource.rb</span>
|
|
216
|
+
<span class="k">class</span> <span class="nc">PositionResource</span> <span class="o"><</span> <span class="no">ApplicationResource</span>
|
|
217
|
+
<span class="n">attribute</span> <span class="ss">:title</span><span class="p">,</span> <span class="ss">:string</span>
|
|
218
|
+
<span class="n">belongs_to</span> <span class="ss">:employee</span>
|
|
219
|
+
<span class="k">end</span></code></pre></figure>
|
|
220
|
+
|
|
221
|
+
<p>We can now fetch Posts and Comments in a single request - <strong><em>including</em></strong> sorting the comments, filtering, fieldsets and everything else a <a href="/1.13/guides/concepts/resources">Resource</a> supports.</p>
|
|
222
|
+
|
|
223
|
+
<p><br /></p>
|
|
224
|
+
|
|
225
|
+
<p align="center">
|
|
226
|
+
<img width="100%" src="https://i.pinimg.com/originals/d1/12/8d/d1128d21ad45ac7e9be074053a9f1c76.jpg" />
|
|
227
|
+
</p>
|
|
228
|
+
|
|
229
|
+
<p><br /></p>
|
|
230
|
+
|
|
231
|
+
</div>
|
|
232
|
+
</div>
|
|
233
|
+
</main>
|
|
234
|
+
<div class="main-footer main-footer--dark">
|
|
235
|
+
<div class="container">
|
|
236
|
+
<div class="row">
|
|
237
|
+
<div class="col-sm-4 menu">
|
|
238
|
+
<h3>Overview</h3>
|
|
239
|
+
<ul>
|
|
240
|
+
<li>
|
|
241
|
+
<a href="/1.13/quickstart">Quickstart</a>
|
|
242
|
+
</li>
|
|
243
|
+
<li>
|
|
244
|
+
<a href="/1.13/tutorial">Tutorial</a>
|
|
245
|
+
</li>
|
|
246
|
+
<li>
|
|
247
|
+
<a href="/1.13/guides">Guides</a>
|
|
248
|
+
</li>
|
|
249
|
+
</ul>
|
|
250
|
+
</div>
|
|
251
|
+
<div class="col-sm-4 menu">
|
|
252
|
+
<h3>Contact</h3>
|
|
253
|
+
<ul>
|
|
254
|
+
<li>
|
|
255
|
+
<a target="_blank" href="https://discord.gg/wgqkMBsSRV">Discord Chat</a>
|
|
256
|
+
</li>
|
|
257
|
+
<li>
|
|
258
|
+
<a href="mailto:richmolj@gmail.com">Email</a>
|
|
259
|
+
</li>
|
|
260
|
+
</ul>
|
|
261
|
+
</div>
|
|
262
|
+
<div class="col-sm-4 menu">
|
|
263
|
+
<h3>Related</h3>
|
|
264
|
+
<ul>
|
|
265
|
+
<li>
|
|
266
|
+
<a target="_blank" href="http://jsonapi.org">JSONAPI Spec</a>
|
|
267
|
+
</li>
|
|
268
|
+
<li>
|
|
269
|
+
<a target="_blank" href="http://jsonapi-rb.org">jsonapi-rb</a>
|
|
270
|
+
</li>
|
|
271
|
+
<li>
|
|
272
|
+
<a target="_blank" href="https://vuejs.org/">VueJS</a>
|
|
273
|
+
</li>
|
|
274
|
+
</ul>
|
|
275
|
+
</div>
|
|
276
|
+
</div>
|
|
277
|
+
</div>
|
|
278
|
+
</div>
|
|
279
|
+
|
|
280
|
+
<script type="text/javascript">
|
|
281
|
+
$(function () {
|
|
282
|
+
|
|
283
|
+
var flipTabs = function() {
|
|
284
|
+
var isTS = true;
|
|
285
|
+
if (localStorage.getItem('js-lang') === 'javascript') {
|
|
286
|
+
isTS = false;
|
|
287
|
+
}
|
|
288
|
+
|
|
289
|
+
$('.code-tabs').each(function(index, el) {
|
|
290
|
+
if (isTS) {
|
|
291
|
+
console.log('hiding js');
|
|
292
|
+
$($(el).children()[1]).hide();
|
|
293
|
+
$($(el).children()[0]).show();
|
|
294
|
+
} else {
|
|
295
|
+
console.log('hiding ts');
|
|
296
|
+
$($(el).children()[0]).hide();
|
|
297
|
+
$($(el).children()[1]).show();
|
|
298
|
+
}
|
|
299
|
+
});
|
|
300
|
+
|
|
301
|
+
if (isTS) {
|
|
302
|
+
$('.tab.typescript').addClass('active');
|
|
303
|
+
$('.tab.javascript').removeClass('active');
|
|
304
|
+
} else {
|
|
305
|
+
$('.tab.typescript').removeClass('active');
|
|
306
|
+
$('.tab.javascript').addClass('active');
|
|
307
|
+
}
|
|
308
|
+
}
|
|
309
|
+
|
|
310
|
+
$('.tab').click(function() {
|
|
311
|
+
if ($(this).hasClass('typescript')) {
|
|
312
|
+
localStorage.setItem('js-lang', 'typescript');
|
|
313
|
+
} else {
|
|
314
|
+
localStorage.setItem('js-lang', 'javascript');
|
|
315
|
+
}
|
|
316
|
+
|
|
317
|
+
flipTabs();
|
|
318
|
+
});
|
|
319
|
+
|
|
320
|
+
flipTabs();
|
|
321
|
+
})
|
|
322
|
+
</script>
|
|
323
|
+
|
|
324
|
+
</body>
|
|
325
|
+
</html>
|
|
@@ -0,0 +1,193 @@
|
|
|
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
|
+
<h1 id="upgrading-to-graphiti-20">Upgrading to Graphiti 2.0</h1>
|
|
84
|
+
|
|
85
|
+
<p>Graphiti 2.0 requires <strong>Ruby 3.2+</strong> and <strong>Rails 7.1+</strong>, and folds <code class="language-plaintext highlighter-rouge">graphiti-rails</code>, <code class="language-plaintext highlighter-rouge">graphiti_spec_helpers</code> and <code class="language-plaintext highlighter-rouge">graphiti_errors</code> into <code class="language-plaintext highlighter-rouge">graphiti</code> itself. Those three gems are retired.</p>
|
|
86
|
+
|
|
87
|
+
<p>For most apps the upgrade is three things:</p>
|
|
88
|
+
|
|
89
|
+
<ol>
|
|
90
|
+
<li>Remove <code class="language-plaintext highlighter-rouge">graphiti-rails</code>, <code class="language-plaintext highlighter-rouge">graphiti_spec_helpers</code> and <code class="language-plaintext highlighter-rouge">graphiti_errors</code> from your Gemfile.</li>
|
|
91
|
+
<li>Add <code class="language-plaintext highlighter-rouge">include Graphiti::Rails::Controller</code> to the controllers serving your resources.</li>
|
|
92
|
+
<li>Update <code class="language-plaintext highlighter-rouge">around_persistence</code> hooks, if you have any — they now receive the model rather than the attributes hash.</li>
|
|
93
|
+
</ol>
|
|
94
|
+
|
|
95
|
+
<p>Old names still resolve and warn, so nothing breaks halfway through. They are removed in 3.0.</p>
|
|
96
|
+
|
|
97
|
+
<p>The <a href="https://github.com/graphiti-api/graphiti/blob/main/UPGRADING.md">full upgrade guide</a> lists every rename, what was removed outright, and the migration path for apps not running Rails.</p>
|
|
98
|
+
|
|
99
|
+
</div>
|
|
100
|
+
</div>
|
|
101
|
+
</main>
|
|
102
|
+
<div class="main-footer main-footer--dark">
|
|
103
|
+
<div class="container">
|
|
104
|
+
<div class="row">
|
|
105
|
+
<div class="col-sm-4 menu">
|
|
106
|
+
<h3>Overview</h3>
|
|
107
|
+
<ul>
|
|
108
|
+
<li>
|
|
109
|
+
<a href="/1.13/quickstart">Quickstart</a>
|
|
110
|
+
</li>
|
|
111
|
+
<li>
|
|
112
|
+
<a href="/1.13/tutorial">Tutorial</a>
|
|
113
|
+
</li>
|
|
114
|
+
<li>
|
|
115
|
+
<a href="/1.13/guides">Guides</a>
|
|
116
|
+
</li>
|
|
117
|
+
</ul>
|
|
118
|
+
</div>
|
|
119
|
+
<div class="col-sm-4 menu">
|
|
120
|
+
<h3>Contact</h3>
|
|
121
|
+
<ul>
|
|
122
|
+
<li>
|
|
123
|
+
<a target="_blank" href="https://discord.gg/wgqkMBsSRV">Discord Chat</a>
|
|
124
|
+
</li>
|
|
125
|
+
<li>
|
|
126
|
+
<a href="mailto:richmolj@gmail.com">Email</a>
|
|
127
|
+
</li>
|
|
128
|
+
</ul>
|
|
129
|
+
</div>
|
|
130
|
+
<div class="col-sm-4 menu">
|
|
131
|
+
<h3>Related</h3>
|
|
132
|
+
<ul>
|
|
133
|
+
<li>
|
|
134
|
+
<a target="_blank" href="http://jsonapi.org">JSONAPI Spec</a>
|
|
135
|
+
</li>
|
|
136
|
+
<li>
|
|
137
|
+
<a target="_blank" href="http://jsonapi-rb.org">jsonapi-rb</a>
|
|
138
|
+
</li>
|
|
139
|
+
<li>
|
|
140
|
+
<a target="_blank" href="https://vuejs.org/">VueJS</a>
|
|
141
|
+
</li>
|
|
142
|
+
</ul>
|
|
143
|
+
</div>
|
|
144
|
+
</div>
|
|
145
|
+
</div>
|
|
146
|
+
</div>
|
|
147
|
+
|
|
148
|
+
<script type="text/javascript">
|
|
149
|
+
$(function () {
|
|
150
|
+
|
|
151
|
+
var flipTabs = function() {
|
|
152
|
+
var isTS = true;
|
|
153
|
+
if (localStorage.getItem('js-lang') === 'javascript') {
|
|
154
|
+
isTS = false;
|
|
155
|
+
}
|
|
156
|
+
|
|
157
|
+
$('.code-tabs').each(function(index, el) {
|
|
158
|
+
if (isTS) {
|
|
159
|
+
console.log('hiding js');
|
|
160
|
+
$($(el).children()[1]).hide();
|
|
161
|
+
$($(el).children()[0]).show();
|
|
162
|
+
} else {
|
|
163
|
+
console.log('hiding ts');
|
|
164
|
+
$($(el).children()[0]).hide();
|
|
165
|
+
$($(el).children()[1]).show();
|
|
166
|
+
}
|
|
167
|
+
});
|
|
168
|
+
|
|
169
|
+
if (isTS) {
|
|
170
|
+
$('.tab.typescript').addClass('active');
|
|
171
|
+
$('.tab.javascript').removeClass('active');
|
|
172
|
+
} else {
|
|
173
|
+
$('.tab.typescript').removeClass('active');
|
|
174
|
+
$('.tab.javascript').addClass('active');
|
|
175
|
+
}
|
|
176
|
+
}
|
|
177
|
+
|
|
178
|
+
$('.tab').click(function() {
|
|
179
|
+
if ($(this).hasClass('typescript')) {
|
|
180
|
+
localStorage.setItem('js-lang', 'typescript');
|
|
181
|
+
} else {
|
|
182
|
+
localStorage.setItem('js-lang', 'javascript');
|
|
183
|
+
}
|
|
184
|
+
|
|
185
|
+
flipTabs();
|
|
186
|
+
});
|
|
187
|
+
|
|
188
|
+
flipTabs();
|
|
189
|
+
})
|
|
190
|
+
</script>
|
|
191
|
+
|
|
192
|
+
</body>
|
|
193
|
+
</html>
|