Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feature: Add support for specifying variables in client generation #1998

Open
loonis opened this issue Sep 6, 2024 · 2 comments
Open

feature: Add support for specifying variables in client generation #1998

loonis opened this issue Sep 6, 2024 · 2 comments
Labels
backlog codegen enhancement New feature or request

Comments

@loonis
Copy link

loonis commented Sep 6, 2024

Describe the Feature Request

Add support for specifying variables in client generation.
This is needed operation caching : for https://netflix.github.io/dgs/advanced/operation-caching/

Describe Alternatives

Workarrounds are

@loonis loonis added the enhancement New feature or request label Sep 6, 2024
@paulbakker
Copy link
Collaborator

While this is conceptually a feature that makes a lot of sense, there is some difficulty in implementing this nicely.
The generated builder methods take the appropriate Java type as input. E.g. an Int input argument is represented by a builder method that takes an Integer.
I'm not sure how we would best represent a variable in such cases. For a String input it's easy to imagine simply setting the value to $someInputVar, but how would that work for other types?

FWIW, for these more complex queries, we've been recommending more and more to just specify them as a multi-line String in code, annotated with @Language("GraphQL"). The generation of query builders was introduced before multi-line Strings were available in Java, which made it ugly to specify queries as Strings. However, that's no longer an issue.
Of course this means there is no compile time checks on queries, but the compiler would never guarantee correctness in any case, because the "client schema" might be outdated. You need tests to verify if the queries actually work.

@loonis
Copy link
Author

loonis commented Sep 12, 2024

I have nothing to add, you said it all :)
We'll have to choose between benefiting from type checking at compile time and the performance offered by query caching.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
backlog codegen enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

2 participants