Upgrade to Pro
— share decks privately, control downloads, hide ads and more …
Speaker Deck
Features
Speaker Deck
PRO
Sign in
Sign up for free
Search
Search
GraphQl, Front queries made easy
Search
Igor Halfeld
December 01, 2018
Programming
2
47
GraphQl, Front queries made easy
How to deal with graphql on client-side
Igor Halfeld
December 01, 2018
Tweet
Share
More Decks by Igor Halfeld
See All by Igor Halfeld
Modular monoliths with fastify
igorhalfeld
0
140
How to migrate legacy frontend?
igorhalfeld
1
100
Patterns for perfect components in Vue.js
igorhalfeld
0
100
Clean Architecture no Front-end (update 2021-05-11)
igorhalfeld
0
46
Step by step I followed a career in software
igorhalfeld
0
690
Using AI to create memes
igorhalfeld
0
500
Deninho, the TS children
igorhalfeld
1
200
Micro Front-ends, what they don't tell you
igorhalfeld
0
360
CSS in JavaScripto, the anti-pattern that is good
igorhalfeld
1
84
Other Decks in Programming
See All in Programming
とにかくAWS GameDay!AWSは世界の共通言語! / Anyway, AWS GameDay! AWS is the world's lingua franca!
seike460
PRO
1
880
Less waste, more joy, and a lot more green: How Quarkus makes Java better
hollycummins
0
100
Pinia Colada が実現するスマートな非同期処理
naokihaba
4
230
シェーダーで魅せるMapLibreの動的ラスタータイル
satoshi7190
1
480
Amazon Qを使ってIaCを触ろう!
maruto
0
410
聞き手から登壇者へ: RubyKaigi2024 LTでの初挑戦が 教えてくれた、可能性の星
mikik0
1
130
イベント駆動で成長して委員会
happymana
1
320
3 Effective Rules for Using Signals in Angular
manfredsteyer
PRO
1
100
AWS Lambdaから始まった Serverlessの「熱」とキャリアパス / It started with AWS Lambda Serverless “fever” and career path
seike460
PRO
1
260
[Do iOS '24] Ship your app on a Friday...and enjoy your weekend!
polpielladev
0
110
3 Effective Rules for Using Signals in Angular
manfredsteyer
PRO
0
100
Why Jakarta EE Matters to Spring - and Vice Versa
ivargrimstad
0
1.1k
Featured
See All Featured
Designing for Performance
lara
604
68k
Docker and Python
trallard
40
3.1k
The Power of CSS Pseudo Elements
geoffreycrofte
73
5.3k
Into the Great Unknown - MozCon
thekraken
32
1.5k
Happy Clients
brianwarren
98
6.7k
Easily Structure & Communicate Ideas using Wireframe
afnizarnur
191
16k
Save Time (by Creating Custom Rails Generators)
garrettdimon
PRO
27
840
Building an army of robots
kneath
302
43k
Evolution of real-time – Irina Nazarova, EuRuKo, 2024
irinanazarova
4
370
Building a Scalable Design System with Sketch
lauravandoore
459
33k
Writing Fast Ruby
sferik
627
61k
ReactJS: Keep Simple. Everything can be a component!
pedronauck
665
120k
Transcript
GraphQl. Front-end queries made easy.
Igor Halfeld Software Engineer & Consultancy igorluiz.me - @IgorHalfeld
Conheça minha história. Onde tudo começou…
None
Objetivo. Onde eu quero chegar…
None
Vamos contextualizar. Como chegamos até aqui?
ZONA DARK SOAP REST #TRISTEZA #SEMCROSSFIT
"Analisarmos alternativas, como o REST. (…) Ficamos frustrados com as
diferenças entre os dados que queríamos e as requests que eram necessárias para obtê-los.” Lee Byron
2012. GraphQl é criado pelo Facebook apenas para uso interno.
2015. É liberado como open source!
Que rolê é esse?
Duas partes. Consumir no front-end e fazer no back-end. *dar
uma olhada nos conceitos antes.
GraphQl Server Data Sources Clients JSON bonitão lindão GraphQl Queries
Resolvers
None
REST tem vários endpoints em que cada um retorna dados
fixos. GraphQl tem um único endpoint que retorna uma estrutura flexível.
REST GET - /users/:id { “name”: “Igor Halfeld”, “email”: “
[email protected]
”,
“state”: “RJ" } GraphQl POST - /graphql { “data”: { “name”: “Igor Halfeld” } } { query { Users (id: “666") { name } } }
3 pilares. Query, Mutation, Subscription.
REST GET GraphQl POST PUT DELETE Query Mutations
{ query { users { name, email } } }
{ query { users (id: “666”) { name, email } } } GET - /users/:id GET - /users
{ mutation { createUser ( name: "Igor Luiz”, email: “
[email protected]
"
) { name, email } } } CREATE - /users { mutation { updateUser ( name: “Halfeld Igor” ) { name, email } } } PUT - /users/:id
{ mutation { deleteUser (id: “666”) { name, email }
} } DELETE - /users
None
O que muda no front é… Basicamente, saber fazer GraphQl
SDL.
type Users { name: String! email: String! skills: [String]! addresses:
[Address] } type Address { street: String, number: Number } GraphQl SDL (Schema Definition Language)
{ Query { users (id: “666”) { name, height (unit:
METERS) } } } Resolvers <3
{ Query { users { admin (role: ADMIN) { …userFields
} accountants (role: ACCOUNTANT) { …userFields } } } } fragment userFields on User { user, name } Fragments
{ Query { users ($id: ID) { name, email }
} } { id: “666" } Variables
Client de GraphQl. Se é tudo POST, eu posso usar
o axios, certo?
Sim, mas não! Você precisa! Justamente para aproveitar melhor os
benefícios do graphql.
None
Certeza que vai fazer a query de forma certa. Cache
built-it: performance. Consistência na UI: Cache reativo.
None
None
None
Como tamo agora?
None
None
None
Tooling. Ferramental daóra.
None
None
GraphQl faker.
GraphQl Voyager.
DEMO TIME!
bit.ly/demo-floripa
Obrigado! igorluiz.me/talks - @IgorHalfeld