KEMBAR78
Elixir absinthe-basics | ODP
Ruben Amortegui
@ramortegui
http://rubenamortegui.com
https://github.com/ramortegui
Absinthe
GraphQL Basics
GraphQL
● A query language for your API
– Ask for what you need, get exactly that.
– Get many resources in a single request
– Describe what is possible with a type system
– Move faster with powerful developer tools
– Bring your own data an code
– Evolve your API without versions
http://graphql.org/
GraphQL as Specification
– Language
– Type System
– Introspection
– Validation
– Execution
– Response
http://facebook.github.io/graphql/October2016/
GraphQL
● Why?
– REST (REpresentational State Transfer)
● What is on the response?
● What if we need more info
● What if we don’t need all the info
● Validations
– GraphQL
● Give the developer a query language to interact with the server
● Provides validation of data by default
● Handle relationships
● Give proper error messages
● What you ask is what you expect
● Single point of entrance
Basic architecture
GraphQL
● It’s not magic
● You need to build the representation of your
data.
Schema sample
Built-in types
Relations
Custom Types
Query representation sample
{
profile{
name
age
friends{
name
}
}
}
What is Absinthe
● GraphQL toolkit for elixir
– absinthe
– absinthe_plug
– absinthe_phoenix
Absinthe
Basic Sample
● Create a API to manage a Todo application.
– Design a Schema
– Query
– Mutation
– Test
“Todo” DB
“Todo” GraphQL Schema
“Todo” GraphQL Schema
● Queries
{
todos {
name
categories {
name
}
}
}
TODO GraphQL
Create a phx app
TODO GraphQL
Create a phx app
TODO GraphQL
Add tables and run migration
TODO GraphQL
Add tables and run migration
TODO GraphQL
Create seed data
TODO GraphQL
Add absinthe library
TODO GraphQL
Add schema
TODO GraphQL
Add routes
TODO GraphQL
Test
Query Sample
TODO GraphQL
Mutation
Other Fun Stuff
● Use variables to do queries
– Unions
– Interfaces
– Fragments
● Create your own Scalar types
– Parse
– Serialize
● Organize your code
– Import fields
– Import types
● Subscriptions
● Publishing your code “middleware”
● Authentication and Authorization
● Tunning Performance
References
● http://graphql.org/
● http://facebook.github.io/graphql/October2016/
● Williams, B. Willson, B. (2017). Craft GraphQL
APIs in Elixir with Absinthe, Beta (Nov. 2017):
The pragmatic programmers.
Next Meetups
● Elixir
– Ecto
– Test
– OTP
Thanks!
Q & A?
@ramortegui
http://rubenamortegui.com
https://github.com/ramortegui

Elixir absinthe-basics