SlideShare a Scribd company logo
1 of 29
Download to read offline
GraphQL with Spring Boot
18.11.2017
Krzysztof Pawłowski
krzysztof.pawlowski@merapar.com | krzychpawlowski
About me
• Senior Java Developer @ Merapar Technologies
• Coder, Lecturer (PJATK), Java Trainer (iSA)
• 7+ years of experience in Java Development
• using GraphQL for a year now
• E-mail: krzysztof.pawlowski@merapar.com
• Twitter: krzychpawlowski
REST not so restful?
GET /author/:id
<<class>>

Author
Long id
String name
String email
String bio
List<BlogEntry>

blogEntries
<<class>>

BlogEntry
Long id
String title
List<Comment> comments
<<class>>

Comment
Long id
String author
String comment
REST not so restful?
GET /author/:id
<<class>>

Author
Long id
String name
String email
String bio
List<BlogEntry>

blogEntries
<<class>>

BlogEntry
Long id
String title
List<Comment> comments
<<class>>

Comment
Long id
String author
String comment
{

id: 1,

name: “Krzysztof”,

email:”k@example.com“,

bio: “java dev”,
blogEntriesIds: [1, 2]

}
REST not so restful?
GET /author/:id
GET /author/:id/blogEntry/:id
<<class>>

Author
Long id
String name
String email
String bio
List<BlogEntry>

blogEntries
<<class>>

BlogEntry
Long id
String title
List<Comment> comments
<<class>>

Comment
Long id
String author
String comment
REST not so restful?
GET /author/:id
GET /author/:id/blogEntry/:id
<<class>>

Author
Long id
String name
String email
String bio
List<BlogEntry>

blogEntries
<<class>>

BlogEntry
Long id
String title
List<Comment> comments
<<class>>

Comment
Long id
String author
String comment
{

id: 1,
title: “GraphQL”,

authorId: 1,
commentsIds: [1, 2]

}
REST not so restful?
GET /author/:id/blogEntry/:id/comments
GET /author/:id
GET /author/:id/blogEntry/:id
<<class>>

Author
Long id
String name
String email
String bio
List<BlogEntry>

blogEntries
<<class>>

BlogEntry
Long id
String title
List<Comment> comments
<<class>>

Comment
Long id
String author
String comment
REST not so restful?
GET /author/:id/blogEntry/:id/comments
GET /author/:id
GET /author/:id/blogEntry/:id
<<class>>

Author
Long id
String name
String email
String bio
List<BlogEntry>

blogEntries
<<class>>

BlogEntry
Long id
String title
List<Comment> comments
<<class>>

Comment
Long id
String author
String comment
{

id: 1,

author: “anonymous”,

comment: “super!”

}
While in GraphQL…
authors(filter : {id : 1 }) {

name

blogEntry {

title

comment {

comment

}

}

}
<<class>>

Author
Long id
String name
String email
String bio
List<BlogEntry>

blogEntries
<<class>>

BlogEntry
Long id
String title
List<Comment> comments
<<class>>

Comment
Long id
String author
String comment
What is GraphQL?
“GraphQL is a query language for APIs and a runtime for fulfilling those
queries with your existing data.”
— http://graphql.org
What is GraphQL?
“GraphQL is a query language for APIs and a runtime for fulfilling those
queries with your existing data.”
— http://graphql.org
Declarative

Ask for what you need,
get exactly that
What is GraphQL?
“GraphQL is a query language for APIs and a runtime for fulfilling those
queries with your existing data.”
— http://graphql.org
Declarative

Ask for what you need,
get exactly that
Compositional

Get many resources
in a single request
What is GraphQL?
“GraphQL is a query language for APIs and a runtime for fulfilling those
queries with your existing data.”
— http://graphql.org
Declarative

Ask for what you need,
get exactly that
Compositional

Get many resources
in a single request
Strongly Typed

