Skip to content

Better generation for parameters - #237

Merged
etienne-sf merged 1 commit into
graphql-java-generator:masterfrom
klafbang:absent-and-default-parameters
Nov 17, 2025
Merged

Better generation for parameters#237
etienne-sf merged 1 commit into
graphql-java-generator:masterfrom
klafbang:absent-and-default-parameters

Conversation

@klafbang

Copy link
Copy Markdown
Contributor

Parameters will null values

A query like this

query HomeQueryRendererAllPostQuery($first: Int, $last: Int) {
  viewer {
    announcements(first: $first, last: $last) {
      edges {
...

with parameters first = 1, last = null would generate

query HomeQueryRendererAllPostQuery($first: Int, $last: Int) {
  viewer {
    announcements(first: $first) {
      edges {

leading to errors with backends checking parameters are used; this is fixed here.

Parameters with default values

Also, queries with default parameters like this

query HomeQueryRendererAllPostQuery($first: Int, $last: Int = 1) {
  viewer {
    announcements(first: $first, last: $last) {
      edges {

were not supported; this too has been added.

@github-actions github-actions Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hello, thank you for your first pull resquest! :)

@etienne-sf

Copy link
Copy Markdown
Collaborator

Thank you for the PR.
:)

I'll add JUnit tests to check that, before merging your PR

Étienne

@etienne-sf
etienne-sf merged commit 1923468 into graphql-java-generator:master Nov 17, 2025
1 check passed
@etienne-sf

Copy link
Copy Markdown
Collaborator

FYI, the first part of the PR is ok.
But the second one isn't: it works only if the default value is one token wide.
And reading a parameter value is tricky: it allows me to finish restructuring a part of the code, that I'm not satisfied with

Once this is done, I'll release a new version with your PR.

Étienne

@klafbang

Copy link
Copy Markdown
Contributor Author

Thanks for checking and good point – I was only dealing with a case of simple single-token values, so I didn't consider more elaborate ones. Let me know if you need anything from me.

@etienne-sf

Copy link
Copy Markdown
Collaborator

Thanks for the proposal, but impacts are quite huge for this "little" thing. And I'm glad to improve the code, there.

BTW, is there any reason why you changed many InputParameter's methods from private to protected ?

I'm in the process of setting them back to private.

@klafbang

Copy link
Copy Markdown
Contributor Author

I made them protected to make it possible to extend the classes and patch functionality without having to replace them. Being private, I have no choice by to replace the class if I need a non-standard feature, but being protected, I can extend the class and override the behavior.

In the end, them being protected makes not difference for this PR.

@etienne-sf

Copy link
Copy Markdown
Collaborator

Hello,

I commited a complementary update to generalize the use of Default Value.
Would you have the opportunity to check that it works ok in your context ?

FYI, it was quite a big commit: 60 files were changed.

Then, about:

In the end, them being protected makes not difference for this PR.

Yes of course. But this method should remain privates, according to me. Nevertheless, I let them as you changed them, as you did this PR.

Etienne

@klafbang

Copy link
Copy Markdown
Contributor Author

Hi Etienne,

Apologies for the late answer - been busy with other things.

I tested the newest version in master and it seems to work just fine for me. Seems to also solve another issue I've encountered in my version, so that's great.

FYI, when compiling master, I noticed it does not compile with Java 25. Works fine with Java 17, though.

@etienne-sf

Copy link
Copy Markdown
Collaborator

Ok, thanks for the PR, the test, and the comment about java 25.
I'll release what's read, and give a try to java 25

@etienne-sf

Copy link
Copy Markdown
Collaborator

I just released the 3.1 version

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants