-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathslides_graphql-api.html
More file actions
554 lines (536 loc) · 26.3 KB
/
slides_graphql-api.html
File metadata and controls
554 lines (536 loc) · 26.3 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<title>Slides for
APIs — Ruby on Rails Guides
</title>
<link rel="stylesheet" type="text/css" href="stylesheets/style.css" data-turbo-track="reload">
<link rel="stylesheet" type="text/css" href="stylesheets/print.css" media="print">
<link rel="stylesheet" type="text/css" href="stylesheets/highlight.css" data-turbo-track="reload">
<meta name="apple-mobile-web-app-capable" content="yes">
<meta name="apple-mobile-web-app-status-bar-style" content="black-translucent">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<link rel="stylesheet" href="stylesheets/reset.css">
<link rel="stylesheet" href="stylesheets/reveal.css">
<link rel="stylesheet" href="stylesheets/myslide.css" id="theme">
<link rel="stylesheet" href="stylesheets/code.css">
<script src="javascripts/clipboard.js" data-turbo-track="reload"></script>
<script src="javascripts/slides.js" data-turbo-track="reload"></script>
</head>
<body>
<div class="reveal">
<!-- Any section element inside of this container is displayed as a slide -->
<div class="slides">
<section>
<h1>APIs</h1><p>After working through this guide you will:</p>
<ul>
<li>know about the thinking behind GraphQL APIs</li>
<li>be able to configure your existing Rails App to offer a GraphQL API</li>
</ul>
<p><small>Slides - use arrow keys to navigate, esc to return to page view, f for fullscreen</small></p>
</section>
<section><a class='slide_break' href='graphql-api.html#slide-0'>▻</a>
<h2 id="api-styles"><a class="anchorlink" href="#api-styles"><span>1</span> API Styles</a></h2></section>
<section><a class='slide_break' href='graphql-api.html#slide-1'>▻</a>
<h3 id="what-is-an-api-questionmark"><a class="anchorlink" href="#what-is-an-api-questionmark"><span>1.1</span> What is an API?</a></h3><p>API stands for "Application Programming Interface". It is a set of clearly defined methods
of communication with a software component. So the objects and methods exposed by a library
form an API.</p><p>In Web development the acronym API is most
commonly used when the software component in question runs on a different server on the
Internet and is accessed via HTTP.</p></section>
<section><a class='slide_break' href='graphql-api.html#slide-2'>▻</a>
<h3 id="soap-rest-and-graphql"><a class="anchorlink" href="#soap-rest-and-graphql"><span>1.2</span> SOAP, REST and GraphQL</a></h3><p>Currently three main API styles are used on the Web:</p>
<ul>
<li>SOAP, designed 1998 at Microsoft, uses XML and POST requests to make "remote procedure calls"</li>
<li>REST, described in 2000, uses different HTTP Methods and Status Messages to access "resources"</li>
<li>GraphQL, released 2015 by Facebook, uses POST requests, it's own query language and JSON</li>
</ul>
<p>This Guide is concerned with GraphQL, there is a second guide for <a href="/rest-api.html">REST</a>. SOAP
is rearely offered with Rails, but there is a <a href="https://github.com/savonrb/savon">soap client</a> in
ruby.</p></section>
<section><a class='slide_break' href='graphql-api.html#slide-3'>▻</a>
<h3 id="api-layer-is-a-separate-layer"><a class="anchorlink" href="#api-layer-is-a-separate-layer"><span>1.3</span> API layer is a separate layer</a></h3><p>Please note that any of the API styles can be used
with any backend, frontend, persistance layers:</p>
<ul>
<li>You can build a REST in front of a PHP backend using MongoDB as the database and use it from a frontend written with jQuery.</li>
<li>You can build a GraphQL API for a Rails backend using MySQL as the database and build the frontend with React.</li>
</ul>
<p>That's kind of the point of an API: to allow different technologies
on both sides of the API.</p></section>
<section><a class='slide_break' href='graphql-api.html#slide-4'>▻</a>
<h2 id="graphql"><a class="anchorlink" href="#graphql"><span>2</span> GraphQL</a></h2><p>REST and SOAP APIs are fixed interfaces: each api call has a fixed set of
arguments and returns a fixed data structure. All decisions are made when
specifying the API.</p><p>GraphQL shifts some decisions to the client: through a Query Language the client
can request data in the specific shape it needs, within the limits that the
API sets.</p></section>
<section><a class='slide_break' href='graphql-api.html#slide-5'>▻</a>
<h3 id="query-language"><a class="anchorlink" href="#query-language"><span>2.1</span> Query Language</a></h3><p>A simple example with two models: a project has many URLs. when querying
through GraphQL you can request different attributes of both models:</p><p><img src="images/two-queries.gif" alt="1:n relationship in the database"></p><p>Notice how the resulting JSON data mirrors the structure of the query.
The query language is used for both Queries (getting data) and Mutations (changing
data).</p></section>
<section><a class='slide_break' href='graphql-api.html#slide-6'>▻</a>
<h3 id="introspection-and-playground"><a class="anchorlink" href="#introspection-and-playground"><span>2.2</span> Introspection and Playground</a></h3><p>A GraphQL API can always be queried to give information
about the possible queries, mutations and types. This is called
introspection.</p><p>The GraphQL Playground is a Web App that enables you to
make Queries and Mutations. It uses introspection to display
documentation and to offer autocompletion:</p>
<video controls="" autoplay="">
<source src="images/autocomplete.mov" type="video/quicktime">
<source src="images/autocomplete.mp4" type="video/mp4">

</video>
</section>
<section><a class='slide_break' href='graphql-api.html#slide-7'>▻</a>
<h3 id="types"><a class="anchorlink" href="#types"><span>2.3</span> Types</a></h3><p>A GraphQL delivers JSON, which only has objects, arrays, strings, numbers and null
as types. But GraphQL itself can build a more detailed type system and check
these types in queries and mutations.</p></section>
<section><a class='slide_break' href='graphql-api.html#slide-8'>▻</a>
<h3 id="how-the-server-handles-the-request"><a class="anchorlink" href="#how-the-server-handles-the-request"><span>2.4</span> How the server handles the request</a></h3>
<ul>
<li>parse the query</li>
<li>validate with schema</li>
<li>resolve data</li>
<li>convert response to JSON</li>
</ul>
</section>
<section><a class='slide_break' href='graphql-api.html#slide-9'>▻</a>
<h2 id="using-rails-to-build-a-graphql-api"><a class="anchorlink" href="#using-rails-to-build-a-graphql-api"><span>3</span> Using Rails to build a GraphQL API</a></h2></section>
<section><a class='slide_break' href='graphql-api.html#slide-10'>▻</a>
<h3 id="setup"><a class="anchorlink" href="#setup"><span>3.1</span> Setup</a></h3><p>To add a GraphQL API to an existing Rails app you need just two gems:</p><div class="interstitial code">
<pre><code class="highlight plaintext">gem 'graphql'
group :development do
gem 'graphql-rails-generators'
end
</code></pre>
<button class="clipboard-button" data-clipboard-text="gem 'graphql'
group :development do
gem 'graphql-rails-generators'
end
">Copy</button>
</div>
</section>
<section><a class='slide_break' href='graphql-api.html#slide-11'>▻</a>
<h4 id="generator"><a class="anchorlink" href="#generator"><span>3.1.1</span> generator</a></h4><p>The rest of the setup is handled by a generator added by the <code>graphql</code> gem:</p><div class="interstitial code">
<pre><code class="highlight plaintext">rails generate graphql:install
exist app/graphql/types
create app/graphql/types/.keep
create app/graphql/portfolio_relaunch_schema.rb
create app/graphql/types/base_object.rb
create app/graphql/types/base_argument.rb
create app/graphql/types/base_field.rb
create app/graphql/types/base_enum.rb
create app/graphql/types/base_input_object.rb
create app/graphql/types/base_interface.rb
create app/graphql/types/base_scalar.rb
create app/graphql/types/base_union.rb
create app/graphql/types/query_type.rb
add_root_type query
create app/graphql/mutations
create app/graphql/mutations/.keep
create app/graphql/mutations/base_mutation.rb
create app/graphql/types/mutation_type.rb
add_root_type mutation
create app/controllers/graphql_controller.rb
route post "/graphql", to: "graphql#execute"
gemfile graphiql-rails
route graphiql-rails
Gemfile has been modified, make sure you `bundle install`
</code></pre>
<button class="clipboard-button" data-clipboard-text="rails generate graphql:install
exist app/graphql/types
create app/graphql/types/.keep
create app/graphql/portfolio_relaunch_schema.rb
create app/graphql/types/base_object.rb
create app/graphql/types/base_argument.rb
create app/graphql/types/base_field.rb
create app/graphql/types/base_enum.rb
create app/graphql/types/base_input_object.rb
create app/graphql/types/base_interface.rb
create app/graphql/types/base_scalar.rb
create app/graphql/types/base_union.rb
create app/graphql/types/query_type.rb
add_root_type query
create app/graphql/mutations
create app/graphql/mutations/.keep
create app/graphql/mutations/base_mutation.rb
create app/graphql/types/mutation_type.rb
add_root_type mutation
create app/controllers/graphql_controller.rb
route post "/graphql", to: "graphql#execute"
gemfile graphiql-rails
route graphiql-rails
Gemfile has been modified, make sure you `bundle install`
">Copy</button>
</div>
</section>
<section><a class='slide_break' href='graphql-api.html#slide-12'>▻</a>
<h4 id="playground-is-available"><a class="anchorlink" href="#playground-is-available"><span>3.1.2</span> playground is available</a></h4><p>After running bundle and restarting the server you can
access the graphql playground at <code>http://localhost:3000/graphiql</code>:
in the left pane you can enter a query, run it, and see the
result in the middle pane. The right pane contains documentation
that was created automatically.</p><p><img src="images/graphql-playground.png" alt="GraphQL Playground"></p><p>We have no Queries to run yet.</p></section>
<section><a class='slide_break' href='graphql-api.html#slide-13'>▻</a>
<h3 id="generating-a-type-from-a-model"><a class="anchorlink" href="#generating-a-type-from-a-model"><span>3.2</span> Generating a Type from a Model</a></h3><p>As a first step we can
use a generator to create a type from an existing model:</p><div class="interstitial code">
<pre><code class="highlight plaintext">rails generate gql:model_type Project
create app/graphql/types/project_type.rb
</code></pre>
<button class="clipboard-button" data-clipboard-text="rails generate gql:model_type Project
create app/graphql/types/project_type.rb
">Copy</button>
</div>
<p>Now we can edit the type to fit our needs, for example
we can remove attributes that should never be public:</p><div class="interstitial code">
<pre><code class="highlight plaintext">module Types
class ProjectType < Types::BaseObject
field :id, GraphQL::Types::ID, null: false
field :title, String, null: false
field :publicationdate, GraphQL::Types::ISO8601Date, null: false
field :membership, Int, null: true
field :created_at, GraphQL::Types::ISO8601DateTime, null: false
field :updated_at, GraphQL::Types::ISO8601DateTime, null: false
field :slug, String, null: false
end
end
</code></pre>
<button class="clipboard-button" data-clipboard-text="module Types
class ProjectType < Types::BaseObject
field :id, GraphQL::Types::ID, null: false
field :title, String, null: false
field :publicationdate, GraphQL::Types::ISO8601Date, null: false
field :membership, Int, null: true
field :created_at, GraphQL::Types::ISO8601DateTime, null: false
field :updated_at, GraphQL::Types::ISO8601DateTime, null: false
field :slug, String, null: false
end
end
">Copy</button>
</div>
</section>
<section><a class='slide_break' href='graphql-api.html#slide-14'>▻</a>
<h3 id="defining-a-query"><a class="anchorlink" href="#defining-a-query"><span>3.3</span> Defining a Query</a></h3><p>The next level up we come to the query. There is already
a dummy Query in <code>app/graphql/types/query_type.rb</code></p><div class="interstitial code">
<pre><code class="highlight plaintext">module Types
class QueryType < Types::BaseObject
# Add root-level fields here.
# They will be entry points for queries on your schema.
# TODO: remove me
field :test_field, String, null: false,
description: "An example field added by the generator"
def test_field
"Hello World!"
end
end
end
</code></pre>
<button class="clipboard-button" data-clipboard-text="module Types
class QueryType < Types::BaseObject
# Add root-level fields here.
# They will be entry points for queries on your schema.
# TODO: remove me
field :test_field, String, null: false,
description: "An example field added by the generator"
def test_field
"Hello World!"
end
end
end
">Copy</button>
</div>
</section>
<section><a class='slide_break' href='graphql-api.html#slide-15'>▻</a>
<h4 id="declare-the-query-and-implement-the-resolver"><a class="anchorlink" href="#declare-the-query-and-implement-the-resolver"><span>3.3.1</span> Declare the Query and implement the resolver</a></h4><p>We can replace this with a query that returns a list of all projects:</p><div class="interstitial code">
<pre><code class="highlight plaintext">module Types
class QueryType < Types::BaseObject
field :all_projects, [ProjectType],
null: false,
description: "a list of all publicly visible projects"
def all_projects
Project.public.all
end
end
end
</code></pre>
<button class="clipboard-button" data-clipboard-text="module Types
class QueryType < Types::BaseObject
field :all_projects, [ProjectType],
null: false,
description: "a list of all publicly visible projects"
def all_projects
Project.public.all
end
end
end
">Copy</button>
</div>
<p>We can now run the query in the playground. Your query will be autocompleted.</p>
<video controls="" autoplay="">
<source src="images/autocomplete.mov" type="video/quicktime">
<source src="images/autocomplete.mp4" type="video/mp4">

