Page 4
GraphQL is a query language for your API, and a server-side runtime for executing queries by using a type system you define for your data.
http://graphql.org/learn/
Page 5
Type Query {
me: User
}
Type User {
id: ID
name: String
}
Page 6
Type Query {
me: User
}
Type User {
id: ID
name: String
}
{ me { name }}
Page 7
{ "me": { "name": "Luke Skywalker" }}
Type Query {
me: User
}
Type User {
id: ID
name: String
}
{ me { name }}
Page 8
Como funciona na prática?
POST http://localhost/graphql
{ "query" : "query { me { name } }"}
Page 9
Como funciona na prática?
POST http://localhost/graphql
{ "query" : "query { me { name } }"}
Response
{ "data" : { "me" : { "name" : "Luke Skywalker" } }}
Page 10
De onde veio GraphQL?
● Protótipo em 2012
https://youtu.be/zVNrqo9XGOs
Page 11
De onde veio GraphQL?
● Protótipo em 2012● 2015 Falaram sobre GraphQL
https://youtu.be/zVNrqo9XGOs
Page 12
De onde veio GraphQL?
● Protótipo em 2012● 2015 Falaram sobre GraphQL● Mais tarde (Julho) foi OSS (JavaScript)
https://youtu.be/zVNrqo9XGOs
Page 13
De onde veio GraphQL?
● Protótipo em 2012● 2015 Falaram sobre GraphQL● Mais tarde (Julho) foi OSS (JavaScript)● 2016 Production Ready
https://youtu.be/zVNrqo9XGOs
Page 14
Explorando APIs GraphQL
Com GraphiQL!
Page 15
GraphiQL is a graphical interactive in-browser GraphQL
IDE.
https://github.com/graphql/graphiql
Page 16
https://github.com/graphql/graphiql
Page 17
http://graphql.org/swapi-graphql/
Page 18
GraphiQL
http://graphql.org/swapi-graphql/
Page 19
Show me the Code!
Acessando a
API do Github
Page 20
Quais linguagens tenho utilizado nos
meus últimos repositórios?
Page 21
API Rest
GET /user/repos
Response
Page 22
API Rest
GET /user/repos
Response
Page 23
API Rest
GET /repos/:owner/:repo/languages
Response
Page 25
API GraphQL do Github
https://developer.github.com/v4
Page 26
API GraphQL do Github
https://developer.github.com/v4/explorer/
Page 27
https://developer.github.com/v4/explorer/
Page 28
https://developer.github.com/v4/explorer/
Page 29
https://developer.github.com/v4/explorer/
Page 30
https://developer.github.com/v4/explorer/
Page 31
https://developer.github.com/v4/explorer/
Page 32
https://developer.github.com/v4/explorer/
Page 33
Show me the Code! [2]
Criando uma
API GraphQL
Page 35
Gemfile
$> bundle
Page 36
Gemfile
$> bundle$> rails g graphql:install
Page 37
Gemfile
$> bundle$> rails g graphql:install
routes.rb
Page 38
app/controllers/graphql_controller.rb
Page 39
app/controllers/graphql_controller.rb
Page 40
app/graphql/leave_management_schema.rb
Page 41
app/graphql/leave_management_schema.rb
Page 42
app/graphql/types/query_type.rb
Page 43
app/graphql/types/query_type.rb
Page 44
app/graphql/types/query_type.rb
Page 45
app/graphql/types/query_type.rb
Page 46
app/graphql/types/leave_query_type.rb
Page 47
app/graphql/types/leave_query_type.rb
Page 48
app/graphql/types/leave_query_type.rb
Page 49
app/graphql/types/leave_query_type.rb
Page 50
app/graphql/types/consultant_query_type.rb
Page 51
app/graphql/types/consultant_query_type.rb
Page 52
http://localhost:3001/graphiql
Page 53
E aí?
GraphQL
ou
REST
Page 54
Ninguém usa GraphQL- O Github já tá usando! - Retrabalho para novos
consumidores
Page 55
O Github já usa GraphQL!- A versão nova da API
(v4) não é REST- Github v3 é o primeiro
resultado no google
Page 56
GraphQL é mais fácil de evoluir- Evoluir os modelos do
grafo é mais fácil do que criar uma nova versão da API
- Mudanças destrutivas continuam quebrando os clientes, e GraphQL não versiona
Page 57
GraphQL é mais fácil de codar- Uma vez que o grafo é
definido, é fácil reutilizá-lo
Page 58
GraphiQL facilita muito a Developer Experience- Consumidores podem
explorar os dados e criar suas consultas(além de ver a documentação)
Page 59
GraphQL facilita muito a Developer Experience- APIs REST precisam
que você implemente customizações da resposta
Page 60
GraphQL + BFF = <3- GraphQL reduz o
payload (essencial para apps mobile)
Page 61
GraphQL exige mudança na mentalidade- Pensar em grafos não é
tão direto assim
Page 62
Beleza!
Quero usar GraphQL, #comofaz?
Page 63
Preciso de uma linguagemnova só pro GraphQL?
Page 64
Preciso de uma linguagemnova só pro GraphQL?
Não!
Page 65
http://graphql.org/code/
Page 66
Preciso de um servidorsó pro GraphQL?
Page 67
Preciso de um servidorsó pro GraphQL?
Não!
Page 68
REST API
GraphQL API
Page 69
GraphQL precisa estar junto com os dados?
Page 70
GraphQL precisa estar junto com os dados?
Não!
Page 72
GraphQL é apenasuma (fina) camada
Page 73
http://graphql.org/learn/thinking-in-graphs/
Page 76
https://martinfowler.com/articles/born-for-it.html
Page 78
Valeu!@marcosbrizeno