A simple Elixir toy app built to demonstrate how we can set up a GraphQL endpoint for registering users, and storing user and other relevant information to a database. Our goal is to persist only data that is valid, or return a helpful error otherwise. We’ll leverage Ecto.Multi and Ecto.Repo.transaction to write a clean user registration flow and handle errors elegantly.
NomNomsFarm is a new food cart serving the neighborhood with local, organic, fair trade, free-range, farm-fresh, artisinal delicacies. We're in charge of running logistics for NomNomsFarm and we need to build an online registration flow for local farms to become part of the food cart's supply chain.
- Clone the repo.
- Run
mix deps.get
to download the dependencies. - In the repo run
mix setup
. (This will create the database, migrate the schema, and seed the USDA farms table.)
- run
iex -S mix phx.server
- Go to
http://localhost:4000/graphiql
- Run mutations. Try:
mutation {
registerFarmAdmin(
username: "bart",
password: "password",
name: "Bartleby",
email: "bart@bartlebysons.com",
usdaUid: "00920",
)
}
- Run
MIX_ENV=test mix setup
- run
mix test
Please reach out with questions, comments or suggestions for how we can improve.
Thanks!