Introduction to GraphQL in Scala

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 :)
1 of 23

Recommended

Amplify로 Neptune 그래프 DB 기반 모바일 앱 만들기 :: 김현민 - AWS Community Day 2019 by
Amplify로 Neptune 그래프 DB 기반 모바일 앱 만들기 :: 김현민 - AWS Community Day 2019Amplify로 Neptune 그래프 DB 기반 모바일 앱 만들기 :: 김현민 - AWS Community Day 2019
Amplify로 Neptune 그래프 DB 기반 모바일 앱 만들기 :: 김현민 - AWS Community Day 2019AWSKRUG - AWS한국사용자모임
2.9K views72 slides
Scaling Your Team With GraphQL: Why Relationships Matter by
Scaling Your Team With GraphQL: Why Relationships MatterScaling Your Team With GraphQL: Why Relationships Matter
Scaling Your Team With GraphQL: Why Relationships MatterJoel Bowen
640 views98 slides
GraphQL research summary by
GraphQL research summaryGraphQL research summary
GraphQL research summaryObjectivity
196 views22 slides
GraphQL API Gateway and microservices by
GraphQL API Gateway and microservicesGraphQL API Gateway and microservices
GraphQL API Gateway and microservicesMohammed Shaban
207 views37 slides
Boost your APIs with GraphQL 1.0 by
Boost your APIs with GraphQL 1.0Boost your APIs with GraphQL 1.0
Boost your APIs with GraphQL 1.0Otávio Santana
682 views29 slides
Mój przepis na skalowalną architekturę mikroserwisową? Apollo Federation i Gr... by
Mój przepis na skalowalną architekturę mikroserwisową? Apollo Federation i Gr...Mój przepis na skalowalną architekturę mikroserwisową? Apollo Federation i Gr...
Mój przepis na skalowalną architekturę mikroserwisową? Apollo Federation i Gr...The Software House
123 views72 slides

More Related Content

Similar to Introduction to GraphQL in Scala

Hands On - GraphQL by
Hands On - GraphQLHands On - GraphQL
Hands On - GraphQLBreno Henrique de Lima Freitas
125 views28 slides
GraphQL_devoxx_2023.pptx by
GraphQL_devoxx_2023.pptxGraphQL_devoxx_2023.pptx
GraphQL_devoxx_2023.pptxSoham Dasgupta
137 views41 slides
How easy (or hard) it is to monitor your graph ql service performance by
How easy (or hard) it is to monitor your graph ql service performanceHow easy (or hard) it is to monitor your graph ql service performance
How easy (or hard) it is to monitor your graph ql service performanceLuca Mattia Ferrari
140 views35 slides
GraphQL and its schema as a universal layer for database access by
GraphQL and its schema as a universal layer for database accessGraphQL and its schema as a universal layer for database access
GraphQL and its schema as a universal layer for database accessConnected Data World
939 views35 slides
Tutorial: Building a GraphQL API in PHP by
Tutorial: Building a GraphQL API in PHPTutorial: Building a GraphQL API in PHP
Tutorial: Building a GraphQL API in PHPAndrew Rota
6.6K views97 slides
GraphQL-ify your APIs by
GraphQL-ify your APIsGraphQL-ify your APIs
GraphQL-ify your APIsSoham Dasgupta
95 views39 slides

Similar to Introduction to GraphQL in Scala(20)

How easy (or hard) it is to monitor your graph ql service performance by Luca Mattia Ferrari
How easy (or hard) it is to monitor your graph ql service performanceHow easy (or hard) it is to monitor your graph ql service performance
How easy (or hard) it is to monitor your graph ql service performance
GraphQL and its schema as a universal layer for database access by Connected Data World
GraphQL and its schema as a universal layer for database accessGraphQL and its schema as a universal layer for database access
GraphQL and its schema as a universal layer for database access
Tutorial: Building a GraphQL API in PHP by Andrew Rota
Tutorial: Building a GraphQL API in PHPTutorial: Building a GraphQL API in PHP
Tutorial: Building a GraphQL API in PHP
Andrew Rota6.6K views
Phase2 OpenPublish Presentation SF SemWeb Meetup, April 28, 2009 by Krista Thomas
Phase2 OpenPublish Presentation SF SemWeb Meetup, April 28, 2009Phase2 OpenPublish Presentation SF SemWeb Meetup, April 28, 2009
Phase2 OpenPublish Presentation SF SemWeb Meetup, April 28, 2009
Krista Thomas692 views
GraphQL Schema Stitching with Prisma & Contentful by Nikolas Burk
GraphQL Schema Stitching with Prisma & ContentfulGraphQL Schema Stitching with Prisma & Contentful
GraphQL Schema Stitching with Prisma & Contentful
Nikolas Burk651 views
Building Serverless Applications Using AWS AppSync and Amazon Neptune (SRV307... by Amazon Web Services
Building Serverless Applications Using AWS AppSync and Amazon Neptune (SRV307...Building Serverless Applications Using AWS AppSync and Amazon Neptune (SRV307...
Building Serverless Applications Using AWS AppSync and Amazon Neptune (SRV307...
Amazon Web Services1.6K views
Multiplaform Solution for Graph Datasources by Stratio
Multiplaform Solution for Graph DatasourcesMultiplaform Solution for Graph Datasources
Multiplaform Solution for Graph Datasources
Stratio771 views
Prisma api kick off: React-Native Seoul meetup by Tae-Seong Park
Prisma api kick off: React-Native Seoul meetupPrisma api kick off: React-Native Seoul meetup
Prisma api kick off: React-Native Seoul meetup
Tae-Seong Park245 views
The power of polyglot searching by GraphAware
The power of polyglot searchingThe power of polyglot searching
The power of polyglot searching
GraphAware116 views
API Athens Meetup - API standards 25-6-2014 by Michael Petychakis
API Athens Meetup - API standards   25-6-2014API Athens Meetup - API standards   25-6-2014
API Athens Meetup - API standards 25-6-2014
Michael Petychakis3.4K views
API Athens Meetup - API standards 25-6-2014 by openi_ict
API Athens Meetup - API standards 25-6-2014API Athens Meetup - API standards 25-6-2014
API Athens Meetup - API standards 25-6-2014
openi_ict298 views
Apache® Spark™ MLlib: From Quick Start to Scikit-Learn by Databricks
Apache® Spark™ MLlib: From Quick Start to Scikit-LearnApache® Spark™ MLlib: From Quick Start to Scikit-Learn
Apache® Spark™ MLlib: From Quick Start to Scikit-Learn
Databricks11.4K views
GraphQL over REST at Reactathon 2018 by Sashko Stubailo
GraphQL over REST at Reactathon 2018GraphQL over REST at Reactathon 2018
GraphQL over REST at Reactathon 2018
Sashko Stubailo1.4K views
Gain Insights with Graph Analytics by Jean Ihm
Gain Insights with Graph Analytics Gain Insights with Graph Analytics
Gain Insights with Graph Analytics
Jean Ihm603 views

More from scalaconfjp

脆弱性対策のためのClean Architecture ~脆弱性に対するレジリエンスを確保せよ~ by
脆弱性対策のためのClean Architecture ~脆弱性に対するレジリエンスを確保せよ~脆弱性対策のためのClean Architecture ~脆弱性に対するレジリエンスを確保せよ~
脆弱性対策のためのClean Architecture ~脆弱性に対するレジリエンスを確保せよ~scalaconfjp
112 views50 slides
Alp x BizReach SaaS事業を営む2社がお互い気になることをゆるゆる聞いてみる会 by
Alp x BizReach SaaS事業を営む2社がお互い気になることをゆるゆる聞いてみる会Alp x BizReach SaaS事業を営む2社がお互い気になることをゆるゆる聞いてみる会
Alp x BizReach SaaS事業を営む2社がお互い気になることをゆるゆる聞いてみる会scalaconfjp
72 views20 slides
GraalVM Overview Compact version by
GraalVM Overview Compact versionGraalVM Overview Compact version
GraalVM Overview Compact versionscalaconfjp
2K views70 slides
Run Scala Faster with GraalVM on any Platform / GraalVMで、どこでもScalaを高速実行しよう by... by
Run Scala Faster with GraalVM on any Platform / GraalVMで、どこでもScalaを高速実行しよう by...Run Scala Faster with GraalVM on any Platform / GraalVMで、どこでもScalaを高速実行しよう by...
Run Scala Faster with GraalVM on any Platform / GraalVMで、どこでもScalaを高速実行しよう by...scalaconfjp
842 views37 slides
Monitoring Reactive Architecture Like Never Before / 今までになかったリアクティブアーキテクチャの監視... by
Monitoring Reactive Architecture Like Never Before / 今までになかったリアクティブアーキテクチャの監視...Monitoring Reactive Architecture Like Never Before / 今までになかったリアクティブアーキテクチャの監視...
Monitoring Reactive Architecture Like Never Before / 今までになかったリアクティブアーキテクチャの監視...scalaconfjp
224 views16 slides
Scala 3, what does it means for me? / Scala 3って、私にはどんな影響があるの? by Joan Goyeau by
Scala 3, what does it means for me? / Scala 3って、私にはどんな影響があるの? by Joan GoyeauScala 3, what does it means for me? / Scala 3って、私にはどんな影響があるの? by Joan Goyeau
Scala 3, what does it means for me? / Scala 3って、私にはどんな影響があるの? by Joan Goyeauscalaconfjp
318 views79 slides

More from scalaconfjp(20)

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

Recently uploaded

Navigating container technology for enhanced security by Niklas Saari by
Navigating container technology for enhanced security by Niklas SaariNavigating container technology for enhanced security by Niklas Saari
Navigating container technology for enhanced security by Niklas SaariMetosin Oy
8 views34 slides
Cycleops - Automate deployments on top of bare metal.pptx by
Cycleops - Automate deployments on top of bare metal.pptxCycleops - Automate deployments on top of bare metal.pptx
Cycleops - Automate deployments on top of bare metal.pptxThanassis Parathyras
30 views12 slides
Headless JS UG Presentation.pptx by
Headless JS UG Presentation.pptxHeadless JS UG Presentation.pptx
Headless JS UG Presentation.pptxJack Spektor
7 views24 slides
SAP FOR CONTRACT MANUFACTURING.pdf by
SAP FOR CONTRACT MANUFACTURING.pdfSAP FOR CONTRACT MANUFACTURING.pdf
SAP FOR CONTRACT MANUFACTURING.pdfVirendra Rai, PMP
11 views2 slides
DSD-INT 2023 Simulating a falling apron in Delft3D 4 - Engineering Practice -... by
DSD-INT 2023 Simulating a falling apron in Delft3D 4 - Engineering Practice -...DSD-INT 2023 Simulating a falling apron in Delft3D 4 - Engineering Practice -...
DSD-INT 2023 Simulating a falling apron in Delft3D 4 - Engineering Practice -...Deltares
6 views15 slides
Software testing company in India.pptx by
Software testing company in India.pptxSoftware testing company in India.pptx
Software testing company in India.pptxSakshiPatel82
7 views9 slides

Recently uploaded(20)

Navigating container technology for enhanced security by Niklas Saari by Metosin Oy
Navigating container technology for enhanced security by Niklas SaariNavigating container technology for enhanced security by Niklas Saari
Navigating container technology for enhanced security by Niklas Saari
Metosin Oy8 views
Cycleops - Automate deployments on top of bare metal.pptx by Thanassis Parathyras
Cycleops - Automate deployments on top of bare metal.pptxCycleops - Automate deployments on top of bare metal.pptx
Cycleops - Automate deployments on top of bare metal.pptx
Headless JS UG Presentation.pptx by Jack Spektor
Headless JS UG Presentation.pptxHeadless JS UG Presentation.pptx
Headless JS UG Presentation.pptx
Jack Spektor7 views
DSD-INT 2023 Simulating a falling apron in Delft3D 4 - Engineering Practice -... by Deltares
DSD-INT 2023 Simulating a falling apron in Delft3D 4 - Engineering Practice -...DSD-INT 2023 Simulating a falling apron in Delft3D 4 - Engineering Practice -...
DSD-INT 2023 Simulating a falling apron in Delft3D 4 - Engineering Practice -...
Deltares6 views
Software testing company in India.pptx by SakshiPatel82
Software testing company in India.pptxSoftware testing company in India.pptx
Software testing company in India.pptx
SakshiPatel827 views
MariaDB stored procedures and why they should be improved by Federico Razzoli
MariaDB stored procedures and why they should be improvedMariaDB stored procedures and why they should be improved
MariaDB stored procedures and why they should be improved
Software evolution understanding: Automatic extraction of software identifier... by Ra'Fat Al-Msie'deen
Software evolution understanding: Automatic extraction of software identifier...Software evolution understanding: Automatic extraction of software identifier...
Software evolution understanding: Automatic extraction of software identifier...
What Can Employee Monitoring Software Do?​ by wAnywhere
What Can Employee Monitoring Software Do?​What Can Employee Monitoring Software Do?​
What Can Employee Monitoring Software Do?​
wAnywhere21 views
Elevate your SAP landscape's efficiency and performance with HCL Workload Aut... by HCLSoftware
Elevate your SAP landscape's efficiency and performance with HCL Workload Aut...Elevate your SAP landscape's efficiency and performance with HCL Workload Aut...
Elevate your SAP landscape's efficiency and performance with HCL Workload Aut...
HCLSoftware6 views
360 graden fabriek by info33492
360 graden fabriek360 graden fabriek
360 graden fabriek
info3349224 views
El Arte de lo Possible by Neo4j
El Arte de lo PossibleEl Arte de lo Possible
El Arte de lo Possible
Neo4j38 views
Tridens DevOps by Tridens
Tridens DevOpsTridens DevOps
Tridens DevOps
Tridens9 views
DSD-INT 2023 Leveraging the results of a 3D hydrodynamic model to improve the... by Deltares
DSD-INT 2023 Leveraging the results of a 3D hydrodynamic model to improve the...DSD-INT 2023 Leveraging the results of a 3D hydrodynamic model to improve the...
DSD-INT 2023 Leveraging the results of a 3D hydrodynamic model to improve the...
Deltares6 views
DSD-INT 2023 Delft3D FM Suite 2024.01 2D3D - New features + Improvements - Ge... by Deltares
DSD-INT 2023 Delft3D FM Suite 2024.01 2D3D - New features + Improvements - Ge...DSD-INT 2023 Delft3D FM Suite 2024.01 2D3D - New features + Improvements - Ge...
DSD-INT 2023 Delft3D FM Suite 2024.01 2D3D - New features + Improvements - Ge...
Deltares16 views
DSD-INT 2023 Thermobaricity in 3D DCSM-FM - taking pressure into account in t... by Deltares
DSD-INT 2023 Thermobaricity in 3D DCSM-FM - taking pressure into account in t...DSD-INT 2023 Thermobaricity in 3D DCSM-FM - taking pressure into account in t...
DSD-INT 2023 Thermobaricity in 3D DCSM-FM - taking pressure into account in t...
Deltares9 views
DSD-INT 2023 - Delft3D User Days - Welcome - Day 3 - Afternoon by Deltares
DSD-INT 2023 - Delft3D User Days - Welcome - Day 3 - AfternoonDSD-INT 2023 - Delft3D User Days - Welcome - Day 3 - Afternoon
DSD-INT 2023 - Delft3D User Days - Welcome - Day 3 - Afternoon
Deltares13 views
Copilot Prompting Toolkit_All Resources.pdf by Riccardo Zamana
Copilot Prompting Toolkit_All Resources.pdfCopilot Prompting Toolkit_All Resources.pdf
Copilot Prompting Toolkit_All Resources.pdf
Riccardo Zamana6 views

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 :)