DEV Community

How to Build GraphQL Services in Java with Spring Boot

Sam Benskin on May 22, 2018

NOTE: Please be aware this article is now out of date as the tech has moved on since I wrote it in 2019. Let's start by taking a quick look at the...
Collapse
 
hugecoderguy profile image
Christian Kreiling

Hey Sam, I've written Java webapps with spotify/apollo before but haven't used Spring. This was a helpful introduction to Spring and the ease of creating a GraphQL server, but do you have any resources for learning Spring / Spring Boot quickly and effectively?

Collapse
 
sambenskin profile image
Sam Benskin

Thank you for the kind words. As far as resources, I always use Google to search for answers to the problems I have but more often than not I'll see an article on baeldung.com that is always well written, well layed out and succinct so I would check that site out if I were you. Of course dev.to has many brilliant articles so I'm sure you'll find something here too.

Collapse
 
ialserdamatrik profile image
Ivo

Hi Sam, very clear written example, thanks. Do you also have a nice example of a Spring Boot Graphql client project to connect to this graphql server. I see a lot of graphql client projects written in NodeJS, Android and iOS but it is hard to find it in java. I think this is because graphql is meant to use it from a frontend framework ( like apollo for android ) and it is not common to use it from a java backend environment.

Collapse
 
gilyaary profile image
gilyaary

This is the best tutorial so far. A to B with no extra clutter. I was able to quickly setup, understand and run the example code.
Very Well Done!!!!

Collapse
 
sambenskin profile image
Sam Benskin

Thank you 😀 I'm glad it's helped you getting started

Collapse
 
biggo6 profile image
Joram Kimata

Thanks for good tutorial, was awesome one but i wonder if you will share with us advanced features of graphql with java like mutation and subscription concepts

Collapse
 
sambenskin profile image
Sam Benskin

Thanks, I haven't written anything yet but I'll definitely consider it.

Collapse
 
acedrow profile image
Linden Holt

Concise and educational tutorial. Gives you everything you need and nothing else, and it works like a charm. Love it.

Collapse
 
sambenskin profile image
Sam Benskin

Thank you 😀

Collapse
 
naveenpop profile image
naveenp

I've written mine after looking at this post.

github.com/nkumarclm/graphql-sample - Graph QL to stitch 2 Rest APIs

Collapse
 
devlopix profile image
devlopix

Thank you man !

Collapse
 
sambenskin profile image
Sam Benskin

You're welcome 😀

Collapse
 
khteh profile image
Teh Kok How

Deploying the application as WAR to tomcat server 9 causes exception: github.com/graphql-java-kickstart/...

Collapse
 
sambenskin profile image
Sam Benskin

Sorry I've not tried that, hope you find the issue and can report back to help anyone else in the same situation

Collapse
 
naveenpop profile image
naveenp

Awesome :)

Collapse
 
sambenskin profile image
Sam Benskin

Thanks 😀

Collapse
 
rolfed profile image
Danniel Rolfe

Hey Sam,
This is a really well written tutorial. I'm working on learning GraphQL and this was the perfect introduction. Keep up the great work.

Collapse
 
sambenskin profile image
Sam Benskin

Thank you, that's very kind of you to say

Collapse
 
sunnyagarwal008 profile image
sunnyagarwal008

How do we define graphql schema with query variables in this example?

Collapse
 
sambenskin profile image
Sam Benskin

Sorry but that's out the scope of this article. I'll try to include it in a future article so.please follow me if you want to be notified when I publish it

Collapse
 
abdel777 profile image
abdellah Frindou

Hello, thanks for your article. i followed the same instructions but i dont get the results. the url localhost:8080/graphiql shows an error

Collapse
 
abdel777 profile image
abdellah Frindou • Edited

it works now, it was enough to write localhost:8080 without adding /graphiql. but can you please explain more how that happend. i mean just writing petshop.graphqls and the resolvers and that was enough to get the data. How the process is that he know this file(petshop.graphqls) and parse it to a java Object. is it possible to add more .graphqls files and interaction between them.