by Carlos Contreras
me
1. Dismissal
One more JavaScript library?! Just use jQuery already!
Hmm, maybe I should check out this new library I keep hearing about…
Help! I need to learn this new library right now or I’ll be completely obsolete!
The three stages when hearing about a new technology:
mongoDB
PostreSQL
Memcache
The client asks for various data from the GraphQL server via queries. The response format is described in the query and defined by the client instead of the server: they are called client‐specified queries.
{
github {
user(username: "DarthCharles") {
login
id
avatar_url
repos {
name
}
}
}
}
Query language
Runtime
We can use the language to communicate queries for reading actions and mutations for writing actions.
A GraphQL operation can have:
We write GraphQL operations in "documents" on the client-side, and then use an interface to send these documents to a GraphQL server.
HTTP is a popular option but it's not the only one we can use, for example, use Sockets, or an SSH protocol, or a simple command-line interface that works with an executable binary.
Relay
The runtime's job is to understand GraphQL documents and translate them for the other services in the server-side stack.
The data services layers will prepare the data for the request and hand it to the GraphQL engine, which puts it together and sends it to the client who asked for it.
Before starting to build your server, GraphQL requires you to design a schema which in turn defines the API of your server.
A GraphQL schema must have:
{
getAuthor(id: 5){
name
posts {
title
author {
name
}
}
}
}
{
data: {
getAuthor: {
name: "Carlos Contreras",
posts: [
{
title: "Hello World",
author: {
name: "Carlos Contreras"
}
},{
title: "Why am I still up at midnight writing this talk on my birthday 🎈?",
author: {
name: "Carlos Contreras"
}
}
]
}
}
}