SlideShare a Scribd company logo
Introduction to GraphQL
in Scala
Yuki Katada
ScalaMatsuri 2017
Scalaで始めるGraphQL
About Me
Name
• Yuki Katada (片田雄樹)
Affiliation
• CyberAgent, Inc.
• Media Development Headquarters (メディアディベロップメント事業本部)
Scala Experience
• One and a half years
Follow Me
• On Twitter @ponyoky ← very few ppl are following me :(
自己紹介
Our Job
• We are developing Advertising Network, which delivers Ads to
multiple media such as CyberAgent “Ameba”.
• Approximate 700 users are using our product.
• Our product has more than 600 million incoming traffics per day
• We are using GraphQL at Admin Page, which requires complex
queries
我々のプロダクトはAmebaメディアに対する広告を配信するシ
ステムで、その管理画面部分でGraphQLを使用しています。
What is GraphQL?
GraphQLとは?
What is GraphQL?
GraphQL is a query language, which is developed by Facebook.
It provides an alternative to REST. (Not Graph DB)
Some GraphQL libraries are provided as following:
• Javascript
• Python
• Scala
• and more.
GraphQLとはRESTの代替としての立ち位置のクエリ言語です。
Why GraphQL?
なぜGraphQLなのか?
Multiple requests in REST
Endpoints
/users
/books
/companies
.
.
.
I want resources at
“/users”
and
“/books”
and
“/companies”
REST
server client
database
Users
Books
Companies
RESTでは複数リソースを取得するために複数のリクエストが
必要となります。
Multiple requests in REST
Resources
Users
Books
Companies
/users
/books
/companies
Endpoints
複数のリソースに対して複数のエンドポイントが紐付いていま
す。
REST
REST requires n requests to retrieve n different resources.
So if website required 100 different resources…?
RESTでは大量のリクエストが発生する可能性がある。
Single request in GraphQL
Endpoint
/graphql
I want resources at
“/users”
and
“/books”
and
“/companies”
GraphQL
server client
database
Users
Books
Companies
GraphQLでは単一のリクエストのみで複数のリソースが取得で
きます。
Single request in GraphQL
Resources
Users
Books
Companies
/graphql
Endpoint
“query” :
“{
user
book
company
}”
Request Body
なので、1つのエンドポイントに複数のリソースが紐付いてい
る状態です。
GraphQL
GraphQL in Scala
ScalaでのGraphQL
GraphQL library for Scala
Sangria
● The most famous Scala GraphQL library
● Github Repo
○ https://github.com/sangria-graphql/sangria
● There is an awesome documentation
○ http://sangria-graphql.org/
Scalaで実装されたGraphQLライブラリ「Sangria」
In my example, I prepared dummy data.
These resources are same as a previous
example; users, books, and companies
In general, DummyData would be a
database or data source.
DummyData.scala
今回の例では、ダミーデータを使用した例で説明します。
In DummyDataRepo class,
I defined 3 methods to
retrieve each resource.
DummyRepo.scala
ダミーデータを取得するレポジトリクラスを定義します。
GraphQLの根幹となる、オブジェクト構造を定義したクラスの
例です。
This is SchemaDefinition
object, which defines
Single Endpoint,
Arguments, and Object
Structures.
In GraphQL, we have to
define Object Structures
to map onto query AST
of request body.
SchemaDefinition.scala
When you retrieve resources from this API, you need to access in HTTP
Post method.
In this example, I requests user data with id = 1, and the right side JSON
shows response.
GraphQLクエリでAPIリクエストした場合の例です。
Please look at my sample code on Github for more detail.
https://github.com/yuki-katada/scalamatsuri_sangria
詳細はGithubを参照してください。
Pros/Cons
実際に使ってみて見えてきた長所と短所
Pros
• Less HTTP requests (less API access) compared to REST
• Additional server side implementation is not required in many cases
– Only client side modification to GraphQL query is required
• GraphiQL makes tests/debugs easier
– An interactive in-browser IDE for GraphQL
長所
Cons
• It is very hard to design Domain-Specific architecture
• Client Side is required to write very long request body
– Who wants to write string formatted & type-unsafe request body…?
• Many people struggle with GraphQL query
– It is hard to understand for many people
短所
Result
Cons are too critical compared to pros…
So we decided to replace GraphQL with REST :(
結果
Thank you for listening :)

More Related Content

Similar to Introduction to GraphQL in Scala (20)

PDF
GraphQL – the future of APIs?
Dmitry Stropalov
 
PDF
GraphQL vs Traditional Rest API
Vladimir Dejanovic
 
PDF
Hands On - GraphQL
Breno Henrique de Lima Freitas
 
PDF
GraphQL-ify your APIs
Soham Dasgupta
 
PDF
GraphQL in Ruby on Rails - basics
Visuality
 
PPTX
Introduction to Graph QL
Deepak More
 
PDF
Let's talk about GraphQL
Commit Software Sh.p.k.
 
PDF
Intro to GraphQL
Rakuten Group, Inc.
 
PPTX
GraphQL_devoxx_2023.pptx
Soham Dasgupta
 
PDF
Graphql
Neven Rakonić
 
PDF
What/How to do with GraphQL? - Valentyn Ostakh (ENG) | Ruby Meditation 27
Ruby Meditation
 
PDF
Let's start GraphQL: structure, behavior, and architecture
Andrii Gakhov
 
PPTX
Introduction to Testing GraphQL Presentation
Knoldus Inc.
 
PPTX
Testing Graph QL Presentation (Test Automation)
Knoldus Inc.
 
PDF
GraphQL-ify your API - JFall 2022
Soham Dasgupta
 
PPTX
GraphQL @ Manc.JS (March 2018)
Chris Grice
 
PDF
Testing and Developing GraphQL APIs
Postman
 
PDF
Graphql
Niv Ben David
 
PPTX
The API Journey: from REST to GraphQL
Haci Murat Yaman
 
PDF
GraphQL- Presentation
Ridwan Fadjar
 
GraphQL – the future of APIs?
Dmitry Stropalov
 
GraphQL vs Traditional Rest API
Vladimir Dejanovic
 
Hands On - GraphQL
Breno Henrique de Lima Freitas
 
GraphQL-ify your APIs
Soham Dasgupta
 
GraphQL in Ruby on Rails - basics
Visuality
 
Introduction to Graph QL
Deepak More
 
Let's talk about GraphQL
Commit Software Sh.p.k.
 
Intro to GraphQL
Rakuten Group, Inc.
 
GraphQL_devoxx_2023.pptx
Soham Dasgupta
 
What/How to do with GraphQL? - Valentyn Ostakh (ENG) | Ruby Meditation 27
Ruby Meditation
 
Let's start GraphQL: structure, behavior, and architecture
Andrii Gakhov
 
Introduction to Testing GraphQL Presentation
Knoldus Inc.
 
Testing Graph QL Presentation (Test Automation)
Knoldus Inc.
 
GraphQL-ify your API - JFall 2022
Soham Dasgupta
 
GraphQL @ Manc.JS (March 2018)
Chris Grice
 
Testing and Developing GraphQL APIs
Postman
 
Graphql
Niv Ben David
 
The API Journey: from REST to GraphQL
Haci Murat Yaman
 
GraphQL- Presentation
Ridwan Fadjar
 

More from scalaconfjp (20)

PDF
脆弱性対策のためのClean Architecture ~脆弱性に対するレジリエンスを確保せよ~
scalaconfjp
 
PDF
Alp x BizReach SaaS事業を営む2社がお互い気になることをゆるゆる聞いてみる会
scalaconfjp
 
PDF
GraalVM Overview Compact version
scalaconfjp
 
PDF
Run Scala Faster with GraalVM on any Platform / GraalVMで、どこでもScalaを高速実行しよう by...
scalaconfjp
 
PPTX
Monitoring Reactive Architecture Like Never Before / 今までになかったリアクティブアーキテクチャの監視...
scalaconfjp
 
PPTX
Scala 3, what does it means for me? / Scala 3って、私にはどんな影響があるの? by Joan Goyeau
scalaconfjp
 
PDF
Functional Object-Oriented Imperative Scala / 関数型オブジェクト指向命令型 Scala by Sébasti...
scalaconfjp
 
PDF
Scala ♥ Graal by Flavio Brasil
scalaconfjp
 
PDF
Safety Beyond Types
scalaconfjp
 
PDF
Reactive Kafka with Akka Streams
scalaconfjp
 
PDF
Reactive microservices with play and akka
scalaconfjp
 
PDF
Scalaに対して意識の低いエンジニアがScalaで何したかの話, by 芸者東京エンターテインメント
scalaconfjp
 
PDF
DWANGO by ドワンゴ
scalaconfjp
 
PDF
OCTOPARTS by M3, Inc.
scalaconfjp
 
PDF
Try using Aeromock by Marverick, Inc.
scalaconfjp
 
PDF
統計をとって高速化する
Scala開発 by CyberZ,Inc.
scalaconfjp
 
PDF
Short Introduction of Implicit Conversion by TIS, Inc.
scalaconfjp
 
PPTX
ビズリーチ x ScalaMatsuri by BIZREACH, Inc.
scalaconfjp
 
PDF
sbt, past and future / sbt, 傾向と対策
scalaconfjp
 
PDF
The Evolution of Scala / Scala進化論
scalaconfjp
 
脆弱性対策のためのClean Architecture ~脆弱性に対するレジリエンスを確保せよ~
scalaconfjp
 
Alp x BizReach SaaS事業を営む2社がお互い気になることをゆるゆる聞いてみる会
scalaconfjp
 
GraalVM Overview Compact version
scalaconfjp
 
Run Scala Faster with GraalVM on any Platform / GraalVMで、どこでもScalaを高速実行しよう by...
scalaconfjp
 
Monitoring Reactive Architecture Like Never Before / 今までになかったリアクティブアーキテクチャの監視...
scalaconfjp
 
Scala 3, what does it means for me? / Scala 3って、私にはどんな影響があるの? by Joan Goyeau
scalaconfjp
 
Functional Object-Oriented Imperative Scala / 関数型オブジェクト指向命令型 Scala by Sébasti...
scalaconfjp
 
Scala ♥ Graal by Flavio Brasil
scalaconfjp
 
Safety Beyond Types
scalaconfjp
 
Reactive Kafka with Akka Streams
scalaconfjp
 
Reactive microservices with play and akka
scalaconfjp
 
Scalaに対して意識の低いエンジニアがScalaで何したかの話, by 芸者東京エンターテインメント
scalaconfjp
 
DWANGO by ドワンゴ
scalaconfjp
 
OCTOPARTS by M3, Inc.
scalaconfjp
 
Try using Aeromock by Marverick, Inc.
scalaconfjp
 
統計をとって高速化する
Scala開発 by CyberZ,Inc.
scalaconfjp
 
Short Introduction of Implicit Conversion by TIS, Inc.
scalaconfjp
 
ビズリーチ x ScalaMatsuri by BIZREACH, Inc.
scalaconfjp
 
sbt, past and future / sbt, 傾向と対策
scalaconfjp
 
The Evolution of Scala / Scala進化論
scalaconfjp
 
Ad

Recently uploaded (20)

PPTX
3uTools Full Crack Free Version Download [Latest] 2025
muhammadgurbazkhan
 
PPTX
Tally_Basic_Operations_Presentation.pptx
AditiBansal54083
 
PPTX
Writing Better Code - Helping Developers make Decisions.pptx
Lorraine Steyn
 
PPTX
An Introduction to ZAP by Checkmarx - Official Version
Simon Bennetts
 
PDF
Capcut Pro Crack For PC Latest Version {Fully Unlocked} 2025
hashhshs786
 
PPTX
Comprehensive Guide: Shoviv Exchange to Office 365 Migration Tool 2025
Shoviv Software
 
PDF
유니티에서 Burst Compiler+ThreadedJobs+SIMD 적용사례
Seongdae Kim
 
PDF
Efficient, Automated Claims Processing Software for Insurers
Insurance Tech Services
 
PDF
Thread In Android-Mastering Concurrency for Responsive Apps.pdf
Nabin Dhakal
 
PDF
Why Businesses Are Switching to Open Source Alternatives to Crystal Reports.pdf
Varsha Nayak
 
PDF
Unlock Efficiency with Insurance Policy Administration Systems
Insurance Tech Services
 
PDF
Build It, Buy It, or Already Got It? Make Smarter Martech Decisions
bbedford2
 
PPTX
Migrating Millions of Users with Debezium, Apache Kafka, and an Acyclic Synch...
MD Sayem Ahmed
 
PPTX
Agentic Automation Journey Session 1/5: Context Grounding and Autopilot for E...
klpathrudu
 
PPTX
Platform for Enterprise Solution - Java EE5
abhishekoza1981
 
PPTX
Revolutionizing Code Modernization with AI
KrzysztofKkol1
 
PPTX
Feb 2021 Cohesity first pitch presentation.pptx
enginsayin1
 
DOCX
Import Data Form Excel to Tally Services
Tally xperts
 
PPTX
Equipment Management Software BIS Safety UK.pptx
BIS Safety Software
 
PPTX
MailsDaddy Outlook OST to PST converter.pptx
abhishekdutt366
 
3uTools Full Crack Free Version Download [Latest] 2025
muhammadgurbazkhan
 
Tally_Basic_Operations_Presentation.pptx
AditiBansal54083
 
Writing Better Code - Helping Developers make Decisions.pptx
Lorraine Steyn
 
An Introduction to ZAP by Checkmarx - Official Version
Simon Bennetts
 
Capcut Pro Crack For PC Latest Version {Fully Unlocked} 2025
hashhshs786
 
Comprehensive Guide: Shoviv Exchange to Office 365 Migration Tool 2025
Shoviv Software
 
유니티에서 Burst Compiler+ThreadedJobs+SIMD 적용사례
Seongdae Kim
 
Efficient, Automated Claims Processing Software for Insurers
Insurance Tech Services
 
Thread In Android-Mastering Concurrency for Responsive Apps.pdf
Nabin Dhakal
 
Why Businesses Are Switching to Open Source Alternatives to Crystal Reports.pdf
Varsha Nayak
 
Unlock Efficiency with Insurance Policy Administration Systems
Insurance Tech Services
 
Build It, Buy It, or Already Got It? Make Smarter Martech Decisions
bbedford2
 
Migrating Millions of Users with Debezium, Apache Kafka, and an Acyclic Synch...
MD Sayem Ahmed
 
Agentic Automation Journey Session 1/5: Context Grounding and Autopilot for E...
klpathrudu
 
Platform for Enterprise Solution - Java EE5
abhishekoza1981
 
Revolutionizing Code Modernization with AI
KrzysztofKkol1
 
Feb 2021 Cohesity first pitch presentation.pptx
enginsayin1
 
Import Data Form Excel to Tally Services
Tally xperts
 
Equipment Management Software BIS Safety UK.pptx
BIS Safety Software
 
MailsDaddy Outlook OST to PST converter.pptx
abhishekdutt366
 
Ad

Introduction to GraphQL in Scala

  • 1. Introduction to GraphQL in Scala Yuki Katada ScalaMatsuri 2017 Scalaで始めるGraphQL
  • 2. About Me Name • Yuki Katada (片田雄樹) Affiliation • CyberAgent, Inc. • Media Development Headquarters (メディアディベロップメント事業本部) Scala Experience • One and a half years Follow Me • On Twitter @ponyoky ← very few ppl are following me :( 自己紹介
  • 3. Our Job • We are developing Advertising Network, which delivers Ads to multiple media such as CyberAgent “Ameba”. • Approximate 700 users are using our product. • Our product has more than 600 million incoming traffics per day • We are using GraphQL at Admin Page, which requires complex queries 我々のプロダクトはAmebaメディアに対する広告を配信するシ ステムで、その管理画面部分でGraphQLを使用しています。
  • 5. What is GraphQL? GraphQL is a query language, which is developed by Facebook. It provides an alternative to REST. (Not Graph DB) Some GraphQL libraries are provided as following: • Javascript • Python • Scala • and more. GraphQLとはRESTの代替としての立ち位置のクエリ言語です。
  • 7. Multiple requests in REST Endpoints /users /books /companies . . . I want resources at “/users” and “/books” and “/companies” REST server client database Users Books Companies RESTでは複数リソースを取得するために複数のリクエストが 必要となります。
  • 8. Multiple requests in REST Resources Users Books Companies /users /books /companies Endpoints 複数のリソースに対して複数のエンドポイントが紐付いていま す。 REST
  • 9. REST requires n requests to retrieve n different resources. So if website required 100 different resources…? RESTでは大量のリクエストが発生する可能性がある。
  • 10. Single request in GraphQL Endpoint /graphql I want resources at “/users” and “/books” and “/companies” GraphQL server client database Users Books Companies GraphQLでは単一のリクエストのみで複数のリソースが取得で きます。
  • 11. Single request in GraphQL Resources Users Books Companies /graphql Endpoint “query” : “{ user book company }” Request Body なので、1つのエンドポイントに複数のリソースが紐付いてい る状態です。 GraphQL
  • 13. GraphQL library for Scala Sangria ● The most famous Scala GraphQL library ● Github Repo ○ https://github.com/sangria-graphql/sangria ● There is an awesome documentation ○ http://sangria-graphql.org/ Scalaで実装されたGraphQLライブラリ「Sangria」
  • 14. In my example, I prepared dummy data. These resources are same as a previous example; users, books, and companies In general, DummyData would be a database or data source. DummyData.scala 今回の例では、ダミーデータを使用した例で説明します。
  • 15. In DummyDataRepo class, I defined 3 methods to retrieve each resource. DummyRepo.scala ダミーデータを取得するレポジトリクラスを定義します。
  • 16. GraphQLの根幹となる、オブジェクト構造を定義したクラスの 例です。 This is SchemaDefinition object, which defines Single Endpoint, Arguments, and Object Structures. In GraphQL, we have to define Object Structures to map onto query AST of request body. SchemaDefinition.scala
  • 17. When you retrieve resources from this API, you need to access in HTTP Post method. In this example, I requests user data with id = 1, and the right side JSON shows response. GraphQLクエリでAPIリクエストした場合の例です。
  • 18. Please look at my sample code on Github for more detail. https://github.com/yuki-katada/scalamatsuri_sangria 詳細はGithubを参照してください。
  • 20. Pros • Less HTTP requests (less API access) compared to REST • Additional server side implementation is not required in many cases – Only client side modification to GraphQL query is required • GraphiQL makes tests/debugs easier – An interactive in-browser IDE for GraphQL 長所
  • 21. Cons • It is very hard to design Domain-Specific architecture • Client Side is required to write very long request body – Who wants to write string formatted & type-unsafe request body…? • Many people struggle with GraphQL query – It is hard to understand for many people 短所
  • 22. Result Cons are too critical compared to pros… So we decided to replace GraphQL with REST :( 結果
  • 23. Thank you for listening :)