Gato GraphQL logo

Field Default Value

Field Default Value

Addition of the @default directive to the GraphQL schema, to set a value to null or empty fields.

{
  post(by: { id: 1 }) {
    featuredImage {
      id
      src
    }
    featuredImageOrDefault: featuredImage @default(value: 55) {
      id
      src
    }
  }
}
{
  "data": {
    "post": {
      "featuredImage": null,
      "featuredImageOrDefault": {
        "id": 55,
        "src": "http://mysite.com/wp-content/uploads/my-default-image.png"
      }
    }
  }
}