Skip to content

Instantly share code, notes, and snippets.

@robertkowalski
Last active September 27, 2016 22:26
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 robertkowalski/80190137314664cb9b904a18298686ac to your computer and use it in GitHub Desktop.
Save robertkowalski/80190137314664cb9b904a18298686ac to your computer and use it in GitHub Desktop.
handle_graphql(Req) ->
Res = 'Elixir.Chttpd.Graphql':run(),
io:format("~p", [Res]),
send_json(Req, {[
{res, "Res"}
]}).
defmodule Chttpd.Graphql do
def run() do
doc = """
{
item(id: "foo") {
name
}
}
"""
Absinthe.run(Chttpd.Schema, variables: %{"id" => "foo"})
end
end
defmodule Chttpd.Schema do
use Absinthe.Schema
@fake_db %{
"foo" => %{id: "foo", name: "Foo", value: 4},
"bar" => %{id: "bar", name: "Bar", value: 5}
}
query do
@desc "Get an item by ID"
field :item, type: :item do
@desc "The ID of the item"
arg :id, :id
resolve fn %{id: id}, _ ->
{:ok, Map.get(@fake_db, id)}
end
end
end
@desc "A valuable item"
object :item do
field :id, :id
field :name, :string, description: "The item's name"
field :value, :integer, description: "Recently appraised value"
end
end
@robertkowalski
Copy link
Author

robertkowalski commented Sep 27, 2016

[error] 2016-09-27T22:19:33.767466Z node1@127.0.0.1 <0.625.0> 9541968053 req_err(3420399751) unknown_error : undef
    [<<"Elixir.Exception:normalize/2">>,<<"Elixir.Absinthe:parse/1 L187">>,<<"Elixir.Absinthe:run/3 L254">>,<<"chttpd_misc:handle_graphql/1 L51">>,<<"chttpd:process_request/1 L293">>,<<"chttpd:handle_request_int/1 L229">>,<<"mochiweb_http:headers/6 L122">>,<<"proc_lib:init_p_do_apply/3 L240">>]
[notice] 2016-09-27T22:19:33.767803Z node1@127.0.0.1 <0.625.0> 9541968053 localhost:15984 127.0.0.1 undefined GET /_graphql 500 ok 15

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment