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

Cannot use dynamic graphql client to invoke mutation with non-null parameter #2259

Open
frisket opened this issue Jan 22, 2025 · 4 comments
Open

Comments

@frisket
Copy link

frisket commented Jan 22, 2025

I'm attempting to call a graphql API that has a non-null parameter defined.

Eg, with a schema like this:

type Film {
title: String
}

mutation {
updateTitle(name: Film!) {
title
}
}

I cannot invoke the "updateTitle" API because I get a name validation error trying to build the graphql client.

The specific exception I get is:

java.lang.IllegalArgumentException: Invalid name: Film!
        at io.smallrye.graphql.client.core.utils.validation.NameValidation.validateName(NameValidation.java:68)
        at io.smallrye.graphql.client.core.VariableType.varType(VariableType.java:17)
        at io.smallrye.graphql.client.core.Variable.var(Variable.java:77)

Attempting to invoke as so:

Document document = Document.document(
	                                       operation(
					                OperationType.MUTATION,
							List.of(var("rec", "Film!")),
					                field("updateTitle", arg("name", var("rec", "Film")))
					        ));

Response response = dynGraphqlClient.executeSync(document, Map.of("rec", film));

I am able to send the same query manually via other tools (eg: Altair) to the endpoint succesfully.

Found this older ticket that seems similar: quarkusio/quarkus#18194

@mskacelik
Copy link
Contributor

mskacelik commented Jan 24, 2025

Hi @frisket, try using io.smallrye.graphql.client.core.VariableType.nonNull method to wrap the Film type instead of using an explicit !
Something like this should work (my reproducer):

    Variable inputVar = Variable.var("arg1", nonNull("String")); // ScalarType.GQL_STRING
    Document query = document(
            operation(vars(inputVar), field("returnSomething", arg("input", inputVar))
        )
    );
    Response response = client.executeSync(query, Map.of("arg1", "Hello"));

The problem is that we added naming validators, and they do not accept characters such as !, [, ]. But this might be considered a bug (because I did not think of use explicitly like that (same with lists)), so I might try to add an additional naming rule for types. @jmartisk wdyt?

@jmartisk
Copy link
Member

I would say that using these wrapper methods to denote non-null and arrays is intentional and good, it makes the code a bit more type-safe, no? I would say that we could update the IllegalArgumentException's message in a way that if it detects that the user wrapped a type in [] or added !, it will tell the user to use the proper methods instead of this.

@mskacelik
Copy link
Contributor

Yeah, the error messages for the validators are lacking and don't say anything of importance in general.

@mskacelik
Copy link
Contributor

Yeah, the error messages for the validators are lacking and don't say anything of importance in general.

PR: #2260

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

No branches or pull requests

3 participants