Marx
Marx

Reputation: 840

GraphQL-java with Spring - resolvers vd datafetcher

There's total mess with GraphQL and Java (Spring). There are multiple projects, and multiple examples, but totally inconsistent.

What I understand Spring Boot should gives is OOTB working solution, and (to some extent) it works like this. Project which gives you such experience is on Github https://github.com/graphql-java-kickstart. Especially https://github.com/graphql-java-kickstart/graphql-spring-boot gives you possibility to create schema, make resolver and everything else is done automatically.

Problem is when you try to replace resolver - which seems like very simply datafetcher - with custom datafetcher. As I know there's no possibility to make asynchronous resolver, or batched resolver - you have to make datafetcher.

To make custom datafetchers one needs to make custom wiring etc, replacing spring-boot solution, or using it somehow (how?). There's no single point of true, how to do that properly. I even found that BatchedDataFetcher are deprecated(!) before they even get a good Spring Boot support/example (see: GraphQL Java: Using @Batched DataFetcher)

Because of that I even don't know where to look for solution. What I would welcome to see is to have an example which has:

Upvotes: 2

Views: 3257

Answers (2)

Ken Chan
Ken Chan

Reputation: 90447

Anyway, the answer is: use graphql-java-kickstart projects, as those from https://www.graphql-java.com/ are outdated. This fact is very misleading and should be stated somewhere.

Not really. graphql-java is only GraphQL java implementation that I know so far. It defines DataFetcher. It is the core library while other projects that you find such as java-kickstart (or to be more precise its graphql-java-tool) is built on top of the graphql-java and it defines its own implementation of the DataFetcher which is called Resolver.

In the end , the Resolver is just a DataFetcher.

You can find more related information about these two projects in this blog post.

So if you want to have the most flexibility when building the GraphQL server , use graphql-java . On the other hand , if you like the opinionated way that is used by graphql-java-tool , uses it.

Upvotes: 6

Marx
Marx

Reputation: 840

My question was caused by 2 different frameworks which works with graphql-java. Few days later I know that days of datafetchers are gone (which is promoted on https://www.graphql-java.com/tutorials/getting-started-with-spring-boot/).

Now, if you want to go simply, you can make resolvers and you're done: https://github.com/graphql-java-kickstart If you want go deeper, you should make dataloaders: https://github.com/graphql-java/java-dataloader

Anyway, the answer is: use graphql-java-kickstart projects, as those from https://www.graphql-java.com/ are outdated. This fact is very misleading and should be stated somewhere.

Upvotes: 2

Related Questions