Field Default Value
1 domain | 5 domains | 25 domains |
---|---|---|
$4.99 | $9.99 | $19.99 |
Buying the extension gives you a license for 1 year (renewable every year), that includes support and access to all extension updates. Prices are in USD.
🛍️ Buy “Field Default Value” Extension
@default
directive, to set a value to null or empty fields.
Description permalink
Directive @default
accepts two arguments:
value
: the default value, from any scalar type (string, boolean, integer, float or ID).condition
: if the field must be null or empty, via enum valuesIS_NULL
orIS_EMPTY
. By default it is null.
In the example below, when a post does not have a featured image, field featuredImage
returns null
:
{
post(by: { id: 1 }) {
featuredImage {
id
src
}
}
}
{
"data": {
"post": {
"featuredImage": null
}
}
}
By using @default
, we can then retrieve some default image:
{
post(by: { id: 1 }) {
featuredImage @default(value: 55) {
id
src
}
}
}
{
"data": {
"post": {
"featuredImage": {
"id": 55,
"src": "http://mysite.com/wp-content/uploads/my-default-image.png"
}
}
}
}
Bundles including extension permalink
Recipes using extension permalink
🛍️ Buy “Field Default Value” Extension