SlideShare a Scribd company logo
Elixir + GraphQL = Absinthe
Alex Knowles
ChicagoElixir Meetup
April 10, 2019
+ =
Alex Knowles
Software Engineer
CityBase
Bruce Williams
@wbruce
Absinthe co-creator
Ben Wilson
@bewwilson512
Absinthe co-creator
Tonight’s Agenda
● GraphQL Overview
○ Who? What? Why?
○ Building blocks
● Server Demo and Absinthe code
● Dataloader
● On the horizon
● Q & A
Who is GraphQL?
[In 2012], our iOS and Android apps were
thin wrappers around views of our
mobile website. While this brought us
close to a platonic ideal of the “write
once, run anywhere” mobile application,
in practice it pushed our mobile-webview
apps beyond their limits. As Facebook’s
mobile apps became more complex, they
suffered poor performance and
frequently crashed.
- Lee Byron, Facebook
Who is GraphQL?
● Developed internally at Facebook in 2012
● Open-sourced in 2015
● GraphQL Foundation announced in November 2018
(hosted under Linux Foundation)
● Apollo launched a full GraphQL Platform in November
2018
Who is using GraphQL
What is GraphQL?
What is GraphQL?
GraphQL is a specification.
Three parts:
● GraphQL Query Language
● GraphQL Schema Language and Type System
● An algorithm for implementers: how queries should be executed against an
arbitrary type system
Credit: Marc-André Giroux
Why GraphQL?
��
We were frustrated with the differences
between the data we wanted to use in
our apps and the server queries they
required. We don’t think of data in terms
of resource URLs, secondary keys, or join
tables; we think about it in terms of a
graph of objects and the models we
ultimately use in our apps like NSObjects
or JSON.
- Lee Byron, Facebook
Why GraphQL?
● Types! Types! Types! 💪
● No more overfetching 🍕🍕🍕🍕🍕🍕🍕
● No more underfecthing 🍕
● Introspection 🔍
● More power to API consumers 🔌
● One API for everything
Strong types are so hot right now
● Dialyzer
● TypeScript
● Flow
● GraphQL!
Overfetching &
Underfetching
GET /characters/1002
Don’t care
N + 1!
Fetching Just-Right
Introspection
● Built-in types recognized by every GraphQL schema:
○ __Schema
○ __Type
○ __TypeKind
○ __Field
○ __InputValue
○ __EnumValue
○ __Directive
● API clients can form meta-queries to discover the
structure of any schema
● Tools like GraphiQL and Apollo Playground use
introspection to render schema documentation and
power auto-completion
Querying for queries (so meta)
Many articles written on GraphQL focus
on the fact that GraphQL solves the
under-fetching and over-fetching
problems. This is totally true, but to me
is a side effect of something much more
crucial: enabling any number of clients to
coexist, and survive the evolution, of a
single API server.
- Marc-André Giroux, GitHub
GraphQL, compared with RESTful Architecture
REST
● CRUD + stuff
● Lots of routes/endpoints
● API versions -- v2, v3, etc…
● API team designs and
maintains an API that works
for every client ...hopefully.
GraphQL
● Queries (reads) + Mutations (writes)
● One endpoint for all operations
● One version that evolves; deprecation
● API team designs a domain-informed
schema; API consumers build operation
documents to fit their exact needs.
GraphQL Building Blocks
GraphQL Schema
There are three operation types:
● Queries: read data
● Mutations: change data
● Subscriptions: queries, but
pushed by the server
GraphQL Types
Scalar Types (Built-in)
● Boolean
● Float
● ID (String)
● Integer
● String
Scalar Types (Absinthe.Type.Custom)
● Datetime
● NaiveDatetime
● Date
● Time
● Decimal
GraphQL Types
● Object: bag of fields (output)
● Input Object: bag of fields (input)
● Interface: contract for Objects (output only)
● Union: (output only)
● List: 0 to many, homogeneous; ex: [Droid]
GraphQL Types: Nullability
● Integer -- an integer (or null)
● Integer! -- an integer
Output types: err on the side of nullable
Input types: err on the side of non-nullable
GraphQL Types: Nullability & Lists
It can get weird
Let’s see some code
Resolvers and Dataloader
● Eager
● Fetches data
right away
I want Galactic Record THX1138.
...and record A113.
📕 Here it is!
...also XF178-9.
📗 Here it is!
📘 Here it is!
...and THX1138. 📕 Got it again!!1
● Eager
● Fetches data
right away
Oh dear!
● Naive
● Inefficient
● Lazy
● Works smart, not
hard
I want Galactic Record THX1138.
...and record A113.
...also XF178-9.
...and THX1138.
TODO
THX1138
A113
XF178-9
OK, I’m done.
Beep Boop
Whistle
📕📗📘
⁈
High five!
...
● Lazy
● Works smart, not
hard
● Efficient
● Dataloader
Dataloader
● Originally implemented by Facebook (JS)
● Absinthe team maintains Elixir version
● Batches requests
● Caches results
● Reduces fetches to data store
Elixir + GraphQL = Absinthe 2019.04.10
Topics I didn’t get to tonight
● Middleware and Authentication
● Serving REST via GraphQL (Absinthe.Phoenix.Controller)
● Mutation design
● Schema stitching
Additional reading / viewing
● Marc-André Giroux on Medium -- all of it!
○ GraphQL Mutation Design: Anemic Mutations
○ Backend For Frontends, Optimized Server Adapters, and GraphQL
○ Where we Come From: An Honest Introduction to GraphQL
● Caleb Meredith on Medium
○ When To Use GraphQL Non-Null Fields
○ Designing GraphQL Mutations
● Principled GraphQL, Apollo
● GraphQL Summit 2018, YouTube
○ GraphQL Schema Design @ Scale (Marc-André Giroux)
○ Shipping 'Belonging' with GraphQL & Apollo at Airbnb (Adam Neary)
Questions?
Thank you!
Alex Knowles
Twitter: @a_lixer
GitHub: alex-knowlesStar Wars Schema in Absinthe
https://github.com/alex-knowles/starwars_graphql_absinthe

