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