Spring GraphQL Milestone One
Written by Nikos Vaggalis   
Monday, 19 July 2021

A new library aims to unify all the previous approaches of accessing GraphQL from Spring. The Spring GraphQL project, which has reached its initial milestone towards a 1.0 release, integrates GraphQL, Java and Spring and was developed as a collaboration between both teams.

Until now the way you accessed GraphQL from Spring was through the standard GraphQL Java Spring project which at the minimum would expose a /graphql endpoint (something that as well as the transport agnostic, was missing from the original GraphQL Java library) in order to accept the GraphQL payloads over HTTP; or the newest counterpart, that of the Netflix DGS Framework (Domain Graph Service).

However adding Spring support to GraphQL Java was an afterthought and not first class citizenship. Thus as of this July, there's another option that aims to completely replace the venerable GraphQL Java Spring library (which is itself based on GraphQL Java) and integrate Spring from the beginning.

At the minimum this new library provides out of the box: 

  • HTTP handlers – available for both Spring MVC and WebFlux, built on WebMvc and WebFlux functional endpoint APIs.
  • WebSocket handlers – following the protocol from graphql-ws with support for GraphQL subscription streams.
  • Web Interception – ability to intercept every GraphQL request, inspect HTTP headers, and modify the GraphQL ExecutionInput or ExecutionResult.
  • Boot starter – put it all together into a runnable application. 

Other than that it improves on the sectors of Security,Exception Handling,Testing and Metrics.

 

Since GraphQL provides a schema language, it once more brings up the Schema First vs Code First debate.The team behind Spring GraphQL is certainly not shy admitting that they're pro-schema. It's a notion that I also share generally, but especially when doing Hibernate-related work, as I describe in The Insider's Guide to the Java Web Developer Nanodegree:

I thought that the process of creating entities, mapping PK's and relationships in code would be too cumbersome. I preferred to start the other way around; be given a database schema to generate the entities and their relationships, especially since MySQL is used as it provides a very nice Workbench where you can design your ERD.

In fact, after completing this course, I'll be looking to go database first and start from the schema to generate the code. Fortunately there are dedicated tools for that too: Hibernate tools for reverse engineering.

The same concept applies here too, and in this case the analogous of Hibernate tools can be the Neftlix DGS Code Generation plugin which generates data types and queries from your schema.

Talking about DGS, the framework, where does it fit in the larger picture?

In Netflix's GraphQL for Spring Boot  I mention that the DGS framework is also built on top of graphql-java and in essence it offers a layer of abstraction over the library's low-level details.

So what's the difference between DGS and Spring GraphQL? The answer lies in that

the spring-graphql user facing API is fairly low-level, and the user mostly uses the graphql-java API. The DGS framework in contrast offers a user-friendly, declarative programming model.

Saying that there's already a plan to fuse them in Prototyping spring-graphql integration.

As it currently stands the Spring GraphQL project is in a milestone phase towards a 1.0 release, but there are already two sample projects which showcase its use:
Spring PetClinic Sample Application using spring-graphql and spring-graphql-demo

 

More Information

Hello, Spring GraphQL
Documentation

GitHub

Related Articles

Netflix's GraphQL for Spring Boot

The Insider's Guide to the Java Web Developer Nanodegree - 4.

 

To be informed about new articles on I Programmer, sign up for our weekly newsletter, subscribe to the RSS feed and follow us on Twitter, Facebook or Linkedin.

Banner


A Tee Is Not Just For Xmas - Top Tees
20/12/2024

Programmer gifts - easy idea, difficult implementation.  Here's our pick of tee-shirts for giving, buying or just wearing at any time of the year.



Hour Of Code 2024 Is About To Kick Off
04/12/2024

This year the event that aims to provide a coding experience for all school students and anyone else who wants to join in runs between December 9th and 15th and includes new activities. Let's find out [ ... ]


More News

espbook

 

Comments




or email your comment to: comments@i-programmer.info

Last Updated ( Monday, 19 July 2021 )