More Related Content

PDF
Standing out as a new grad candidate
PDF
How to GraphQL
PDF
Let's talk about GraphQL
PDF
All About GRAND Stack: GraphQL, React, Apollo, and Neo4j (Mark Needham) - Gre...
PPTX
Into to GraphQL
PDF
Raphael Amorim - Scrating React Fiber
PPTX
Dynamic content with Angular
PDF
FRP with Ractive and RxJS
Standing out as a new grad candidate
How to GraphQL
Let's talk about GraphQL
All About GRAND Stack: GraphQL, React, Apollo, and Neo4j (Mark Needham) - Gre...
Into to GraphQL
Raphael Amorim - Scrating React Fiber
Dynamic content with Angular
FRP with Ractive and RxJS

What's hot (20)

PPTX
The Bleeding Edge - Whats New in Angular 2
PDF
The Apollo and GraphQL Stack
PDF
Introduction to AngularJS
ODP
Seminar globalize3 - DungNV
PDF
NE Scala 2016 roundup
PDF
Matheus Marsiglio - Isomorphic React + Redux App
PDF
Android clean architecture workshop 3h edition
PDF
Introduction to GraphQL with Ruby
ODP
Objectivec vs swift
PDF
[INNOVATUBE] Tech Talk #3: Golang - Takaaki Mizuno
PDF
Marconi: Queuing and Notification service for OpenStack
PDF
GraphQL over REST at Reactathon 2018
PDF
Why should a Java programmer shifts towards Functional Programming Paradigm
PDF
How to Build APIs - MHacks 2016
PPTX
Google Cloud Functions: try { Kotlin } instead of JavaScript
PDF
[INNOVATUBE] Tech Talk #3: Golang - Vũ Nguyễn
PDF
Railsフロントエンドの modernizeにおける一事例 ~decaffeinateからES2015移行まで~
PDF
APIdays Paris 2019 - End-to-end Type-Safe GraphQL Apps by Carlos Rufo, GraphQ...
PDF
A Journey From Objective C to Swift - Chromeinfotech
PPTX
Modern Programming Languages - An overview
The Bleeding Edge - Whats New in Angular 2
The Apollo and GraphQL Stack
Introduction to AngularJS
Seminar globalize3 - DungNV
NE Scala 2016 roundup
Matheus Marsiglio - Isomorphic React + Redux App
Android clean architecture workshop 3h edition
Introduction to GraphQL with Ruby
Objectivec vs swift
[INNOVATUBE] Tech Talk #3: Golang - Takaaki Mizuno
Marconi: Queuing and Notification service for OpenStack
GraphQL over REST at Reactathon 2018
Why should a Java programmer shifts towards Functional Programming Paradigm
How to Build APIs - MHacks 2016
Google Cloud Functions: try { Kotlin } instead of JavaScript
[INNOVATUBE] Tech Talk #3: Golang - Vũ Nguyễn
Railsフロントエンドの modernizeにおける一事例 ~decaffeinateからES2015移行まで~
APIdays Paris 2019 - End-to-end Type-Safe GraphQL Apps by Carlos Rufo, GraphQ...
A Journey From Objective C to Swift - Chromeinfotech
Modern Programming Languages - An overview
Ad

Similar to Elixir + GraphQL = Absinthe 2019.04.10 (20)

PDF
Sashko Stubailo - The GraphQL and Apollo Stack: connecting everything together
PPTX
Kotlin REST & GraphQL API
PDF
Modular GraphQL with Schema Stitching
PDF
Marco Liberati - Graph analytics
PDF
GraphQL ♥︎ GraphDB
PDF
Build, deploy and scale: Django, GraphQL and SPA (DjangoCon EU 2021)
PDF
GraphQL + relay
PDF
GraphQL is actually rest
PDF
GraphQL Bangkok meetup 5.0
PDF
Visual, scalable, and manageable data loading to and from Neo4j with Apache Hop
PDF
Functional APIs with Absinthe GraphQL
PPTX
GraphQL API Crafts presentation
PDF
Introduction to GraphQL
PDF
Getting Started with Spring for GraphQL
PPTX
GraphQL - Missing Link In REST
PPTX
Introduction to React Native
PDF
Google I/O 2014 Recap
PDF
React and GraphQL at Stripe
PDF
Building Fullstack Graph Applications With Neo4j
PDF
Collaborative data science and how to build a data science toolchain around n...
Sashko Stubailo - The GraphQL and Apollo Stack: connecting everything together
Kotlin REST & GraphQL API
Modular GraphQL with Schema Stitching
Marco Liberati - Graph analytics
GraphQL ♥︎ GraphDB
Build, deploy and scale: Django, GraphQL and SPA (DjangoCon EU 2021)
GraphQL + relay
GraphQL is actually rest
GraphQL Bangkok meetup 5.0
Visual, scalable, and manageable data loading to and from Neo4j with Apache Hop
Functional APIs with Absinthe GraphQL
GraphQL API Crafts presentation
Introduction to GraphQL
Getting Started with Spring for GraphQL
GraphQL - Missing Link In REST
Introduction to React Native
Google I/O 2014 Recap
React and GraphQL at Stripe
Building Fullstack Graph Applications With Neo4j
Collaborative data science and how to build a data science toolchain around n...
Ad

Recently uploaded (20)

