Modeling Input Objects

Up to this point, we’ve been adding arguments directly onto our fields, but this can get messy. Imagine, for instance, if we wanted to add various filtering options to our :menu_items field. We could just add them à la carte:

 @desc ​"​​Matching a category name"
 arg ​:category​, ​:string
 @desc ​"​​Matching a tag"
 arg ​:tag​, ​:string
 
 @desc ​"​​Priced above a value"
 arg ​:priced_above​, ​:float
 
 @desc ​"​​Priced below a value"
 arg ​:priced_below​, ​:float

Mixed in with other arguments that we add to the field, this can quickly become a hodgepodge of various flags and options that would be better organized into related groupings. GraphQL gives us a tool to do this: input object types.

We can collect multiple ...

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

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.