-
Notifications
You must be signed in to change notification settings - Fork 181
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
Default values not working for @GraphQLArgument in 0.9.8 #163
Comments
Ouch 😫 |
I'm glad to help you if you can point me to the class where it is likely broken. |
A quick test in Java doesn't seem to replicate the issue for me: @GraphQLQuery(description = "Queries nearby ShoutOuts, that should be displayed on the map for the given user.")
public Collection<String> discoverShoutOuts(Double lat, Double lng, @GraphQLArgument(name = "radiusInMeters", defaultValue = "50000") Double radiusInMeters) {
return Collections.emptyList();
}
|
After digging deeper, it seems like when I execute a GraphQL request with the value not specified, it works fine and it uses the default value. However, GraphiQL shows me an error that a required argument is not specified. Looking at the introspection query response, it seems like the defaultValue is there, but the field is
So I can't tell it it's a bug or it is supposed to be like this. |
I checked the code at |
In 0.9.8, primitives are always non-null, and I unfortunately don't know enough Kotlin to say what is primitive and what isn't 😕 |
Also, it might be worth to try the latest version of GraphiQL, as it sounds like a possible bug in there... but I'm not sure how to interpret this behavior yet. |
Yes, it is recognized as a primitive. If I make a type nullable in Kotlin, for example: Int?, that's when it is represented as Integer in Java. So going back to the previous example:
It is clear that radiusInMeters is a double primitive and it's non-nullable, and that's exactly what I want in the CODE. But since a defaultValue is provided, it is not required to specify this argument. Conclusion: is it possible to make arguments that have a default value nullable in the schema? I guess it would make sense?! Thanks :) |
I remembered having a reason to leave primitives alone, but I forgot what it was and making them non-null seemed logical... Now the reason is apparent. To replace a mapper: generator.withTypeMappers((conf, current) -> current.replace(NonNullMapper.class, new CustomNonNullMapper())) |
The GraphQL spec has changed to better deal with non-null arguments with a default value. |
My commit makes sure everything with a default value is nullable, so that will be the behavior in 0.9.9. When graphql-java catches up with the spec, I'll probably have to revert that bit. |
HI!
Great release for 0.9.8, it was long awaited :)
One issue I encountered with 0.9.8 is that
@GraphQLArgument
seems to ignoredefaultValue
.I have the following code:
After upgrading to 0.9.8 the
radiusInMeters
argument is required and doesn't have a default value.Is there anything to do with it to make it work?
I tried to debug it, and I see that in
AnnotatedArgumentBuilder
, thedefaultValue()
method correctly returns the value I specified, so the problem must be afterwards.The text was updated successfully, but these errors were encountered: