{
myShop {
name
location {
city
address
}
products(orderby: POPULARITY) {
name
price
}
}
}
Slide 38
Slide 38 text
type Address {
city: String
address: String
}
Slide 39
Slide 39 text
{
myShop {
name
location {
city
address
}
products(orderby: POPULARITY) {
name
price
}
}
}
Slide 40
Slide 40 text
type Product {
name: String
price: Int
}
Slide 41
Slide 41 text
Fragments
Slide 42
Slide 42 text
{
myShop {
name
location {
city
address
}
products(orderby: POPULARITY) {
id
name
price
}
}
}
Slide 43
Slide 43 text
No content
Slide 44
Slide 44 text
{
myShop {
name
location {
city
address
}
products(orderby: POPULARITY) {
id
name
price
}
}
}
Slide 45
Slide 45 text
fragment productFields on Product {
id
name
price
}
Slide 46
Slide 46 text
{
myShop {
name
location {
city
address
}
products(orderby: POPULARITY) {
...productFields
}
}
}
Slide 47
Slide 47 text
query
Fragment
Fragment
Fragment Fragment
Slide 48
Slide 48 text
Introspection
Slide 49
Slide 49 text
query {
__schema {
…
}
}
Slide 50
Slide 50 text
Static Validation
Code Generation
IDE Integration
Auto Documentation
Slide 51
Slide 51 text
No content
Slide 52
Slide 52 text
No content
Slide 53
Slide 53 text
Resolving fields
Slide 54
Slide 54 text
type Product {
name: String
price: Int
}
Slide 55
Slide 55 text
ProductType = GraphQL::ObjectType.define do
name "Product"
description “A product sold at a shop”
# …
end
Slide 56
Slide 56 text
field :name do
type types.String
resolve -> (obj, args, ctx) { obj.name }
end
Slide 57
Slide 57 text
field :price do
type types.Int
resolve -> (obj, args, ctx) do
obj.subtotal + obj.taxes + obj.shipping_price
end
end
Slide 58
Slide 58 text
field :price do
type types.Int
resolve -> (obj, args, ctx) do
obj.subtotal + obj.taxes + obj.shipping_price
end
end
Slide 59
Slide 59 text
POST /graphql
Slide 60
Slide 60 text
Mutations
Slide 61
Slide 61 text
mutation {
createProduct(name: “Nice Mug”, price: 10000) {
id
name
}
}
Slide 62
Slide 62 text
Drawbacks
and solutions
Slide 63
Slide 63 text
N+1 Queries
Slide 64
Slide 64 text
field :image do
type ImageType
resolve -> (product, args, ctx) do
product.image
end
end
field :products do
type [ProductType]
resolve -> (shop, args, ctx) do
shop.products
end
end
Slide 65
Slide 65 text
Product Load (1.0ms) SELECT "products".* FROM "products"
WHERE "products"."shop_id" = …
Image Load (0.9ms) SELECT "images".* FROM "images"
WHERE "images"."product_id" = …
Image Load (0.2ms) SELECT "images".* FROM "images"
WHERE "images"."product_id" = …
Image Load (0.1ms) SELECT "images".* FROM "images"
WHERE "images"."product_id" = …
Slide 66
Slide 66 text
Solution: Batching + Caching
Slide 67
Slide 67 text
field :image do
type ImageType
resolve -> (product, args, ctx) do
RecordLoader.for(Image).load(product.image_id)
end
end