DOCX
The AUB Centre for AI in Media Proposal.docx
PPTX
ACSFv1EN-58255 AWS Academy Cloud Security Foundations.pptx
PDF
Encapsulation theory and applications.pdf
PDF
Architecting across the Boundaries of two Complex Domains - Healthcare & Tech...
PDF
Empathic Computing: Creating Shared Understanding
PDF
Reach Out and Touch Someone: Haptics and Empathic Computing
PDF
cuic standard and advanced reporting.pdf
PPTX
20250228 LYD VKU AI Blended-Learning.pptx
PPTX
sap open course for s4hana steps from ECC to s4
PPTX
KOM of Painting work and Equipment Insulation REV00 update 25-dec.pptx
PPTX
Cloud computing and distributed systems.
PDF
TokAI - TikTok AI Agent : The First AI Application That Analyzes 10,000+ Vira...
PPTX
Programs and apps: productivity, graphics, security and other tools
PDF
Mobile App Security Testing_ A Comprehensive Guide.pdf
PPT
Teaching material agriculture food technology
PPT
“AI and Expert System Decision Support & Business Intelligence Systems”
PDF
Network Security Unit 5.pdf for BCA BBA.
PDF
Advanced methodologies resolving dimensionality complications for autism neur...
PDF
KodekX | Application Modernization Development
PDF
Blue Purple Modern Animated Computer Science Presentation.pdf.pdf
The AUB Centre for AI in Media Proposal.docx
ACSFv1EN-58255 AWS Academy Cloud Security Foundations.pptx
Encapsulation theory and applications.pdf
Architecting across the Boundaries of two Complex Domains - Healthcare & Tech...
Empathic Computing: Creating Shared Understanding
Reach Out and Touch Someone: Haptics and Empathic Computing
cuic standard and advanced reporting.pdf
20250228 LYD VKU AI Blended-Learning.pptx
sap open course for s4hana steps from ECC to s4
KOM of Painting work and Equipment Insulation REV00 update 25-dec.pptx
Cloud computing and distributed systems.
TokAI - TikTok AI Agent : The First AI Application That Analyzes 10,000+ Vira...
Programs and apps: productivity, graphics, security and other tools
Mobile App Security Testing_ A Comprehensive Guide.pdf
Teaching material agriculture food technology
“AI and Expert System Decision Support & Business Intelligence Systems”
Network Security Unit 5.pdf for BCA BBA.
Advanced methodologies resolving dimensionality complications for autism neur...
KodekX | Application Modernization Development
Blue Purple Modern Animated Computer Science Presentation.pdf.pdf

