Ordering API

Learn how to build ordering API in GraphQL.

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:

Press + to interact
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 ...