Skip to content

Instantly share code, notes, and snippets.

View pmk1c's full-sized avatar

Ruben Grimm pmk1c

  • Münster, Germany
  • 09:57 (UTC +02:00)
View GitHub Profile
class BlogPrependI18nPath < Middleman::Extension
option :blog_name, 'blog'
def after_configuration
manipulator = Manipulator.new(@app, options)
@app.sitemap.register_resource_list_manipulator(:"fix_i18n_article_paths_#{options.blog_name}", manipulator)
end
class Manipulator
def initialize(app, options)
@pmk1c
pmk1c / relacs.json
Last active April 12, 2018 15:28
Lactose data
[ {
"id": 1,
"title": "Buttermilch",
"lactose": 4
}, {
"id": 2,
"title": "Magermilch UHT",
"lactose": 4.7
}, {
"id": 3,
defmodule Restql.Web.PostController do
use Restql.Web, :controller
def index(conn, _params) do
posts = Restql.Blog.list_posts
json conn, posts
end
end
@pmk1c
pmk1c / post_controller.ex
Last active July 17, 2017 09:04
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 {
@pmk1c
pmk1c / post_controller.ex
Last active July 17, 2017 09:02
RestQL - create function in PostController with GraphQL
defmodule Restql.Web.PostController do
# ...
def create(conn, %{"post" => post_params}) do
graphql conn, """
mutation CreatePost($title: String!, $body: String!) {
post(title: $title, body: $body) {
id
}
}
""", post_params
@pmk1c
pmk1c / post_resolver.ex
Created June 12, 2017 12:32
RestQL - create in PostResolver
defmodule Restql.Blog.PostResolver do
# ...
def create(args, _info) do
Restql.Blog.create_post(args)
end
# ...
end
@pmk1c
pmk1c / schema.ex
Created June 12, 2017 12:32
RestQL - CreatePost manipulation in GraphQL Schema
defmodule Restql.Blog.Schema do
# ...
mutation name: "CreatePost" do
field :post, type: :post do
arg :title, non_null(:string)
arg :body, non_null(:string)
resolve &Restql.Blog.PostResolver.create/2
end
end
# ...
@pmk1c
pmk1c / post_resolver.ex
Last active June 12, 2017 11:55
RestQL - PostResolver
defmodule Restql.Blog.PostResolver do
def all(_args, _info) do
{:ok, Restql.Blog.list_posts |> Restql.Repo.preload(:author)}
end
end
@pmk1c
pmk1c / schema.ex
Created June 12, 2017 11:11
RestQL - GraphQL Schema
defmodule Restql.Blog.Schema do
use Absinthe.Schema
import_types Restql.Blog.Schema.Types
query do
field :posts, list_of(:post) do
resolve &Restql.Blog.PostResolver.all/2
end
end
end
@pmk1c
pmk1c / types.ex
Last active June 12, 2017 11:09
RestQL - GraphQL Types
defmodule Restql.Blog.Schema.Types do
use Absinthe.Schema.Notation
object :post do
field :id, :id
field :title, :string
field :body, :string
field :author, :user
end