Fireship · @fireship
GraphQL Explained in 100 Seconds
Uploaded February 13, 2021 · Length 2:22
Summary
graphql explained as a query language for reading and mutating data in apis with a type system and schema.
- graphql
- api design
- query language
- schema definition
- type system
Transcript preview
The first 2 minutes of the transcript. Select a timestamp to watch that moment on YouTube.
- 0:00
graphql a query language for reading and
- 0:03
mutating data in apis
- 0:05
as a back-end developer graphql provides
- 0:08
a type system
- 0:09
where you can describe a schema for your
- 0:11
data in turn
- 0:12
this gives front-end consumers of the
- 0:14
api the power to explore
- 0:16
and request the exact data they need
- 0:18
traditionally
- 0:19
web developers have consumed apis using
- 0:21
rest where data entities
- 0:23
live on a bunch of urls on a server when
- 0:25
a request is received
- 0:26
the api responds with the full data
- 0:28
payload of that entity
- 0:30
that sounds simple enough but there are
- 0:31
two potential drawbacks here
- 0:33
we may need multiple entities at one
- 0:35
time in which case
- 0:36
each request is under fetching the
- 0:38
actual data we want
- 0:39
in other cases we may only want a small
- 0:42
subset of a data entity
- 0:43
in which case we need to over fetch from
- 0:45
the api and that of course is bad for
- 0:48
the environment
- 0:48
how dare you instead of multiple urls a
- 0:51
graphql api
- 0:52
has a single entry point data is queried
- 0:55
or fetched
- 0:56
by describing it with a syntax that
- 0:58
mirrors its return shape in json
- 1:00
the front-end developer describes the
- 1:02
data they want while the back-end
- 1:03
developer
- 1:04
writes code to resolve the request and
- 1:06
it all happens in a syntax that can work
- 1:08
with any programming language
- 1:09
we can start defining a schema with our
- 1:11
own custom objects using the type
- 1:13
keyword
- 1:14
a type can have multiple fields like a
- 1:16
unique id
- 1:17
and we'll make that required with a bang
- 1:19
let's also give it integer and string
- 1:21
values
- 1:21
then create a relationship with another
- 1:23
type a creator can have many videos
- 1:26
which we can represent by wrapping the
- 1:27
type in brackets on the flip side
- 1:29
a video belongs to a creator now every
- 1:32
graphql api
- 1:33
has a query type which is the main entry
- 1:35
point for a consumer of the api
- 1:38
we can query a list of videos or an
- 1:40
individual user based on their id
- 1:42
that's how a consumer reads data but
- 1:43
they may also want to mutate data
- 1:46
in which case we implement a mutation
- 1:48
type that defines how data can be
- 1:49
modified on the api
- 1:51
from there we can define code to resolve
- 1:53
this data in any programming language
- 1:55
once deployed any developer consuming
- 1:57
this api will be able to explore it with
- 1:59
a complete understanding


