SlideShare a Scribd company logo
1 of 39
Download to read offline
GraphQL-ify your APIs
Soham Dasgupta
Capgemini Netherlands
What’s in store today
GraphQL
What
Queries & Mutation
Schemas & Types
Show me some code
graphql-java
graphql-java-kickstart
graphql-dgs-framework
spring-graphql
What’s better
Implementation easiness – code,
generation, error handling, testing,
clients
N+1 problem
GraphQL is a query language for your API, and a
server-side runtime for executing queries.
Backed by your existing code and data.
It was designed by Facebook to get around
common constraints in fetching data via REST.
It was open sourced by Facebook in 2015.
Nothing to do with Graph DB.
Not a replacement of REST.
Not going to magically solve every API design
issues.
What’s GraphQL
Schema Query Results
Schema , Query & Results
GraphQL provides description of the data in your API, gives clients the power to ask for exactly
what they need.
https://landscape.graphql.org/card-mode?category=graph-ql-adopter&grouping=category&style=borderless
Who is using it ?
GraphQL vs REST API vs SOAP
https://trends.google.com/trends/explore?date=today%205-y&q=%2Fg%2F11cn3w0w9t,REST%20API,%2Fm%2F077dn
Hierarchical & Aggregator Strongly Typed
Validation & Type check
out-of-the-box
API evolution without
versioning
GraphQL
Characteristics
Query & Mutation
• Ask what you need.
• Expand the same
query.
• Send arguments.
• Use Aliases, Fragment
Schemas & Types
• GraphQL schema language -
allows us to talk about
GraphQL schemas in a
language-agnostic way.
• Scalar : Int, String, Boolean, ID,
Float
• Lists & Non-Null
• Union, Interfaces, Input Types
N+1 queries Caching complexity
Community presence File Upload
GraphQL
Maturity
Show me some code
graphql-java
graphql-java-kickstart
graphql-dgs-framework
spring-graphql
https://github.com/sohamda/serivce-repository-swagger
graphql-java https://www.graphql-java.com/documentation/getting-started
https://github.com/graphql-java - Version 18.2 : Last updated on June’22
https://github.com/graphql-java/graphql-java-spring
This project is archived in favor of the official Spring GraphQL integration
https://github.com/sohamda/graphql-java
graphql-java- kickstart https://graphql-java-kickstart.com/
https://github.com/graphql-java-kickstart
Version 12 : Last updated on Sep’21
https://github.com/sohamda/graphql-java-kickstart
dgs-framework
https://netflix.github.io/dgs/
https://github.com/Netflix/dgs-framework
Version 5.0.5 : Last updated on July’22
https://github.com/sohamda/graphql-dgs-netflix
Spring GraphQL https://docs.spring.io/spring-
graphql/docs/current/reference/html/
https://github.com/spring-projects/spring-graphql
Version 1.0.0 : Last updated on May’22
19-7-2022
19
spring-graphql application structure
H2
Providers(1)
Services(*)
JPA
Repository
Service
spring-graphql
BatchLoaderRegistry
Controller
/graphql/providerservice
SchemaMapping
MutationMapping
https://github.com/sohamda/spring-graphql
What’s better
Implementation easiness – code, generation, error
handling, testing, clients
N+1 problem
21
DataFetchers
Piece of code that fetches the data
1. Define a @Component which defines
datafetching methods.
2. Register them in while building/parsing
the schema
graphql-java
22
DataFetchers
Piece of code that fetches the data
1. Define @Component which implements
GraphQLQueryResolver.
2. For field-level define a @Component
which implements GraphQLResolver<T>.
graphql-java-kickstart
23
DataFetchers
Piece of code that fetches the data
1. Define a @DgsComponent.
2. Map the schema operations with
@DgsData
dgs
24
DataFetchers
Piece of code that fetches the data
1. Define a @Controller.
2. Map the schema operations with
@SchemaMapping or @QueryMapping
spring-graphql
25
DataLoaders
Piece of code that is responsible for N+1 query issue
1. Define a BatchLoader which
return s a CompletableFuture.
2. Define a DataLoaderRegistry
@Bean which registers the
Loader.
3. Define a DataFetcher using that
Loader.
graphql-java
26
DataLoaders
Piece of code that is responsible for N+1 query issue
1. Define @Component which
defines a loader and adds it to
the registry.
2. Define a @Component which
implements
GraphQLServletContextBuilder
and associate the registry.
3. Define a @Component which
invokes the dataloader.
graphql-java-kickstart
27
DataLoaders
Piece of code that is responsible for N+1 query issue
1. Define a @DgsDataLoader.
2. Map the schema operations with
@DgsData
dgs
28
DataLoaders
Piece of code that is responsible for N+1 query issue
1. Register (Mapped)BatchLoader.
2. Map it to the method that can be
invoked for a list of keys.
3. Load the dataloader with
@SchemaMapping/@QueryMapping
spring-graphql
29
Error Handling
Piece of code that handles exceptions/errors
1. Implement GraphQLError
graphql-java
30
Error Handling
Piece of code that handles exceptions/errors
• Enable ExceptionHandler property
and handle them in a Spring way.
OR
• Implement GraphQLErrorHandler
and manage the errors in overridden
method.
graphql-java-kickstart
31
Error Handling
Piece of code that handles exceptions/errors
• Define a @Component which
implements
DataFetcherExceptionHandler
dgs
32
Error Handling
Piece of code that handles exceptions/errors
1. Define a Config bean and register
the exception handlers.
spring-graphql
34
Client
How to call a GraphQL API
1. No defined way.
2. Needs text templates to generate
requests.
graphql-java
35
Client
How to call a GraphQL API
1. Gives a Webclient library.
2. Needs text templates to generate
requests.
graphql-java-kickstart
36
Client
How to call a GraphQL API
1. GraphQLClient uses String as query
which is same as the previous two.
2. Code generation using
Gradle/Maven. This is the type-safe
option.
dgs
37
Client
How to call a GraphQL API
1. Define WebGraphQlClient object.
2. Options are http, websocket,
rsocket.
3. Executing the query gives Mono
object.
4. Responses can be mapped to an
custom object.
spring-graphql
Testing & Code Generation
grpahql-java graphql-java-kickstart dgs spring-graphql
X X
1. Code generation using
Gradle/Maven. This is the
type-safe option.
2. Use the generated classes
to build request and test
using
DgsAutoConfiguration
class.
1. No Code generation.
2. @AutoConfigureXXGraph
QlTester to initialize
context.
3. Responses can be mapped
to custom objects.
graphql-java
graphql-java-
kickstart
dgs
spring-graphql
• Is there since long, so
evolved and matured.
• A lot of Boilerplate
code just to write a
simple API.
• Library for Spring boot
is archieved.
• Not a easy way to Unit
Test everything you
write.
• No Clients avaiable.
Need to use text
templates to create
queries.
• Matured but missing
extended
documentation.
• Still a bit of Boilerplate
code.
• Directly usable within
Springboot. Although
other modules
available to work on
Java only
environments.
• Not a easy way to UT
everything you write.
• Basic Client avaiable.
• Not sure about
maturity, but Netflix is
behind this, so faith is
there.
• No Boilerplate code.
• Directly usable within
Springboot.
• You can UT everything
you write.
• Client avaiable.
• Code generation using
Gradle/Maven.
• Just released not
enough usage data
available.
• No Boilerplate code.
• Spring is behind this.
• You can UT everything
you write.
• Client avaiable.
• No Code generation.
Final words
https://github.com/sohamda?tab=repositories&q=graphql&type=&language=&sort=
Soham Dasgupta
• Twitter : @iamsoham
• LinkedIn: dasguptasoham
• Github: sohamda
• Medium: @iam.soham

