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
Introduction to GraphQL
Search
Sponsored
·
SiteGround - Reliable hosting with speed, security, and support you can count on.
→
jnwng
November 16, 2017
Technology
580
1
Share
Embed
Copy iframe code
Copy JS code
Copy link
Start on current slide
Introduction to GraphQL
Real World React November 17th, 2017
jnwng
November 16, 2017
More Decks by jnwng
See All by jnwng
Evolving the Graph
jnwng
1
310
An Introduction to GraphQL (ReactJS SF Bay Area)
jnwng
0
150
Introduction to GraphQL (Reactathon)
jnwng
0
190
Providing Flexibility Through Constraint
jnwng
0
100
Going GraphQL First - ReactSF
jnwng
0
210
Going GraphQL First
jnwng
5
760
keeping up with javascript
jnwng
3
1.1k
Presentations 101
jnwng
1
270
SViOS Meetup: HTTP Live Streaming
jnwng
2
420
Other Decks in Technology
See All in Technology
20260801_スクフェス大阪
kgnkhkr
0
120
Claude Mythos、Fable...フロンティアAIの最新動向と企業のセキュリティ対策
flatt_security
0
170
AI研修(Day1)【MIXI 26新卒技術研修】
mixi_engineers
PRO
2
2.9k
それでも、技術なブログを書く理由 #kichijojipm / Why I Still Write Tech Blogs Even Now
shinkufencer
0
1.4k
StepFunctionsとGraphRAGを活用した暗黙知活用のためのRAG基盤
yakumo
0
190
AI驚き屋発見器
yama3133
1
390
実践が先生だった— 新卒サーバーエンジニア1年目のリアル
mixi_engineers
PRO
0
210
Escolhendo LLMs na Prática: Lições Reais em Busca Agêntica no Mercado Livre —TDC 2026 Floripa
jpbonson
0
110
LangfuseによるLLMOps基盤の構築と活用事例
zozotech
PRO
1
200
最高のシステムプロンプトを作るためにフィードバック機能を導入した話
alchemy1115
1
250
データベース研修【MIXI 26新卒技術研修】
mixi_engineers
PRO
1
720
toio・myCobotでフィジカルAIっぽいことを行うための検討(とりあえず調査) / フィジカルAI LT(IoTLTによる開催)
you
PRO
0
150
Featured
See All Featured
How to audit for AI Accessibility on your Front & Back End
davetheseo
0
480
A designer walks into a library…
pauljervisheath
211
24k
Rebuilding a faster, lazier Slack
samanthasiow
85
9.6k
Redefining SEO in the New Era of Traffic Generation
szymonslowik
1
370
Visual Storytelling: How to be a Superhuman Communicator
reverentgeek
2
600
Bridging the Design Gap: How Collaborative Modelling removes blockers to flow between stakeholders and teams @FastFlow conf
baasie
0
620
Leveraging LLMs for student feedback in introductory data science courses - posit::conf(2025)
minecr
1
330
The Mindset for Success: Future Career Progression
greggifford
PRO
0
430
I Don’t Have Time: Getting Over the Fear to Launch Your Podcast
jcasabona
34
2.8k
Helping Users Find Their Own Way: Creating Modern Search Experiences
danielanewman
31
3.3k
My Coaching Mixtape
mlcsv
0
180
Claude Code のすすめ
schroneko
67
230k
Transcript
An Introduction To GraphQL Real World React, November 16, 2017
Jon Wong Frontend Infrastructure, Coursera @jnwng 2
Runtime ▪ Clients ▪ Servers ▪ Tools What We’re Covering
in GraphQL Language ▪ Schemas ▪ Queries ▪ Mutations 3
What is GraphQL? Taken straight from GraphQL.org
Describe your Data type Project { name: String tagline: String
contributors: [User] } 5
Ask for What You Want { project(name: "GraphQL") { tagline
} } 6
Get Predictable Results { project(name: "GraphQL") { tagline } }
7 { "project": { "tagline": "A query language for APIs" } }
A single endpoint for data from anywhere { book {
author { tweets amazonReviews } } } 8
Schemas Describing possible data
Describe everything that is possible ▪ All possible data results
are described by the server. 10
Validation ▪ Every query is validated against the GraphQL schema
▪ No runtime errors for query documents 11
Execution ▪ Query execution utilizes the schema to figure out
what to run, mapping them to “resolvers” 12
The GraphQL Schema gives us the basis of everything that
is possible when communicating to the server from the client. 13
Queries Reading your data
query { someField } { “data”: { “someField”: “someValue” }}
15 A simple query
query MyQueryName { fieldName } 16 A simple query with
a name
query ($someArg: String) { fieldWithArg(name: $someArg) } 17 A simple
query with arguments
query ($someArg: String) { fieldWithArg(name: $someArg) } + { “someArg”:
“my-field-name” } 18 … which requires variables
query { smallPicture: picture(size: 100) mediumPicture: picture(size: 500) largePicture: picture(size:
2000) } 19 A simple query with aliases
Fragments fragment MyFancyFragment on MyResource { someField } 20 These
are required!
Spreading a fragment in a query query { someResource {
...MyFancyFragment } } 21 These two types should match
22 A typical React application
23 … broken down into components ...
24 A complex query
25 A complex query
26 A complex query query CoursePage { course(slug: “Machine Learning”)
{ title description ...University ...Instructor } }
27 <h1>{course.title}</h1> <p>{course.description}</p> <University university={course.university} /> <Instructor instructor={course.instructor} /> Breaking
queries down with fragments query CoursePage { course(slug: “Machine Learning”) { title description ...University ...Instructor } }
28 ▪ Components can be more portable ▪ Components are
more self-sufficient. Every component can declare its own data requirements
GraphQL queries allow the client to declare exactly what it
needs, in the form that it needs it in. 29
Mutations Writing your data
mutation { addToCounter { count } } 31 A simple
mutation { “data”: { “addToCounter”: { “count”: 1 } } }
mutation { addToCounter { count } } 32 A simple
mutation This is a query
mutation { addToCounter { count } second: addToCounter { count
} } 33 Mutations execute serially { “data”: { “addToCounter”: { “count”: 1 }, “second”: { “count”: 2 } } }
Clients Managing your data
Clients make it easier to manage data Relay Apollo 35
Caching ▪ Clients provide advanced caching for GraphQL queries. 36
Caching query ListView { allBooks { id name } }
37 query DetailView ($id: ID) { bookById(id: $id) { name } }
The GraphQL HoC const Component = ({ data: { someField
}}) => <span>{someField}</span> export default graphql(gql` query { someField } `)(Component) 38
39
40 const Instructor = ({ data: { instructor }}) =>
( <View> <ProfilePhoto profile={instructor.profile} /> <span>{instructor.name}</span> </View> ); export default graphql(gql` query { instructor(id: 1) { name profile { ...ProfilePhoto } } } ${ProfilePhoto.fragment} `)(Instructor)
Clients make adopting GraphQL in your application a breeze. 41
Servers Serving your data
Mapping types to resolvers 43 const schemaDefinition = ` type
Query { books: [Book] } type Book { title: String author: String } `; const resolvers = { Query: { books: () => fetch('https://api.com/books') }, };
Every field can be resolved separately. 44 const resolvers =
{ Query: { books: () => fetch('https://api.com/books') }, Book: { reviews: () => return [], title: () => fetch(‘https://api.com/titles’) } };
A single endpoint for data from anywhere { book {
author { tweets amazonReviews } } } 45
GraphQL servers are flexible 46 ▪ They can act as
proxies to existing data ▪ They can also become the business logic layer itself
Tools Supercharging your data
GraphiQL 48
`eslint-plugin-graphql` 49 Catch invalid API calls at compile-time
`apollo-codegen` 50 Catch runtime errors at compile-time
GraphQL enables an entire ecosystem of tools to make developers
more effective. 51
▪ GraphQL makes it really simple to query lots of
data, no matter where it is. 52 In Summary
▪ Just like React, GraphQL can break down complexity into
composable, reusable pieces 53 In Summary
▪ GraphQL.org ▪ GraphQL.com ▪ https://launchpad.graphql.com/ new 54 How to
Get Started
THANKS! 55 @jnwng Presentation template by SlidesCarnival