</video>
</section>
<section><a class='slide_break' href='graphql-api.html#slide-16'>▻</a>
<h4 id="queries-with-arguments"><a class="anchorlink" href="#queries-with-arguments"><span>3.3.2</span> Queries with arguments</a></h4><p>If a query needs arguments you have do declare
them in the <code>fields</code> declaration and then handle
them in the method:</p><div class="interstitial code">
<pre><code class="highlight plaintext"> field :project, ProjectType, null: true do
argument :id, ID, required: true
end
def project(id:)
Project.visible.find(id)
end
</code></pre>
<button class="clipboard-button" data-clipboard-text=" field :project, ProjectType, null: true do
argument :id, ID, required: true
end
def project(id:)
Project.visible.find(id)
end
">Copy</button>
</div>
</section>
<section><a class='slide_break' href='graphql-api.html#slide-17'>▻</a>
<h3 id="relationships-between-models"><a class="anchorlink" href="#relationships-between-models"><span>3.4</span> Relationships between models</a></h3></section>
<section><a class='slide_break' href='graphql-api.html#slide-18'>▻</a>
<h4 id="create-type-for-a-second-model"><a class="anchorlink" href="#create-type-for-a-second-model"><span>3.4.1</span> Create type for a second model</a></h4><p><img src="images/graphql-project-has-many-urls.png" alt="1:n relationship in the database"></p><p>generate the UrlType automatically from the model:</p><div class="interstitial code">
<pre><code class="highlight plaintext">module Types
class UrlType < Types::BaseObject
field :id, GraphQL::Types::ID, null: false
field :title, String, null: true
field :url, String, null: true
field :url_type, String, null: true
field :created_at, GraphQL::Types::ISO8601DateTime, null: true
field :updated_at, GraphQL::Types::ISO8601DateTime, null: true
end
end
</code></pre>
<button class="clipboard-button" data-clipboard-text="module Types
class UrlType < Types::BaseObject
field :id, GraphQL::Types::ID, null: false
field :title, String, null: true
field :url, String, null: true
field :url_type, String, null: true
field :created_at, GraphQL::Types::ISO8601DateTime, null: true
field :updated_at, GraphQL::Types::ISO8601DateTime, null: true
end
end
">Copy</button>
</div>
</section>
<section><a class='slide_break' href='graphql-api.html#slide-19'>▻</a>
<h4 id="create-queries-for-the-second-model"><a class="anchorlink" href="#create-queries-for-the-second-model"><span>3.4.2</span> create queries for the second model</a></h4><p>add the queries <code>all_urls</code> and <code>url</code> to <code>app/graphql/types/query_type.rb</code></p><p>now you can use those queries in the playground</p></section>
<section><a class='slide_break' href='graphql-api.html#slide-20'>▻</a>
<h4 id="add-field-for-relationship-to-type"><a class="anchorlink" href="#add-field-for-relationship-to-type"><span>3.4.3</span> add field for relationship to type</a></h4><p>add the field <code>urls</code> to <code>app/graphql/types/project_type.rb</code>:</p><div class="interstitial code">
<pre><code class="highlight plaintext">module Types
class ProjectType < Types::BaseObject
field :id, GraphQL::Types::ID, null: false
field :title, String, null: false
field :publicationdate, GraphQL::Types::ISO8601Date, null: false
field :membership, Int, null: true
field :created_at, GraphQL::Types::ISO8601DateTime, null: false
field :updated_at, GraphQL::Types::ISO8601DateTime, null: false
field :slug, String, null: false
field :urls, [ UrlType ], null: false
end
end
</code></pre>
<button class="clipboard-button" data-clipboard-text="module Types
class ProjectType < Types::BaseObject
field :id, GraphQL::Types::ID, null: false
field :title, String, null: false
field :publicationdate, GraphQL::Types::ISO8601Date, null: false
field :membership, Int, null: true
field :created_at, GraphQL::Types::ISO8601DateTime, null: false
field :updated_at, GraphQL::Types::ISO8601DateTime, null: false
field :slug, String, null: false
field :urls, [ UrlType ], null: false
end
end
">Copy</button>
</div>
<p>now you can query for Urls through their project:</p><p><img src="images/graphql-query-relationship.png" alt="query a 1:n relationship with graphql"></p></section>
<section><a class='slide_break' href='graphql-api.html#slide-21'>▻</a>
<h4 id="inverse-relationship"><a class="anchorlink" href="#inverse-relationship"><span>3.4.4</span> inverse relationship</a></h4><p>what would you need to do, to make a query
from Url to Project possible?</p><div class="interstitial code">
<pre><code class="highlight plaintext">{
url(id:2077){
id
url
urlType
title
project {
title
}
}
}
</code></pre>
<button class="clipboard-button" data-clipboard-text="{
url(id:2077){
id
url
urlType
title
project {
title
}
}
}
">Copy</button>
</div>
</section>
<section><a class='slide_break' href='graphql-api.html#slide-22'>▻</a>
<h4 id="implementation-of-the-inverse-relationship"><a class="anchorlink" href="#implementation-of-the-inverse-relationship"><span>3.4.5</span> implementation of the inverse relationship</a></h4><p>Answer: add a field project to UrlType:</p><div class="interstitial code">
<pre><code class="highlight plaintext">module Types
class UrlType < Types::BaseObject
field :id, GraphQL::Types::ID, null: false
field :title, String, null: true
field :url, String, null: true
field :url_type, String, null: true
field :created_at, GraphQL::Types::ISO8601DateTime, null: true
field :updated_at, GraphQL::Types::ISO8601DateTime, null: true
field :project, ProjectType, null: false
end
end
</code></pre>
<button class="clipboard-button" data-clipboard-text="module Types
class UrlType < Types::BaseObject
field :id, GraphQL::Types::ID, null: false
field :title, String, null: true
field :url, String, null: true
field :url_type, String, null: true
field :created_at, GraphQL::Types::ISO8601DateTime, null: true
field :updated_at, GraphQL::Types::ISO8601DateTime, null: true
field :project, ProjectType, null: false
end
end
">Copy</button>
</div>
<p><img src="images/graphql-query-belongs-to.png" alt="query a 1:n relationship with graphql (reverse)"></p></section>
<section><a class='slide_break' href='graphql-api.html#slide-23'>▻</a>
<h3 id="more-types"><a class="anchorlink" href="#more-types"><span>3.5</span> More Types</a></h3><p>In Ruby and JavaScript we often use Strings to store all
kinds of values. In the example
above, <code>Url.url_type</code> only has three possible values: 'Link','Repository','Award'.</p><p>GraphQL comes with an Enum Type that we can use for that</p></section>
<section><a class='slide_break' href='graphql-api.html#slide-24'>▻</a>
<h4 id="define-the-enum-type"><a class="anchorlink" href="#define-the-enum-type"><span>3.5.1</span> define the Enum Type:</a></h4><div class="interstitial code">
<pre><code class="highlight plaintext">rails g graphql:enum UrlTypeEnum Link Repository Award
create app/graphql/types/url_type_enum_type.rb
</code></pre>
<button class="clipboard-button" data-clipboard-text="rails g graphql:enum UrlTypeEnum Link Repository Award
create app/graphql/types/url_type_enum_type.rb
">Copy</button>
</div>
<div class="interstitial code">
<pre><code class="highlight plaintext">module Types
class UrlTypeEnumType < Types::BaseEnum
value "Link"
value "Repository"
value "Award"
end
end
</code></pre>
<button class="clipboard-button" data-clipboard-text="module Types
class UrlTypeEnumType < Types::BaseEnum
value "Link"
value "Repository"
value "Award"
end
end
">Copy</button>
</div>
</section>
<section><a class='slide_break' href='graphql-api.html#slide-25'>▻</a>
<h4 id="using-the-enum-type"><a class="anchorlink" href="#using-the-enum-type"><span>3.5.2</span> using the Enum Type</a></h4><p>This can now be used in <code>UrlType</code>:</p><div class="interstitial code">
<pre><code class="highlight plaintext">module Types
class UrlType < Types::BaseObject
field :id, GraphQL::Types::ID, null: false
field :title, String, null: true
field :url, String, null: true
field :url_type, UrlTypeEnumType, null: true
field :created_at, GraphQL::Types::ISO8601DateTime, null: true
field :updated_at, GraphQL::Types::ISO8601DateTime, null: true
field :project, ProjectType, null: false
end
end
</code></pre>
<button class="clipboard-button" data-clipboard-text="module Types
class UrlType < Types::BaseObject
field :id, GraphQL::Types::ID, null: false
field :title, String, null: true
field :url, String, null: true
field :url_type, UrlTypeEnumType, null: true
field :created_at, GraphQL::Types::ISO8601DateTime, null: true
field :updated_at, GraphQL::Types::ISO8601DateTime, null: true
field :project, ProjectType, null: false
end
end
">Copy</button>
</div>
</section>
<section><a class='slide_break' href='graphql-api.html#slide-26'>▻</a>
<h4 id="types-uses-and-limitations"><a class="anchorlink" href="#types-uses-and-limitations"><span>3.5.3</span> Types: uses and limitations</a></h4><p>The data returned by a query is still JSON, and cannot contain
enums, only Strings.</p><p><img src="images/graphql-enum.png" alt="querying an enum gives a string"></p><p>In the documentation you can see that
only three Strings are valid. The GraphQL API will
validate this both in Queries and in Mutations.</p></section>
<section><a class='slide_break' href='graphql-api.html#slide-27'>▻</a>
<h2 id="a-lot-more-to-learn"><a class="anchorlink" href="#a-lot-more-to-learn"><span>4</span> A lot more to learn</a></h2><p>This guide has not touched on:</p>
<ul>
<li>mutations</li>
<li>filtering, searching</li>
<li>pagination</li>
<li>resolving graphql queries that are not directly mapped to models</li>
<li>...</li>
</ul>
</section>
<section><a class='slide_break' href='graphql-api.html#slide-28'>▻</a>
<h3 id="see-also"><a class="anchorlink" href="#see-also"><span>4.1</span> See Also</a></h3>
<ul>
<li><a href="https://www.howtographql.com/graphql-ruby/0-introduction/">GraphQL Guides: Ruby </a></li>
<li><a href="https://pragmaticstudio.com/tutorials/what-is-graphql">Pragmatic Tutorial: GraphQL?</a> (see also part 2 + 3)</li>
<li><a href="https://www.apollographql.com/">Apollo Client + Server</a> in JavaScript</li>
<li><a href="https://api-platform.com/">API Platform</a> to build REST + GraphQL APIs in PHP</li>
<li><a href="https://wundergraph.com/blog/graphql_in_production_analyzing_public_graphql_apis_1_twitch_tv">Analyzing the Twitch.tv GraphQL API</a></li>
</ul>
</div></section>
</div>
</div>
<!-- End slides. -->
<!-- Required JS files. -->
<script src="javascripts/reveal.js"></script>
<script src="javascripts/search.js"></script>
<script src="javascripts/markdown.js"></script>
<script>
// Also available as an ES module, see:
// https://revealjs.com/initialization/
Reveal.initialize({
controls: false,
progress: true,
center: false,
hash: true,
// The "normal" size of the presentation, aspect ratio will
// be preserved when the presentation is scaled to fit different
// resolutions. Can be specified using percentage units.
width: 1000,
height: 600,
disableLayout: false,
// Factor of the display size that should remain empty around
// the content
margin: 0.05,
// Bounds for smallest/largest possible scale to apply to content
minScale: 0.2,
maxScale: 10.0,
keyboard: {
27: () => {
// do something custom when ESC is pressed
var new_url = window.location.pathname.replace('slides_', '') + window.location.hash.replace('/','slide-');
window.location = new_url;
},
191: 'toggleHelp',
13: 'next', // go to the next slide when the ENTER key is pressed
},
// Learn about plugins: https://revealjs.com/plugins/
plugins: [ RevealSearch, RevealMarkdown ]
});
</script>
</body>
</html>