4

I am new to GraphQL and was exploring it since last few weeks. I am looking for suggestions for GraphQL Clients in Java.

As we work on Java based application, would really appreciate if some-one can point me to the different GraphQL Java Clients which have the basic features like query/mutation/subscription.

I explored some of them like DGS framework by Netflix, which has integration with Spring Boot and has annotation support. However before arriving to conclusion, would really appreciate if i can get a comparison of different Java Clients on the following aspects:

  1. Set of features like support for extended java scalars types etc.
  2. The ones which are in active development as well as the ones which are used extensively.
  3. Limitations if any.
  4. Simple and easy to use
  5. OpenSource?

If at all possible, please do share the respective links for the popular clients.

Appreciate your Help!! Thanks in Advance.

Ashu
  • 163
  • 4
  • 13
  • Folks, Any updates on this? Can some-one please share their experience or evaluation in choosing the GraphQL java Client based on the parameters? – Ashu May 17 '22 at 17:54
  • did you land on a solution? – timon_the_destroyer Dec 20 '22 at 16:28
  • Looking at the solutions available, i moved forward with a hybrid way of using Apollo/HTTP Client for Android/Kotlin, which has some steps like generating models, that needs to be automated as well. For inline queries where one doesn't want strict type checking, we can use the HTTP Client – Ashu Dec 23 '22 at 08:15

2 Answers2

1

EDIT: this answer focuses on graphql java servers as you mentioned spring-boot. If you are after graphql java clients, I would recommend the Apollo Client, it is easy to use and does everything you could need.

Disclaimer: I have never used DGS, and I have not been using graphql-java actively in the last year, things might have changed. I have tried graphql-java-tools and spqr. This answer is opinionated.

The graphql implementation graphql-java was around before DGS. It is open source and you will find many project have been built on top of it. Projects that add features to graphql-java itself can be found in the graphl-java repositories, making graphql-java quite modular and adaptable to your needs.

For example:

Graphql-java is quite verbose, and I would not recommend using it as is. Instead I would recommend using one of the following projects.

https://github.com/kobylynskyi/graphql-java-codegen generate your graphql server/client from your schema, following a schema first approach

https://github.com/leangen/graphql-spqr or https://github.com/Enigmatis/graphql-java-annotations follow a code first approach and makes a very efficient use of annotation to generate your schema from your code (spqr also provide a spring-boot starter)

https://github.com/graphql-java-kickstart/graphql-java-tools use a schema first approach and that let you create your own DTO. It takes care of most of the boiler plate code. It is Spring friendly (if used to the Spring framework, the graphql-java-tools resolver will be very intuitive), and has a spring-boot start. The schema parser and class discovery are powerful yet modular.

Features

In term of features, all those projects leverage the feature of graphql-java, they will be very similar.

Active development and community adoption

graphql-java-tools was updated yesterday, spqr and graphql-java-annotations last year, graphql-java-codegen in January. From reading stackoverflow questions, graphql-java-tools and spqr seem to be the most popular - but I could be wrong.

Limitations

None that I can think of.

Ease of use

SPQR wins that one for me, the annotations are really intuitive and will get you going super quickly. There is also a spring-boot-starter and a few sample projects. graphql-java-tools is a bit more complex but they have a good documentation and sample projects. I would recommend SPQR for smaller/new projects and graphql-java-tools for bigger projects or existing projects that needs to build a graphql-api on top of an existing code base. For my personal projects, I moved to SPQR and never regretted it.

Open Source

All the projects referenced in this answer are open source.

Final word:

I think the code-first approach (define your api in java, let the library generate your schema) or schema-first approach (define your api in a schema file, let the library generate your code) is probably the most important factor in deciding which library to go for. You can read my answer and Kaqqao's (SPQR author) excellent answer to learn more.

AllirionX
  • 1,073
  • 6
  • 13
  • Thank You @AllirionX , I can see there are lot of options for Server, I am mainly looking for Client Library for now. Apollo Client seems to be very popular, was thinking if there are some other options for comparison purpose. – Ashu May 18 '22 at 09:01
  • Apollo Client is indeed popular, well documented, available in multiple languages, multi platform. My company uses it in production and it's doing the job for us. – AllirionX May 18 '22 at 09:25
0

If you are following schema-first approach and would like to generate client-side classes, I recommend using https://github.com/kobylynskyi/graphql-java-codegen.

Here are a few examples of how you can use generated classes to build requests and call GraphQL API from Java:

Bogdan Kobylynskyi
  • 1,150
  • 1
  • 12
  • 34