You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
If we do not add the annotation, it would be treated as null.
Without annotation it will be treated as "Source" object. And the source for fields of the Query type is null.
@QueryMappingUserfindUserById(@ArgumentStringid) { // here source would be null, because we are at the root returnuserService.findUserById(id);
}
@SchemaMapping(type = "User", field = "name")
StringuserName(Usersource) {
returnsource.getName().toUppercase();
}
This is by design, having @Argument is expected and documented indeed.
For what it's worth @PathVariable and @RequestBody are both required. @RequestParam and @ModelAttribute are not, and between the two it's decided depending on whether it is a "simple" type vs command object. In the case here, however, the source/parent doesn't have to be complex type, see #370.
So at the end of the day, we can only do this for the source/parent or for arguments, but not both, and source/parent didn't even require an annotation for any customizations, unlike arguments.
We can't change this but we could have better handling for this illegal state case, avoiding the NPE, and having a better message to state clearly that a method parameter without an annotation is treated as the source.
rstoyanchev
changed the title
NullPointerException when not using @Argument annotation
Improve handling of case where a source/parent is expected and is null
Jul 1, 2022
Given the following schema:
and the following controller
it will explode with:
The only way to fix this right now is to annotate the argument correctly with
@Argument
but new users of this framework might not know this.The text was updated successfully, but these errors were encountered: