|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:
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:
or email your comment to: firstname.lastname@example.org
|Last Updated ( Monday, 19 July 2021 )|