Netflix's GraphQL for Spring Boot |
Written by Nikos Vaggalis | |||
Wednesday, 10 March 2021 | |||
Netflix has open sourced its DGS Framework (Domain Graph Service) GraphQL server framework for Spring Boot. Starting out as a tool internal to the corporation, it has been generously open sourced for the rest of us to enjoy. Netflix is one of those organizations that have gone beyond REST, embracing GraphQL instead. Rather than exposing a myriad of microservices to UI developers, Netflix opted for a unified API aggregation layer at the edge, powered by GraphQL. Since they also use Spring Boot for their infrastructure, merging was bound to happen. As such the DGS framework is built on top of graphql-java and in essence it offers a layer of abstraction over the library's low-level details. While exclusively written in Kotlin (requires Kotlin 1.4), the framework mainly targets Java as Java is most closely associated with Spring Boot.That said, you are free to write your code in Kotlin too. Integrating the library is easy since it too utilizes Spring Boot’s annotation-based model. For example in implementing a Data Fetcher (constructs which return the data for a query) you use the following annotation based snippet :
Apart from that, it comes with a host of other features:
It's pretty easy to setup. Just add the reference to the library com.netflix.graphql.dgs:graphql-dgs-spring-boot-starter and let it consume your GraphQL schema file as DGS is designed for schema-first development. To generate each GraphQL type for each type described in the schema, as well as to generate the Data Fetchers, the DSG codegen plugin must be included in the project :
This works according to the mapping rules so, for example, the basic scalar types are mapped to corresponding Java/Kotlin types (String, Integer etc.), whereas the date and time types are mapped to corresponding java.time classes. The code generator can also create the client API classes which you can use to query data from a GraphQL endpoints using Java. This is another testament to Spring Boot's versatility for your backend development; there are just so many integration options, something I found out first hand when graduating from the Java Web Developer Nanodegree. (See my Insider's Guide here). Now it can do GraphQL with ease too. More InformationRelated ArticlesThe Insider's Guide to the Java Web Developer Nanodegree Foojay - All About Java and the OpenJDK Introducing The Android Kotlin Developer Nanodegree
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.
Comments
or email your comment to: comments@i-programmer.info |
|||
Last Updated ( Wednesday, 10 March 2021 ) |