GraphQL Client - New typesafe API desired (and already prototyped) #52675
Replies: 3 comments 5 replies
-
|
\CC @jmartisk |
Beta Was this translation helpful? Give feedback.
-
You should be able to annotate the field with either
So what exactly does it fetch on the first call (when you call Another thing is that the @t1 as the main author of the original typesafe client should be involved |
Beta Was this translation helpful? Give feedback.
-
|
Here's a working example: |
Beta Was this translation helpful? Give feedback.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
-
Summary: I started a rewrite of Smallrye GrapheQL typesafe client. Are you interested? I have a starting prototype.
I need to interact with Github's GraphQL API. Because of a limitation, Smallrye Graph QL Typesafe client is unusable. Specifically, raw strings field variables are "String!" while Smallrye treats strings as "String". I couldn't find a workaround for this from the docs. (Maybe there is something?).
I also found the client typesafeAPI awkward, more verbose than needed, and inefficient, so I wrote a replacement.
Github Graqph ql has a ton of nested queries under repository, where repository requires owner and name parameters. With Smallrye I had to provide these parameters for every different item under repository I was querying for. Parameter lists just got longer and longer. So, I wanted to create something like JAX-RS subresource locators, but on the client side. Here's an example:
So, basically given the above, I only have to enter in the repo field variables once, then can make any other queries I want on the Repository interface. The proxy automatically inserts query { repository(owner: "quarkusio", name: "quarkus" when calling @query methods under Repository interface.
Next thing I found is that for Smallrye I had to model the whole graph schema in Java classes even though I wanted a small nested part of the graph. I wanted to create a shortcut for this. Here's an example
The client proxy knows to navigate through the returned result json to the actual json node I want to unmarshal into DiscussionCommentsConnection.
The comments method would produce this query
@inputType on a method parameter specifies the variable type. Can also be put on a class too.
@GraphField on a method uses that value instead of the method name for a field reference
@variable on a method parameter specifies the field variable name instead of the default argument name.
@DefaultVariable on a method allows you to define default field variables and their values.
Beta Was this translation helpful? Give feedback.
All reactions