Marking Arguments as Non-Null

In the last section, you saw variable declarations that featured use of exclamation marks to ensure variable values were provided. It looked something like this:

 query (​$​​filter:​ MenuItemFilter​!​) {
  menuItems(​filter:​ ​$​filter) {

The document here declares that the $filter variable is a MenuItemFilter, while the addition of an exclamation mark denotes that a value is mandatory. This is a constraint that the document designer (usually a front-end developer) builds into the query, but the schema designer can enforce non-null constraints on the backend as well.

Let’s say, for instance, that we wanted to ensure that a filter was always provided to the :menu_items field, regardless of what the ...

Get Craft GraphQL APIs in Elixir with Absinthe now with the O’Reilly learning platform.

O’Reilly members experience live online training, plus books, videos, and digital content from nearly 200 publishers.