Description
Similar as for traditional controllers the @RequestParam
annotation supports a defaultValue
, it would be nice to have this for the GraphQL @Argument
annotation as well.
Rationale:
Imagine this Query
definition:
seasons(first: Int = 10, offset: Int = 0): SeasonPage!
here default values are specified in the GraphQL schema, and if not provided by the user the defaults are used automatically.
But the above Season
type could have the following field:
type Season {
standings(first: Int, offset: Int = 0): StandingPage!
}
here the first
argument has no default value in the GraphQL schema, basically meaning there is no limit and by default all standings are returned unless the limit is explicitly set by the client.
Now having a SchemaMapping
for this like:
@SchemaMapping
public Page<Standing> standings(Season season, @Argument int first, @Argument int offset) { .. }
will fail as null
is an illegal argument for the first
argument.
It would be nice to define the SchemaMapping
like:
@SchemaMapping
public Page<Standing> standings(Season season, @Argument(defaultValue = "99999") int first, @Argument int offset) { .. }
See the arbitrary 99999
as default value which in this proposal will be used when the argument is not passed, or set to null by the client.
I don't want the 99999
in the GraphQL schema itself as it is an arbitrary value without a real meaning,
unlike offset = 0
or first = 10
in the query mapping.
Without a defaultValue
I can solve it on other ways to:
- Like mentioned above, add an arbitrary value like
99999
to the GraphQL schema. But even then a client could passnull
which will break the controller - Change the code to
@Argument Integer first
and test myself onnull
; this will also make sure the controller won't break.