It’s time to start creating your project. The First you’ll need to have Elixir and Erlang installed on your machine. See https://elixir-lang.org/install.html
Unlike some frameworks, Phoenix works within the ordinary structure of a regular Elixir application. It does however bring its own generator to add in some basic Phoenix code to get you going.
This tutorial also uses Postgres as the database for this app. See here for installing postgres on your OS: https://wiki.postgresql.org/wiki/Detailed_installation_guides
For OS X users it should be as simple as brew install postgres
.
You’re going to build an app called Community, and you can think of it as a miniature version of Hacker News, Slashdot, or any other site that displays content on the basis of user submissions and votes.
Say y
to the question about fetching and installing dependencies, and then cd into the application directory.
In order to support GraphQL your application needs some additional dependencies which are configured in the mix.exs
file. They go inside the list found within the defp deps do
function:
Add the following lines to priv/repo/seeds.exs
so that you have some basic seed data:
alias Community.News.Link
alias Community.Repo
%Link{url: "http://graphql.org/", description: "The Best Query Language"} |> Repo.insert!
%Link{url: "http://dev.apollodata.com/", description: "Awesome GraphQL Client"} |> Repo.insert!
At this point the database tables have been created, and the migrations ran. If at any point you want to clear everything out you can just run mix ecto.reset
. If you get postgres connection issues be sure to double check your database credentials inside config/dev.exs
.