Elixir + GraphQL = Absinthe 2019.04.10

  • 1. Elixir + GraphQL = Absinthe Alex Knowles ChicagoElixir Meetup April 10, 2019 + =
  • 3. Bruce Williams @wbruce Absinthe co-creator Ben Wilson @bewwilson512 Absinthe co-creator
  • 4. Tonight’s Agenda ● GraphQL Overview ○ Who? What? Why? ○ Building blocks ● Server Demo and Absinthe code ● Dataloader ● On the horizon ● Q & A
  • 6. [In 2012], our iOS and Android apps were thin wrappers around views of our mobile website. While this brought us close to a platonic ideal of the “write once, run anywhere” mobile application, in practice it pushed our mobile-webview apps beyond their limits. As Facebook’s mobile apps became more complex, they suffered poor performance and frequently crashed. - Lee Byron, Facebook
  • 7. Who is GraphQL? ● Developed internally at Facebook in 2012 ● Open-sourced in 2015 ● GraphQL Foundation announced in November 2018 (hosted under Linux Foundation) ● Apollo launched a full GraphQL Platform in November 2018
  • 8. Who is using GraphQL
  • 10. What is GraphQL? GraphQL is a specification. Three parts: ● GraphQL Query Language ● GraphQL Schema Language and Type System ● An algorithm for implementers: how queries should be executed against an arbitrary type system Credit: Marc-André Giroux
  • 12. We were frustrated with the differences between the data we wanted to use in our apps and the server queries they required. We don’t think of data in terms of resource URLs, secondary keys, or join tables; we think about it in terms of a graph of objects and the models we ultimately use in our apps like NSObjects or JSON. - Lee Byron, Facebook
  • 13. Why GraphQL? ● Types! Types! Types! 💪 ● No more overfetching 🍕🍕🍕🍕🍕🍕🍕 ● No more underfecthing 🍕 ● Introspection 🔍 ● More power to API consumers 🔌 ● One API for everything
  • 14. Strong types are so hot right now ● Dialyzer ● TypeScript ● Flow ● GraphQL!
  • 17. Introspection ● Built-in types recognized by every GraphQL schema: ○ __Schema ○ __Type ○ __TypeKind ○ __Field ○ __InputValue ○ __EnumValue ○ __Directive ● API clients can form meta-queries to discover the structure of any schema ● Tools like GraphiQL and Apollo Playground use introspection to render schema documentation and power auto-completion
  • 18. Querying for queries (so meta)
  • 19. Many articles written on GraphQL focus on the fact that GraphQL solves the under-fetching and over-fetching problems. This is totally true, but to me is a side effect of something much more crucial: enabling any number of clients to coexist, and survive the evolution, of a single API server. - Marc-André Giroux, GitHub
  • 20. GraphQL, compared with RESTful Architecture REST ● CRUD + stuff ● Lots of routes/endpoints ● API versions -- v2, v3, etc… ● API team designs and maintains an API that works for every client ...hopefully. GraphQL ● Queries (reads) + Mutations (writes) ● One endpoint for all operations ● One version that evolves; deprecation ● API team designs a domain-informed schema; API consumers build operation documents to fit their exact needs.
  • 22. GraphQL Schema There are three operation types: ● Queries: read data ● Mutations: change data ● Subscriptions: queries, but pushed by the server
  • 23. GraphQL Types Scalar Types (Built-in) ● Boolean ● Float ● ID (String) ● Integer ● String Scalar Types (Absinthe.Type.Custom) ● Datetime ● NaiveDatetime ● Date ● Time ● Decimal
  • 24. GraphQL Types ● Object: bag of fields (output) ● Input Object: bag of fields (input) ● Interface: contract for Objects (output only) ● Union: (output only) ● List: 0 to many, homogeneous; ex: [Droid]
  • 25. GraphQL Types: Nullability ● Integer -- an integer (or null) ● Integer! -- an integer Output types: err on the side of nullable Input types: err on the side of non-nullable
  • 26. GraphQL Types: Nullability & Lists It can get weird
  • 29. ● Eager ● Fetches data right away
  • 30. I want Galactic Record THX1138. ...and record A113. 📕 Here it is! ...also XF178-9. 📗 Here it is! 📘 Here it is! ...and THX1138. 📕 Got it again!!1
  • 31. ● Eager ● Fetches data right away Oh dear! ● Naive ● Inefficient
  • 32. ● Lazy ● Works smart, not hard
  • 33. I want Galactic Record THX1138. ...and record A113. ...also XF178-9. ...and THX1138. TODO THX1138 A113 XF178-9 OK, I’m done. Beep Boop Whistle 📕📗📘 ⁈ High five! ...
  • 34. ● Lazy ● Works smart, not hard ● Efficient ● Dataloader
  • 35. Dataloader ● Originally implemented by Facebook (JS) ● Absinthe team maintains Elixir version ● Batches requests ● Caches results ● Reduces fetches to data store
  • 37. Topics I didn’t get to tonight ● Middleware and Authentication ● Serving REST via GraphQL (Absinthe.Phoenix.Controller) ● Mutation design ● Schema stitching
  • 38. Additional reading / viewing ● Marc-André Giroux on Medium -- all of it! ○ GraphQL Mutation Design: Anemic Mutations ○ Backend For Frontends, Optimized Server Adapters, and GraphQL ○ Where we Come From: An Honest Introduction to GraphQL ● Caleb Meredith on Medium ○ When To Use GraphQL Non-Null Fields ○ Designing GraphQL Mutations ● Principled GraphQL, Apollo ● GraphQL Summit 2018, YouTube ○ GraphQL Schema Design @ Scale (Marc-André Giroux) ○ Shipping 'Belonging' with GraphQL & Apollo at Airbnb (Adam Neary)
  • 40. Thank you! Alex Knowles Twitter: @a_lixer GitHub: alex-knowlesStar Wars Schema in Absinthe https://github.com/alex-knowles/starwars_graphql_absinthe