2. Soham Dasgupta
• Father, Husband and Football lover
• Capgemini Netherlands
• Oracle ACE
• Tech Enthusiast/Programmer/Architect
• Speaker & Blogger
• Twitter : @iamsoham
• LinkedIn: dasguptasoham
• Github: sohamda
• Medium: @iam.soham
Who am I?
3. What’s in store today
GraphQL
What
Queries & Mutation
Schemas & Types
Show me some code
graphql-java
graphql-java-kickstart
graphql-dgs-framework
What’s better
Implementation easiness – code,
generation, error handling, testing,
clients
N+1 problem
Memory footprint
4. 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
5. 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.
7. GraphQL vs REST API vs SOAP
https://trends.google.com/trends/explore?date=today%205-y&q=%2Fg%2F11cn3w0w9t,REST%20API,%2Fm%2F077dn
8. Hierarchical & Aggregator Strongly Typed
Validation & Type check
out-of-the-box
API evolution without
versioning
GraphQL
Characteristics
9. 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
20. DataFetchers
graphql-java
Piece of code that fetches the data
graphql-java-kickstart dgs
1. Define a @Component which
defines datafetching methods.
2. Register them in while
building/parsing the schema
1. Define @Component which
implements
GraphQLQueryResolver.
2. For field-level define a
@Component which
implements
GraphQLResolver<T>.
1. Define a @DgsComponent.
2. Map the schema operations
with @DgsData
21. DataLoaders
graphql-java
Piece of code that is responsible for N+1 query issue
graphql-java-kickstart dgs
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.
1. Define @Component which
defines a loader and adds it to
the registry.
2. Define a @Component which
implements
GraphQLServletContextBuild
er and associate the registry.
1. Define a @DgsDataLoader.
2. Map the schema operations
with @DgsData
22. Mutations
graphql-java
Piece of code that persist the data
graphql-java-kickstart dgs
1. Define a @Component which
defines datafetching methods.
2. Register them in while
building/parsing the schema
• Define @Component which
implements
GraphQLMutationResolver.
1. Define a @DgsComponent.
2. Map the schema operations
with @DgsData
23. Error Handling
graphql-java
Piece of code that handles exceptions/errors
graphql-java-kickstart dgs
Implement GraphQLError 1. Enable ExceptionHandler
property and handle
them in a Spring way.
2. Implement
GraphQLErrorHandler
and manage the errors in
overridden method.
Define a @Component which
implements
DataFetcherExceptionHandle
r
24. Client
graphql-java
How to call a GraphQL API
graphql-java-kickstart dgs
1. No defined way.
2. Needs text templates to
generate requests.
1. Gives a Webclient library.
2. Needs text templates to
generate requests.
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.
25. Testing
graphql-java
How to test your code
graphql-java-kickstart dgs
1. No defined way.
2. Only can test the service-repo
layer.
1. No defined way.
2. Only can test the service-repo
layer.
1. Code generation using Gradle.
This is the type-safe option.
2. Use the generated classes to
build request and test using
DgsAutoConfiguration class.
graphql-java graphql-java-kickstart dgs
1. No defined way. 1. No defined way. 1. Code generation using
Gradle/Maven.
Code Generation
27. Final Words
graphql-java graphql-java-kickstart dgs-framework
• Is there since long, so evolved
and matured.
• A lot of Boilerplate code just
to write a simple API.
• Need extra library to work in
Springboot. With other Java
• Not a easy way to Unit Test
everything you write.
• No Clients avaiable. Need to
use text templates to create
queries.
• Looks very 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.
https://medium.com/springboot-chronicles/graphql-in-springboot-a-comparative-study-
among-the-libraries-and-their-implementation-know-how-b0e8d544f2fc