Ben Wilson
Written By
Ben Wilson
Developer @ Cargosense

A full time Elixir developer at CargoSense, Ben is a co-author of the Absinthe GraphQL implementation for Elixir.

Getting Started

Install Dependencies

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.

Setting up your App

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:

.../graphql-elixir/blob/master/mix.exs
{:absinthe, "~> 1.6"},
{:absinthe_plug, "~> 1.5"}

Add the following lines to priv/repo/seeds.exs so that you have some basic seed data:

.../graphql-elixir/priv/repo/seeds.exs
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.

Next Chapter

Queries

Learn how to define the GraphQL schema with Absinthe, implement query resolvers in Elixir and test your queries in a GraphiQL Playground.

Go to next chapter