r/graphlinkdotdev • • 21d ago

We replaced our hand-written REST client with a schema-generated one: what improved, and what didn't change

Short version of the article: the backend behind optidialysis.com called Keycloak through Spring RestClient, with paths, headers and form bodies spread through one service. We moved it to a 95-line GraphQL schema with REST directives and generated the Java client from it (JDK HttpClient, no new HTTP library).

What improved: the whole contract is one reviewable file, contract drift is a compile error, there are no response classes to write by hand, and the client is easy to test against a fake server on the wire. The same schema can generate other languages, but we only ran Java.

What didn't change: our line count (359 to 362), because our server mode already generated the response types. The generator also can't do DELETE with a body, so one call is hand-built through the generated adapter. Full list of rough edges is in the article.

Full Article here

2 Upvotes

2 comments sorted by

3

u/trodiix 21d ago

Why don't you just use the admin-client provided by keycloak instead of reinventing the wheel?

1

u/graphlinkdev 20d ago

I wanted to proof concept the graphlink generator without bloating the app with the dependency because KC already has both rest and form based communication (which graphlink supports out of the box). I am a real believer that having more generated code for most languages is the right way to do software. I got inspired by svelte, retrofit and flutter (dart) and I have seen both reflection heavy frameworks and code generator ones.