Skip to content

Instantly share code, notes, and snippets.

@pmk1c
Last active July 17, 2017 09:04
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save pmk1c/eff062450751d5168678a2bc7fb99e5a to your computer and use it in GitHub Desktop.
Save pmk1c/eff062450751d5168678a2bc7fb99e5a to your computer and use it in GitHub Desktop.
RestQL - PostController with GraphQL
defmodule Restql.Web.PostController do
use Restql.Web, :controller
alias Restql.Blog
alias Restql.Blog.Post
def index(conn, _params) do
graphql conn, """
{
posts {
title
body
author {
name
}
}
}
"""
end
defp graphql(conn, document, variables \\ %{}, schema \\ Restql.Blog.Schema) do
with {:ok, data} <- Absinthe.run(document, schema, variables: variables) do
json conn, data
end
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment