This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
[ { | |
"id": 1, | |
"title": "Buttermilch", | |
"lactose": 4 | |
}, { | |
"id": 2, | |
"title": "Magermilch UHT", | |
"lactose": 4.7 | |
}, { | |
"id": 3, |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
defmodule Restql.Blog.PostResolver do | |
# ... | |
def create(args, _info) do | |
Restql.Blog.create_post(args) | |
end | |
# ... | |
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | |
# ... |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
defmodule Restql.Blog.PostResolver do | |
def all(_args, _info) do | |
{:ok, Restql.Blog.list_posts |> Restql.Repo.preload(:author)} | |
end | |
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
defmodule Restql.Web.PostController do | |
use Restql.Web, :controller | |
alias Restql.Blog | |
alias Restql.Blog.Post | |
def index(conn, _params) do | |
graphql conn, """ | |
{ | |
posts { |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
defmodule Restql.Web.PostController do | |
use Restql.Web, :controller | |
def index(conn, _params) do | |
posts = Restql.Blog.list_posts | |
json conn, posts | |
end | |
end |