More Related Content

What's hot

What's hot (20)

Graphql
GraphqlGraphql
Graphql
 
GraphQL
GraphQLGraphQL
GraphQL
 
Introduction to graphQL
Introduction to graphQLIntroduction to graphQL
Introduction to graphQL
 
Introduction to GraphQL
Introduction to GraphQLIntroduction to GraphQL
Introduction to GraphQL
 
GraphQL as an alternative approach to REST (as presented at Java2Days/CodeMon...
GraphQL as an alternative approach to REST (as presented at Java2Days/CodeMon...GraphQL as an alternative approach to REST (as presented at Java2Days/CodeMon...
GraphQL as an alternative approach to REST (as presented at Java2Days/CodeMon...
 
Introduction to GraphQL
Introduction to GraphQLIntroduction to GraphQL
Introduction to GraphQL
 
GraphQL
GraphQLGraphQL
GraphQL
 
How to GraphQL
How to GraphQLHow to GraphQL
How to GraphQL
 
GraphQL Fundamentals
GraphQL FundamentalsGraphQL Fundamentals
GraphQL Fundamentals
 
Spring GraphQL
Spring GraphQLSpring GraphQL
Spring GraphQL
 
GraphQL vs REST
GraphQL vs RESTGraphQL vs REST
GraphQL vs REST
 
GraphQL Story: Intro To GraphQL
GraphQL Story: Intro To GraphQLGraphQL Story: Intro To GraphQL
GraphQL Story: Intro To GraphQL
 
Graphql Intro (Tutorial and Example)
Graphql Intro (Tutorial and Example)Graphql Intro (Tutorial and Example)
Graphql Intro (Tutorial and Example)
 
Intro to GraphQL
 Intro to GraphQL Intro to GraphQL
Intro to GraphQL
 
GraphQL: Enabling a new generation of API developer tools
GraphQL: Enabling a new generation of API developer toolsGraphQL: Enabling a new generation of API developer tools
GraphQL: Enabling a new generation of API developer tools
 
Graphql presentation
Graphql presentationGraphql presentation
Graphql presentation
 
Building Fullstack Serverless GraphQL APIs In The Cloud
Building Fullstack Serverless GraphQL APIs In The CloudBuilding Fullstack Serverless GraphQL APIs In The Cloud
Building Fullstack Serverless GraphQL APIs In The Cloud
 
GraphQL Introduction
GraphQL IntroductionGraphQL Introduction
GraphQL Introduction
 
Getting Started with Spring for GraphQL
Getting Started with Spring for GraphQLGetting Started with Spring for GraphQL
Getting Started with Spring for GraphQL
 
REST vs. GraphQL: Critical Look
REST vs. GraphQL: Critical LookREST vs. GraphQL: Critical Look
REST vs. GraphQL: Critical Look
 

Similar to GraphQL-ify your APIs

Training Series: Build APIs with Neo4j GraphQL Library
Training Series: Build APIs with Neo4j GraphQL LibraryTraining Series: Build APIs with Neo4j GraphQL Library
Training Series: Build APIs with Neo4j GraphQL Library
Neo4j
 

Similar to GraphQL-ify your APIs (20)

GraphQL-ify your API - JFall 2022
GraphQL-ify your API - JFall 2022GraphQL-ify your API - JFall 2022
GraphQL-ify your API - JFall 2022
 
GraphQL_devoxx_2023.pptx
GraphQL_devoxx_2023.pptxGraphQL_devoxx_2023.pptx
GraphQL_devoxx_2023.pptx
 
GraphQL-ify your APIs
GraphQL-ify your APIsGraphQL-ify your APIs
GraphQL-ify your APIs
 
GraphQL-ify your APIs - Devoxx UK 2021
 GraphQL-ify your APIs - Devoxx UK 2021 GraphQL-ify your APIs - Devoxx UK 2021
GraphQL-ify your APIs - Devoxx UK 2021
 
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 across the stack: How everything fits together
GraphQL across the stack: How everything fits togetherGraphQL across the stack: How everything fits together
GraphQL across the stack: How everything fits together
 
Tutorial: Building a GraphQL API in PHP
Tutorial: Building a GraphQL API in PHPTutorial: Building a GraphQL API in PHP
Tutorial: Building a GraphQL API in PHP
 
GraphQL & Ratpack
GraphQL & RatpackGraphQL & Ratpack
GraphQL & Ratpack
 
How easy (or hard) it is to monitor your graph ql service performance
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
 
How to provide a GraphQL API - I want it that way
How to provide a GraphQL API - I want it that wayHow to provide a GraphQL API - I want it that way
How to provide a GraphQL API - I want it that way
 
Graphql Overview By Chirag Dodia
Graphql Overview By Chirag DodiaGraphql Overview By Chirag Dodia
Graphql Overview By Chirag Dodia
 
GraphQL & DGraph with Go
GraphQL & DGraph with GoGraphQL & DGraph with Go
GraphQL & DGraph with Go
 
Training Week: GraphQL 2022
Training Week: GraphQL 2022Training Week: GraphQL 2022
Training Week: GraphQL 2022
 
Training Series: Build APIs with Neo4j GraphQL Library
Training Series: Build APIs with Neo4j GraphQL LibraryTraining Series: Build APIs with Neo4j GraphQL Library
Training Series: Build APIs with Neo4j GraphQL Library
 
Code-first GraphQL Server Development with Prisma
Code-first  GraphQL Server Development with PrismaCode-first  GraphQL Server Development with Prisma
Code-first GraphQL Server Development with Prisma
 
MuleSoft Surat Virtual Meetup#6 - MuleSoft Project Template Using Maven Arche...
MuleSoft Surat Virtual Meetup#6 - MuleSoft Project Template Using Maven Arche...MuleSoft Surat Virtual Meetup#6 - MuleSoft Project Template Using Maven Arche...
MuleSoft Surat Virtual Meetup#6 - MuleSoft Project Template Using Maven Arche...
 
GraphQL over REST at Reactathon 2018
GraphQL over REST at Reactathon 2018GraphQL over REST at Reactathon 2018
GraphQL over REST at Reactathon 2018
 
GraphQL + relay
GraphQL + relayGraphQL + relay
GraphQL + relay
 
Boost your APIs with GraphQL 1.0
Boost your APIs with GraphQL 1.0Boost your APIs with GraphQL 1.0
Boost your APIs with GraphQL 1.0
 
React inter3
React inter3React inter3
React inter3
 

More from Soham Dasgupta

More from Soham Dasgupta (6)

Are you testing your unit tests?
Are you testing your unit tests?Are you testing your unit tests?
Are you testing your unit tests?
 
Spring Native : Why not YET!
Spring Native : Why not YET!Spring Native : Why not YET!
Spring Native : Why not YET!
 
OneBot: A Comprehensive Case Study on Enterprise Digital Assistants
OneBot: A Comprehensive Case Study on Enterprise Digital AssistantsOneBot: A Comprehensive Case Study on Enterprise Digital Assistants
OneBot: A Comprehensive Case Study on Enterprise Digital Assistants
 
No-Java Enterprise Applications: It’s All About JavaScript [DEV5107]
No-Java Enterprise Applications: It’s All About JavaScript [DEV5107]No-Java Enterprise Applications: It’s All About JavaScript [DEV5107]
No-Java Enterprise Applications: It’s All About JavaScript [DEV5107]
 
Javascript for Enterprise Application
Javascript for Enterprise ApplicationJavascript for Enterprise Application
Javascript for Enterprise Application
 
How the Dutch Police became “Chatbot” interactive
How the Dutch Police became “Chatbot” interactiveHow the Dutch Police became “Chatbot” interactive
How the Dutch Police became “Chatbot” interactive
 

Recently uploaded

Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers:  A Deep Dive into Serverless Spatial Data and FMECloud Frontiers:  A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
Safe Software
 
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
?#DUbAI#??##{{(☎️+971_581248768%)**%*]'#abortion pills for sale in dubai@
 

Recently uploaded (20)

Artificial Intelligence Chap.5 : Uncertainty
Artificial Intelligence Chap.5 : UncertaintyArtificial Intelligence Chap.5 : Uncertainty
Artificial Intelligence Chap.5 : Uncertainty
 
Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024
 
TrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law DevelopmentsTrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
 
Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...
Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...
Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...
 
Polkadot JAM Slides - Token2049 - By Dr. Gavin Wood
Polkadot JAM Slides - Token2049 - By Dr. Gavin WoodPolkadot JAM Slides - Token2049 - By Dr. Gavin Wood
Polkadot JAM Slides - Token2049 - By Dr. Gavin Wood
 
Deploy with confidence: VMware Cloud Foundation 5.1 on next gen Dell PowerEdg...
Deploy with confidence: VMware Cloud Foundation 5.1 on next gen Dell PowerEdg...Deploy with confidence: VMware Cloud Foundation 5.1 on next gen Dell PowerEdg...
Deploy with confidence: VMware Cloud Foundation 5.1 on next gen Dell PowerEdg...
 
GenAI Risks & Security Meetup 01052024.pdf
GenAI Risks & Security Meetup 01052024.pdfGenAI Risks & Security Meetup 01052024.pdf
GenAI Risks & Security Meetup 01052024.pdf
 
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers:  A Deep Dive into Serverless Spatial Data and FMECloud Frontiers:  A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
 
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
 
presentation ICT roal in 21st century education
presentation ICT roal in 21st century educationpresentation ICT roal in 21st century education
presentation ICT roal in 21st century education
 
Strategies for Landing an Oracle DBA Job as a Fresher
Strategies for Landing an Oracle DBA Job as a FresherStrategies for Landing an Oracle DBA Job as a Fresher
Strategies for Landing an Oracle DBA Job as a Fresher
 
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
 
Workshop - Best of Both Worlds_ Combine KG and Vector search for enhanced R...
Workshop - Best of Both Worlds_ Combine  KG and Vector search for  enhanced R...Workshop - Best of Both Worlds_ Combine  KG and Vector search for  enhanced R...
Workshop - Best of Both Worlds_ Combine KG and Vector search for enhanced R...
 
Manulife - Insurer Innovation Award 2024
Manulife - Insurer Innovation Award 2024Manulife - Insurer Innovation Award 2024
Manulife - Insurer Innovation Award 2024
 
How to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerHow to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected Worker
 
Partners Life - Insurer Innovation Award 2024
Partners Life - Insurer Innovation Award 2024Partners Life - Insurer Innovation Award 2024
Partners Life - Insurer Innovation Award 2024
 
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, AdobeApidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
 
Powerful Google developer tools for immediate impact! (2023-24 C)
Powerful Google developer tools for immediate impact! (2023-24 C)Powerful Google developer tools for immediate impact! (2023-24 C)
Powerful Google developer tools for immediate impact! (2023-24 C)
 
Boost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdfBoost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdf
 
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
 

GraphQL-ify your APIs