Describe what’s
possible
with a type system
GraphQL query
authors {
# queries can have comments!
name
email
blogEntries {
title
}
}
GraphQL query
authors {
# queries can have comments!
name
email
blogEntries {
title
}
}
{
"data": {
"authors": [
{
"name": "author 1",
"email": "Python dev",
"blogEntries": [
{
"title": "blog entry 1"
},
{
"title": "blog entry 3"
}
]
},
{
"name": "author 2",
"email": "Java dev",
"blogEntries": [
{
"title": "blog entry 2"
},
{
"title": "blog entry 4"
}
]
}
]
}
GraphQL query - filter
authors(filter : {id : 1 }) {
name
email
blogEntries {
title
}
}
GraphQL query - filter
authors(filter : {id : 1 }) {
name
email
blogEntries {
title
}
}
{
"data": {
"authors": [
{
"name": "author 1",
"email": "Python dev",
"blogEntries": [
{
"title": "blog entry 1"
},
{
"title": "blog entry 3"
}
]
}
]
}
}
GraphQL mutation
mutation addAuthorMutation($authorInfo: addAuthorInput!) {
addAuthor(input : $authorInfo) {
id
name
bio
email
}
}
{
"authorInfo": {
"id": 1,
“name" : "Krzysztof Pawlowski",
"bio" : "java dev",
"email" : "krzysztof.pawlowski@merapar.com"
}
GraphQL mutation
mutation addAuthorMutation($authorInfo: addAuthorInput!) {
addAuthor(input : $authorInfo) {
id
name
bio
email
}
}
{
"authorInfo": {
"id": 1,
“name" : "Krzysztof Pawlowski",
"bio" : "java dev",
"email" : "krzysztof.pawlowski@merapar.com"
}
{
"data": {
"addAuthor": {
"id": 1,
"name": "Krzysztof Pawlowski",
"bio": "java dev",
"email": 

“krzysztof.pawlowski@merapar.com"
}
}
}
GraphQL schema
type Author {

id: Long!
name: String
bio: String
email: String

blogEntries: [BlogEntry]
}



type BlogEntry {
id: Long!
title: String!
comments: [Comment]
}
type Comment {
id: Long!
author: String
comment: String
}

GraphQL schema
type Author {

id: Long!
name: String
bio: String
email: String

blogEntries: [BlogEntry]
}



type BlogEntry {
id: Long!
title: String!
comments: [Comment]
}
type Comment {
id: Long!
author: String
comment: String
}

type Query {
authors(id: Long!): Author
blogEntries(id: Long!): BlogEntry
comments(id: Long!): Comment
}
type Mutation {
addAuthor(author: Author!): Author
updateAuthor(author: Author!): Author
deleteAuthor(author: Author!): Author
…
}
GraphQL schema
type Author {

id: Long!
name: String
bio: String
email: String

blogEntries: [BlogEntry]
}



type BlogEntry {
id: Long!
title: String!
comments: [Comment]
}
type Comment {
id: Long!
author: String
comment: String
}

type Query {
authors(id: Long!): Author
blogEntries(id: Long!): BlogEntry
comments(id: Long!): Comment
}
type Mutation {
addAuthor(author: Author!): Author
updateAuthor(author: Author!): Author
deleteAuthor(author: Author!): Author
…
}
schema {
query: Query
mutation: Mutation
}
Other benefits of GraphQL
‣flexibility
‣one end-point
‣self-documenting (strong typing and schema)
‣query validation
‣no versioning needed
Client and documentation
Spring Boot Starter for GraphQL
‣adding Maven dependency creates GraphQL controller under

/v1/graphql
<dependency>
<groupId>com.merapar</groupId>
<artifactId>graphql-spring-boot-starter</artifactId>
<version>1.0.2</version>
</dependency>
‣adding new queries and mutation is a matter of implementing
GraphQlFields interface
Demo
https://github.com/krzysztof-pawlowski/GraphQLwithSpringBoot
Problems with GraphQL
‣HTTP caching
‣Unpredictable execution
‣No handling for file upload
‣Authorisation and authentication
Thank you!
Questions?
krzysztof.pawlowski@merapar.com | krzychpawlowski
Bonus — GitHub GraphQL API
https://developer.github.com/v4/

More Related Content

What's hot

Austin Day of Rest - Introduction
Austin Day of Rest - IntroductionAustin Day of Rest - Introduction
Austin Day of Rest - IntroductionHandsOnWP.com
 
Cool bonsai cool - an introduction to ElasticSearch
Cool bonsai cool - an introduction to ElasticSearchCool bonsai cool - an introduction to ElasticSearch
Cool bonsai cool - an introduction to ElasticSearchclintongormley
 
Building Beautiful REST APIs in ASP.NET Core
Building Beautiful REST APIs in ASP.NET CoreBuilding Beautiful REST APIs in ASP.NET Core
Building Beautiful REST APIs in ASP.NET CoreNate Barbettini
 
Beautiful REST+JSON APIs with Ion
Beautiful REST+JSON APIs with IonBeautiful REST+JSON APIs with Ion
Beautiful REST+JSON APIs with IonStormpath
 
Building Beautiful REST APIs in ASP.NET Core
Building Beautiful REST APIs in ASP.NET CoreBuilding Beautiful REST APIs in ASP.NET Core
Building Beautiful REST APIs in ASP.NET CoreStormpath
 
The ultimate guide for Elasticsearch plugins
The ultimate guide for Elasticsearch pluginsThe ultimate guide for Elasticsearch plugins
The ultimate guide for Elasticsearch pluginsItamar
 
Practical Elasticsearch - real world use cases
Practical Elasticsearch - real world use casesPractical Elasticsearch - real world use cases
Practical Elasticsearch - real world use casesItamar
 
Webinar: Modern Techniques for Better Search Relevance with Fusion
Webinar: Modern Techniques for Better Search Relevance with FusionWebinar: Modern Techniques for Better Search Relevance with Fusion
Webinar: Modern Techniques for Better Search Relevance with FusionLucidworks
 
State-of-the-Art Drupal Search with Apache Solr
State-of-the-Art Drupal Search with Apache SolrState-of-the-Art Drupal Search with Apache Solr
State-of-the-Art Drupal Search with Apache Solrguest432cd6
 
Pragmatic REST APIs
Pragmatic REST APIsPragmatic REST APIs
Pragmatic REST APIsamesar0
 
Cloud Security Monitoring and Spark Analytics
Cloud Security Monitoring and Spark AnalyticsCloud Security Monitoring and Spark Analytics
Cloud Security Monitoring and Spark Analyticsamesar0
 
Episode 8 - Path To Code - Integrate Salesforce with external system using R...
Episode 8  - Path To Code - Integrate Salesforce with external system using R...Episode 8  - Path To Code - Integrate Salesforce with external system using R...
Episode 8 - Path To Code - Integrate Salesforce with external system using R...Jitendra Zaa
 
Server Logs: After Excel Fails
Server Logs: After Excel FailsServer Logs: After Excel Fails
Server Logs: After Excel FailsOliver Mason
 
Apache Solr/Lucene Internals by Anatoliy Sokolenko
Apache Solr/Lucene Internals  by Anatoliy SokolenkoApache Solr/Lucene Internals  by Anatoliy Sokolenko
Apache Solr/Lucene Internals by Anatoliy SokolenkoProvectus
 
How to automate all your SEO projects
How to automate all your SEO projectsHow to automate all your SEO projects
How to automate all your SEO projectsVincent Terrasi
 
Log File Analysis: The most powerful tool in your SEO toolkit
Log File Analysis: The most powerful tool in your SEO toolkitLog File Analysis: The most powerful tool in your SEO toolkit
Log File Analysis: The most powerful tool in your SEO toolkitTom Bennet
 
Pragmatic REST: recent trends in API design
Pragmatic REST: recent trends in API designPragmatic REST: recent trends in API design
Pragmatic REST: recent trends in API designMarsh Gardiner
 
使用 Elasticsearch 及 Kibana 進行巨量資料搜尋及視覺化-曾書庭
使用 Elasticsearch 及 Kibana 進行巨量資料搜尋及視覺化-曾書庭使用 Elasticsearch 及 Kibana 進行巨量資料搜尋及視覺化-曾書庭
使用 Elasticsearch 及 Kibana 進行巨量資料搜尋及視覺化-曾書庭台灣資料科學年會
 
Building a Real-time Solr-powered Recommendation Engine
Building a Real-time Solr-powered Recommendation EngineBuilding a Real-time Solr-powered Recommendation Engine
Building a Real-time Solr-powered Recommendation Enginelucenerevolution
 

What's hot (20)

React & GraphQL
React & GraphQLReact & GraphQL
React & GraphQL
 
Austin Day of Rest - Introduction
Austin Day of Rest - IntroductionAustin Day of Rest - Introduction
Austin Day of Rest - Introduction
 
Cool bonsai cool - an introduction to ElasticSearch
Cool bonsai cool - an introduction to ElasticSearchCool bonsai cool - an introduction to ElasticSearch
Cool bonsai cool - an introduction to ElasticSearch
 
Building Beautiful REST APIs in ASP.NET Core
Building Beautiful REST APIs in ASP.NET CoreBuilding Beautiful REST APIs in ASP.NET Core
Building Beautiful REST APIs in ASP.NET Core
 
Beautiful REST+JSON APIs with Ion
Beautiful REST+JSON APIs with IonBeautiful REST+JSON APIs with Ion
Beautiful REST+JSON APIs with Ion
 
Building Beautiful REST APIs in ASP.NET Core
Building Beautiful REST APIs in ASP.NET CoreBuilding Beautiful REST APIs in ASP.NET Core
Building Beautiful REST APIs in ASP.NET Core
 
The ultimate guide for Elasticsearch plugins
The ultimate guide for Elasticsearch pluginsThe ultimate guide for Elasticsearch plugins
The ultimate guide for Elasticsearch plugins
 
Practical Elasticsearch - real world use cases
Practical Elasticsearch - real world use casesPractical Elasticsearch - real world use cases
Practical Elasticsearch - real world use cases
 
Webinar: Modern Techniques for Better Search Relevance with Fusion
Webinar: Modern Techniques for Better Search Relevance with FusionWebinar: Modern Techniques for Better Search Relevance with Fusion
Webinar: Modern Techniques for Better Search Relevance with Fusion
 
State-of-the-Art Drupal Search with Apache Solr
State-of-the-Art Drupal Search with Apache SolrState-of-the-Art Drupal Search with Apache Solr
State-of-the-Art Drupal Search with Apache Solr
 
Pragmatic REST APIs
Pragmatic REST APIsPragmatic REST APIs
Pragmatic REST APIs
 
Cloud Security Monitoring and Spark Analytics
Cloud Security Monitoring and Spark AnalyticsCloud Security Monitoring and Spark Analytics
Cloud Security Monitoring and Spark Analytics
 
Episode 8 - Path To Code - Integrate Salesforce with external system using R...
Episode 8  - Path To Code - Integrate Salesforce with external system using R...Episode 8  - Path To Code - Integrate Salesforce with external system using R...
Episode 8 - Path To Code - Integrate Salesforce with external system using R...
 
Server Logs: After Excel Fails
Server Logs: After Excel FailsServer Logs: After Excel Fails
Server Logs: After Excel Fails
 
Apache Solr/Lucene Internals by Anatoliy Sokolenko
Apache Solr/Lucene Internals  by Anatoliy SokolenkoApache Solr/Lucene Internals  by Anatoliy Sokolenko
Apache Solr/Lucene Internals by Anatoliy Sokolenko
 
How to automate all your SEO projects
How to automate all your SEO projectsHow to automate all your SEO projects
How to automate all your SEO projects
 
Log File Analysis: The most powerful tool in your SEO toolkit
Log File Analysis: The most powerful tool in your SEO toolkitLog File Analysis: The most powerful tool in your SEO toolkit
Log File Analysis: The most powerful tool in your SEO toolkit
 
Pragmatic REST: recent trends in API design
Pragmatic REST: recent trends in API designPragmatic REST: recent trends in API design
Pragmatic REST: recent trends in API design
 
使用 Elasticsearch 及 Kibana 進行巨量資料搜尋及視覺化-曾書庭
使用 Elasticsearch 及 Kibana 進行巨量資料搜尋及視覺化-曾書庭使用 Elasticsearch 及 Kibana 進行巨量資料搜尋及視覺化-曾書庭
使用 Elasticsearch 及 Kibana 進行巨量資料搜尋及視覺化-曾書庭
 
Building a Real-time Solr-powered Recommendation Engine
Building a Real-time Solr-powered Recommendation EngineBuilding a Real-time Solr-powered Recommendation Engine
Building a Real-time Solr-powered Recommendation Engine
 

Similar to GraphQL with Spring Boot

Better APIs with GraphQL
Better APIs with GraphQL Better APIs with GraphQL
Better APIs with GraphQL Josh Price
 
Overview of GraphQL & Clients
Overview of GraphQL & ClientsOverview of GraphQL & Clients
Overview of GraphQL & ClientsPokai Chang
 
APIdays Paris 2018 - Building scalable, type-safe GraphQL servers from scratc...
APIdays Paris 2018 - Building scalable, type-safe GraphQL servers from scratc...APIdays Paris 2018 - Building scalable, type-safe GraphQL servers from scratc...
APIdays Paris 2018 - Building scalable, type-safe GraphQL servers from scratc...apidays
 
MongoDB.local Berlin: Building a GraphQL API with MongoDB, Prisma and Typescript
MongoDB.local Berlin: Building a GraphQL API with MongoDB, Prisma and TypescriptMongoDB.local Berlin: Building a GraphQL API with MongoDB, Prisma and Typescript
MongoDB.local Berlin: Building a GraphQL API with MongoDB, Prisma and TypescriptMongoDB
 
Introduction to Graph QL
Introduction to Graph QLIntroduction to Graph QL
Introduction to Graph QLDeepak More
 
Into to GraphQL
Into to GraphQLInto to GraphQL
Into to GraphQLshobot
 
Cascalog at May Bay Area Hadoop User Group
Cascalog at May Bay Area Hadoop User GroupCascalog at May Bay Area Hadoop User Group
Cascalog at May Bay Area Hadoop User Groupnathanmarz
 
Elasticsearch & "PeopleSearch"
Elasticsearch & "PeopleSearch"Elasticsearch & "PeopleSearch"
Elasticsearch & "PeopleSearch"George Stathis
 
GraphQL in an Age of REST
GraphQL in an Age of RESTGraphQL in an Age of REST
GraphQL in an Age of RESTYos Riady
 
REST API に疲れたあなたへ贈る GraphQL 入門
REST API に疲れたあなたへ贈る GraphQL 入門REST API に疲れたあなたへ贈る GraphQL 入門
REST API に疲れたあなたへ贈る GraphQL 入門Keisuke Tsukagoshi
 
Next-generation API Development with GraphQL and Prisma
Next-generation API Development with GraphQL and PrismaNext-generation API Development with GraphQL and Prisma
Next-generation API Development with GraphQL and PrismaNikolas Burk
 
What/How to do with GraphQL? - Valentyn Ostakh (ENG) | Ruby Meditation 27
What/How to do with GraphQL? - Valentyn Ostakh (ENG) | Ruby Meditation 27What/How to do with GraphQL? - Valentyn Ostakh (ENG) | Ruby Meditation 27
What/How to do with GraphQL? - Valentyn Ostakh (ENG) | Ruby Meditation 27Ruby Meditation
 
GraphQL and its schema as a universal layer for database access
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
 
GraphQL Los Angeles Meetup Slides
GraphQL Los Angeles Meetup SlidesGraphQL Los Angeles Meetup Slides
GraphQL Los Angeles Meetup SlidesGrant Miller
 
JavaScript Workshop
JavaScript WorkshopJavaScript Workshop
JavaScript WorkshopPamela Fox
 

Similar to GraphQL with Spring Boot (20)

Better APIs with GraphQL
Better APIs with GraphQL Better APIs with GraphQL
Better APIs with GraphQL
 
Overview of GraphQL & Clients
Overview of GraphQL & ClientsOverview of GraphQL & Clients
Overview of GraphQL & Clients
 
APIdays Paris 2018 - Building scalable, type-safe GraphQL servers from scratc...
APIdays Paris 2018 - Building scalable, type-safe GraphQL servers from scratc...APIdays Paris 2018 - Building scalable, type-safe GraphQL servers from scratc...
APIdays Paris 2018 - Building scalable, type-safe GraphQL servers from scratc...
 
MongoDB.local Berlin: Building a GraphQL API with MongoDB, Prisma and Typescript
MongoDB.local Berlin: Building a GraphQL API with MongoDB, Prisma and TypescriptMongoDB.local Berlin: Building a GraphQL API with MongoDB, Prisma and Typescript
MongoDB.local Berlin: Building a GraphQL API with MongoDB, Prisma and Typescript
 
Introduction to Graph QL
Introduction to Graph QLIntroduction to Graph QL
Introduction to Graph QL
 
Graphql usage
Graphql usageGraphql usage
Graphql usage
 
Into to GraphQL
Into to GraphQLInto to GraphQL
Into to GraphQL
 
Cascalog at May Bay Area Hadoop User Group
Cascalog at May Bay Area Hadoop User GroupCascalog at May Bay Area Hadoop User Group
Cascalog at May Bay Area Hadoop User Group
 
Elasticsearch & "PeopleSearch"
Elasticsearch & "PeopleSearch"Elasticsearch & "PeopleSearch"
Elasticsearch & "PeopleSearch"
 
GraphQL in an Age of REST
GraphQL in an Age of RESTGraphQL in an Age of REST
GraphQL in an Age of REST
 
REST API に疲れたあなたへ贈る GraphQL 入門
REST API に疲れたあなたへ贈る GraphQL 入門REST API に疲れたあなたへ贈る GraphQL 入門
REST API に疲れたあなたへ贈る GraphQL 入門
 
Hands On - GraphQL
Hands On - GraphQLHands On - GraphQL
Hands On - GraphQL
 
SamBO
SamBOSamBO
SamBO
 
Next-generation API Development with GraphQL and Prisma
Next-generation API Development with GraphQL and PrismaNext-generation API Development with GraphQL and Prisma
Next-generation API Development with GraphQL and Prisma
 
What/How to do with GraphQL? - Valentyn Ostakh (ENG) | Ruby Meditation 27
What/How to do with GraphQL? - Valentyn Ostakh (ENG) | Ruby Meditation 27What/How to do with GraphQL? - Valentyn Ostakh (ENG) | Ruby Meditation 27
What/How to do with GraphQL? - Valentyn Ostakh (ENG) | Ruby Meditation 27
 
kRouter
kRouterkRouter
kRouter
 
GraphQL and its schema as a universal layer for database access
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
 
GraphQL Los Angeles Meetup Slides
GraphQL Los Angeles Meetup SlidesGraphQL Los Angeles Meetup Slides
GraphQL Los Angeles Meetup Slides
 
SamKK
SamKKSamKK
SamKK
 
JavaScript Workshop
JavaScript WorkshopJavaScript Workshop
JavaScript Workshop
 

Recently uploaded

Bun (KitWorks Team Study 노별마루 발표 2024.4.22)
Bun (KitWorks Team Study 노별마루 발표 2024.4.22)Bun (KitWorks Team Study 노별마루 발표 2024.4.22)
Bun (KitWorks Team Study 노별마루 발표 2024.4.22)Wonjun Hwang
 
DevEX - reference for building teams, processes, and platforms
DevEX - reference for building teams, processes, and platformsDevEX - reference for building teams, processes, and platforms
DevEX - reference for building teams, processes, and platformsSergiu Bodiu
 
Vector Databases 101 - An introduction to the world of Vector Databases
Vector Databases 101 - An introduction to the world of Vector DatabasesVector Databases 101 - An introduction to the world of Vector Databases
Vector Databases 101 - An introduction to the world of Vector DatabasesZilliz
 
Human Factors of XR: Using Human Factors to Design XR Systems
Human Factors of XR: Using Human Factors to Design XR SystemsHuman Factors of XR: Using Human Factors to Design XR Systems
Human Factors of XR: Using Human Factors to Design XR SystemsMark Billinghurst
 
Install Stable Diffusion in windows machine
Install Stable Diffusion in windows machineInstall Stable Diffusion in windows machine
Install Stable Diffusion in windows machinePadma Pradeep
 
Gen AI in Business - Global Trends Report 2024.pdf
Gen AI in Business - Global Trends Report 2024.pdfGen AI in Business - Global Trends Report 2024.pdf
Gen AI in Business - Global Trends Report 2024.pdfAddepto
 
SIP trunking in Janus @ Kamailio World 2024
SIP trunking in Janus @ Kamailio World 2024SIP trunking in Janus @ Kamailio World 2024
SIP trunking in Janus @ Kamailio World 2024Lorenzo Miniero
 
What's New in Teams Calling, Meetings and Devices March 2024
What's New in Teams Calling, Meetings and Devices March 2024What's New in Teams Calling, Meetings and Devices March 2024
What's New in Teams Calling, Meetings and Devices March 2024Stephanie Beckett
 
Dev Dives: Streamline document processing with UiPath Studio Web
Dev Dives: Streamline document processing with UiPath Studio WebDev Dives: Streamline document processing with UiPath Studio Web
Dev Dives: Streamline document processing with UiPath Studio WebUiPathCommunity
 
Anypoint Exchange: It’s Not Just a Repo!
Anypoint Exchange: It’s Not Just a Repo!Anypoint Exchange: It’s Not Just a Repo!
Anypoint Exchange: It’s Not Just a Repo!Manik S Magar
 
Artificial intelligence in cctv survelliance.pptx
Artificial intelligence in cctv survelliance.pptxArtificial intelligence in cctv survelliance.pptx
Artificial intelligence in cctv survelliance.pptxhariprasad279825
 
SAP Build Work Zone - Overview L2-L3.pptx
SAP Build Work Zone - Overview L2-L3.pptxSAP Build Work Zone - Overview L2-L3.pptx
SAP Build Work Zone - Overview L2-L3.pptxNavinnSomaal
 
CloudStudio User manual (basic edition):
CloudStudio User manual (basic edition):CloudStudio User manual (basic edition):
CloudStudio User manual (basic edition):comworks
 
Developer Data Modeling Mistakes: From Postgres to NoSQL
Developer Data Modeling Mistakes: From Postgres to NoSQLDeveloper Data Modeling Mistakes: From Postgres to NoSQL
Developer Data Modeling Mistakes: From Postgres to NoSQLScyllaDB
 
Commit 2024 - Secret Management made easy
Commit 2024 - Secret Management made easyCommit 2024 - Secret Management made easy
Commit 2024 - Secret Management made easyAlfredo García Lavilla
 
"ML in Production",Oleksandr Bagan
"ML in Production",Oleksandr Bagan"ML in Production",Oleksandr Bagan
"ML in Production",Oleksandr BaganFwdays
 
Scanning the Internet for External Cloud Exposures via SSL Certs
Scanning the Internet for External Cloud Exposures via SSL CertsScanning the Internet for External Cloud Exposures via SSL Certs
Scanning the Internet for External Cloud Exposures via SSL CertsRizwan Syed
 
Beyond Boundaries: Leveraging No-Code Solutions for Industry Innovation
Beyond Boundaries: Leveraging No-Code Solutions for Industry InnovationBeyond Boundaries: Leveraging No-Code Solutions for Industry Innovation
Beyond Boundaries: Leveraging No-Code Solutions for Industry InnovationSafe Software
 
Story boards and shot lists for my a level piece
Story boards and shot lists for my a level pieceStory boards and shot lists for my a level piece
Story boards and shot lists for my a level piececharlottematthew16
 
"Debugging python applications inside k8s environment", Andrii Soldatenko
"Debugging python applications inside k8s environment", Andrii Soldatenko"Debugging python applications inside k8s environment", Andrii Soldatenko
"Debugging python applications inside k8s environment", Andrii SoldatenkoFwdays
 

Recently uploaded (20)

Bun (KitWorks Team Study 노별마루 발표 2024.4.22)
Bun (KitWorks Team Study 노별마루 발표 2024.4.22)Bun (KitWorks Team Study 노별마루 발표 2024.4.22)
Bun (KitWorks Team Study 노별마루 발표 2024.4.22)
 
DevEX - reference for building teams, processes, and platforms
DevEX - reference for building teams, processes, and platformsDevEX - reference for building teams, processes, and platforms
DevEX - reference for building teams, processes, and platforms
 
Vector Databases 101 - An introduction to the world of Vector Databases
Vector Databases 101 - An introduction to the world of Vector DatabasesVector Databases 101 - An introduction to the world of Vector Databases
Vector Databases 101 - An introduction to the world of Vector Databases
 
Human Factors of XR: Using Human Factors to Design XR Systems
Human Factors of XR: Using Human Factors to Design XR SystemsHuman Factors of XR: Using Human Factors to Design XR Systems
Human Factors of XR: Using Human Factors to Design XR Systems
 
Install Stable Diffusion in windows machine
Install Stable Diffusion in windows machineInstall Stable Diffusion in windows machine
Install Stable Diffusion in windows machine
 
Gen AI in Business - Global Trends Report 2024.pdf
Gen AI in Business - Global Trends Report 2024.pdfGen AI in Business - Global Trends Report 2024.pdf
Gen AI in Business - Global Trends Report 2024.pdf
 
SIP trunking in Janus @ Kamailio World 2024
SIP trunking in Janus @ Kamailio World 2024SIP trunking in Janus @ Kamailio World 2024
SIP trunking in Janus @ Kamailio World 2024
 
What's New in Teams Calling, Meetings and Devices March 2024
What's New in Teams Calling, Meetings and Devices March 2024What's New in Teams Calling, Meetings and Devices March 2024
What's New in Teams Calling, Meetings and Devices March 2024
 
Dev Dives: Streamline document processing with UiPath Studio Web
Dev Dives: Streamline document processing with UiPath Studio WebDev Dives: Streamline document processing with UiPath Studio Web
Dev Dives: Streamline document processing with UiPath Studio Web
 
Anypoint Exchange: It’s Not Just a Repo!
Anypoint Exchange: It’s Not Just a Repo!Anypoint Exchange: It’s Not Just a Repo!
Anypoint Exchange: It’s Not Just a Repo!
 
Artificial intelligence in cctv survelliance.pptx
Artificial intelligence in cctv survelliance.pptxArtificial intelligence in cctv survelliance.pptx
Artificial intelligence in cctv survelliance.pptx
 
SAP Build Work Zone - Overview L2-L3.pptx
SAP Build Work Zone - Overview L2-L3.pptxSAP Build Work Zone - Overview L2-L3.pptx
SAP Build Work Zone - Overview L2-L3.pptx
 
CloudStudio User manual (basic edition):
CloudStudio User manual (basic edition):CloudStudio User manual (basic edition):
CloudStudio User manual (basic edition):
 
Developer Data Modeling Mistakes: From Postgres to NoSQL
Developer Data Modeling Mistakes: From Postgres to NoSQLDeveloper Data Modeling Mistakes: From Postgres to NoSQL
Developer Data Modeling Mistakes: From Postgres to NoSQL
 
Commit 2024 - Secret Management made easy
Commit 2024 - Secret Management made easyCommit 2024 - Secret Management made easy
Commit 2024 - Secret Management made easy
 
"ML in Production",Oleksandr Bagan
"ML in Production",Oleksandr Bagan"ML in Production",Oleksandr Bagan
"ML in Production",Oleksandr Bagan
 
Scanning the Internet for External Cloud Exposures via SSL Certs
Scanning the Internet for External Cloud Exposures via SSL CertsScanning the Internet for External Cloud Exposures via SSL Certs
Scanning the Internet for External Cloud Exposures via SSL Certs
 
Beyond Boundaries: Leveraging No-Code Solutions for Industry Innovation
Beyond Boundaries: Leveraging No-Code Solutions for Industry InnovationBeyond Boundaries: Leveraging No-Code Solutions for Industry Innovation
Beyond Boundaries: Leveraging No-Code Solutions for Industry Innovation
 
Story boards and shot lists for my a level piece
Story boards and shot lists for my a level pieceStory boards and shot lists for my a level piece
Story boards and shot lists for my a level piece
 
"Debugging python applications inside k8s environment", Andrii Soldatenko
"Debugging python applications inside k8s environment", Andrii Soldatenko"Debugging python applications inside k8s environment", Andrii Soldatenko
"Debugging python applications inside k8s environment", Andrii Soldatenko
 

GraphQL with Spring Boot

  • 1. GraphQL with Spring Boot 18.11.2017 Krzysztof Pawłowski krzysztof.pawlowski@merapar.com | krzychpawlowski
  • 2. About me • Senior Java Developer @ Merapar Technologies • Coder, Lecturer (PJATK), Java Trainer (iSA) • 7+ years of experience in Java Development • using GraphQL for a year now • E-mail: krzysztof.pawlowski@merapar.com • Twitter: krzychpawlowski
  • 3. REST not so restful? GET /author/:id <<class>>
 Author Long id String name String email String bio List<BlogEntry>
 blogEntries <<class>>
 BlogEntry Long id String title List<Comment> comments <<class>>
 Comment Long id String author String comment
  • 4. REST not so restful? GET /author/:id <<class>>
 Author Long id String name String email String bio List<BlogEntry>
 blogEntries <<class>>
 BlogEntry Long id String title List<Comment> comments <<class>>
 Comment Long id String author String comment {
 id: 1,
 name: “Krzysztof”,
 email:”k@example.com“,
 bio: “java dev”, blogEntriesIds: [1, 2]
 }
  • 5. REST not so restful? GET /author/:id GET /author/:id/blogEntry/:id <<class>>
 Author Long id String name String email String bio List<BlogEntry>
 blogEntries <<class>>
 BlogEntry Long id String title List<Comment> comments <<class>>
 Comment Long id String author String comment
  • 6. REST not so restful? GET /author/:id GET /author/:id/blogEntry/:id <<class>>
 Author Long id String name String email String bio List<BlogEntry>
 blogEntries <<class>>
 BlogEntry Long id String title List<Comment> comments <<class>>
 Comment Long id String author String comment {
 id: 1, title: “GraphQL”,
 authorId: 1, commentsIds: [1, 2]
 }
  • 7. REST not so restful? GET /author/:id/blogEntry/:id/comments GET /author/:id GET /author/:id/blogEntry/:id <<class>>
 Author Long id String name String email String bio List<BlogEntry>
 blogEntries <<class>>
 BlogEntry Long id String title List<Comment> comments <<class>>
 Comment Long id String author String comment
  • 8. REST not so restful? GET /author/:id/blogEntry/:id/comments GET /author/:id GET /author/:id/blogEntry/:id <<class>>
 Author Long id String name String email String bio List<BlogEntry>
 blogEntries <<class>>
 BlogEntry Long id String title List<Comment> comments <<class>>
 Comment Long id String author String comment {
 id: 1,
 author: “anonymous”,
 comment: “super!”
 }
  • 9. While in GraphQL… authors(filter : {id : 1 }) {
 name
 blogEntry {
 title
 comment {
 comment
 }
 }
 } <<class>>
 Author Long id String name String email String bio List<BlogEntry>
 blogEntries <<class>>
 BlogEntry Long id String title List<Comment> comments <<class>>
 Comment Long id String author String comment
  • 10. What is GraphQL? “GraphQL is a query language for APIs and a runtime for fulfilling those queries with your existing data.” — http://graphql.org
  • 11. What is GraphQL? “GraphQL is a query language for APIs and a runtime for fulfilling those queries with your existing data.” — http://graphql.org Declarative
 Ask for what you need, get exactly that
  • 12. What is GraphQL? “GraphQL is a query language for APIs and a runtime for fulfilling those queries with your existing data.” — http://graphql.org Declarative
 Ask for what you need, get exactly that Compositional
 Get many resources in a single request
  • 13. What is GraphQL? “GraphQL is a query language for APIs and a runtime for fulfilling those queries with your existing data.” — http://graphql.org Declarative
 Ask for what you need, get exactly that Compositional
 Get many resources in a single request Strongly Typed
 Describe what’s possible with a type system
  • 14. GraphQL query authors { # queries can have comments! name email blogEntries { title } }
  • 15. GraphQL query authors { # queries can have comments! name email blogEntries { title } } { "data": { "authors": [ { "name": "author 1", "email": "Python dev", "blogEntries": [ { "title": "blog entry 1" }, { "title": "blog entry 3" } ] }, { "name": "author 2", "email": "Java dev", "blogEntries": [ { "title": "blog entry 2" }, { "title": "blog entry 4" } ] } ] }
  • 16. GraphQL query - filter authors(filter : {id : 1 }) { name email blogEntries { title } }
  • 17. GraphQL query - filter authors(filter : {id : 1 }) { name email blogEntries { title } } { "data": { "authors": [ { "name": "author 1", "email": "Python dev", "blogEntries": [ { "title": "blog entry 1" }, { "title": "blog entry 3" } ] } ] } }
  • 18. GraphQL mutation mutation addAuthorMutation($authorInfo: addAuthorInput!) { addAuthor(input : $authorInfo) { id name bio email } } { "authorInfo": { "id": 1, “name" : "Krzysztof Pawlowski", "bio" : "java dev", "email" : "krzysztof.pawlowski@merapar.com" }
  • 19. GraphQL mutation mutation addAuthorMutation($authorInfo: addAuthorInput!) { addAuthor(input : $authorInfo) { id name bio email } } { "authorInfo": { "id": 1, “name" : "Krzysztof Pawlowski", "bio" : "java dev", "email" : "krzysztof.pawlowski@merapar.com" } { "data": { "addAuthor": { "id": 1, "name": "Krzysztof Pawlowski", "bio": "java dev", "email": 
 “krzysztof.pawlowski@merapar.com" } } }
  • 20. GraphQL schema type Author {
 id: Long! name: String bio: String email: String
 blogEntries: [BlogEntry] }
 
 type BlogEntry { id: Long! title: String! comments: [Comment] } type Comment { id: Long! author: String comment: String }

  • 21. GraphQL schema type Author {
 id: Long! name: String bio: String email: String
 blogEntries: [BlogEntry] }
 
 type BlogEntry { id: Long! title: String! comments: [Comment] } type Comment { id: Long! author: String comment: String }
 type Query { authors(id: Long!): Author blogEntries(id: Long!): BlogEntry comments(id: Long!): Comment } type Mutation { addAuthor(author: Author!): Author updateAuthor(author: Author!): Author deleteAuthor(author: Author!): Author … }
  • 22. GraphQL schema type Author {
 id: Long! name: String bio: String email: String
 blogEntries: [BlogEntry] }
 
 type BlogEntry { id: Long! title: String! comments: [Comment] } type Comment { id: Long! author: String comment: String }
 type Query { authors(id: Long!): Author blogEntries(id: Long!): BlogEntry comments(id: Long!): Comment } type Mutation { addAuthor(author: Author!): Author updateAuthor(author: Author!): Author deleteAuthor(author: Author!): Author … } schema { query: Query mutation: Mutation }
  • 23. Other benefits of GraphQL ‣flexibility ‣one end-point ‣self-documenting (strong typing and schema) ‣query validation ‣no versioning needed
  • 25. Spring Boot Starter for GraphQL ‣adding Maven dependency creates GraphQL controller under
 /v1/graphql <dependency> <groupId>com.merapar</groupId> <artifactId>graphql-spring-boot-starter</artifactId> <version>1.0.2</version> </dependency> ‣adding new queries and mutation is a matter of implementing GraphQlFields interface
  • 27. Problems with GraphQL ‣HTTP caching ‣Unpredictable execution ‣No handling for file upload ‣Authorisation and authentication
  • 29. Bonus — GitHub GraphQL API https://developer.github.com/v4/