AWS AppSync allow to define default values in schema like that
type Foo {
bar(
arg: Int = 20
): Bar!
}
or that
type Foo {
bar(
arg: Int! = 20
): Bar!
}
But either way when the value is not explicitly defined, the default value is not passed to the resolver.
Is there something I should opt-in to activate the default value to be passed? Is that an AWS bug? If so, is there a workaround?
PS: In the GraphQL specs
If no value is provided for a defined input object field and that field definition provides a default value, the default value should be used. If no default value is provided and the input object field’s type is non‐null, an error should be thrown. Otherwise, if the field is not required, then no entry is added to the coerced unordered map.
In GraphQL you can assign Default values to the variables. It's done by by adding the default value after the type declaration in your query. If Default values are provided for all variables, you can call the query without passing any variables.
Data sources and resolvers are how AWS AppSync translates GraphQL requests and fetches information from your AWS resources. AWS AppSync has support for automatic provisioning and connections with certain data source types.
AppSync is a managed service that uses GraphQL to make it easy for applications to get exactly the data they need.
Default arguments are currently a known issue and the best way to get around them is to use the $util.defaultIfNull()
velocity helper function. For example, you can default arguments for limit and next token doing something like this:
{
"version": "2017-02-28",
"operation": "Scan",
"limit": $util.defaultIfNull($ctx.args.first, 20),
"nextToken": $util.toJson($util.defaultIfNullOrEmpty($ctx.args.after, null)),
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With