Search⌘ K
AI Features

Ordering API

Explore how to build an ordering API in Elixir using GraphQL mutations with Absinthe. Learn to define input types, create schema mutations, and test using the GraphiQL interface to handle orders accurately without price manipulation.

We'll cover the following...

Building the ordering API

The context function we just built provides an accurate indicator of what our GraphQL inputs should look like. We’re expecting a list of items we want to order and an optional customer reference number. Notably, the items don’t contain any price info, as that should always be looked up from the menu system (to make sure clients aren’t changing the prices). Add the following field to your mutation object in schema.ex file:

import_types __MODULE__.OrderingTypes
# «Other schema content»
mutation do
field :place_order, :order_result do
arg :input, non_null(:place_order_input)
resolve &Resolvers.Ordering.place_order/3
end
# «other types»
end

This field relies on types sourced by import_types/1 from a separate ...