Last active
July 16, 2018 12:57
-
-
Save zacck-zz/8cae1a57a92a754a2793569261585267 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
{ user { fullName }} | |
query do | |
field :user, :user do | |
resolve fn _, _ -> | |
{:ok, %{first_name: "Bruce", last_name: "Williams"}} | |
end | |
end | |
field :hello, :string do | |
arg :name, :string | |
resolve fn %{name: name}, _ -> | |
{:ok, "hello #{name}"} | |
end | |
end | |
end | |
object :post do | |
field :title, :string | |
end | |
object :user do | |
field :full_name, :string do | |
resolve fn user, _, _ -> | |
{:ok, "#{user.first_name} #{user.last_name}"} | |
end | |
end | |
field :posts, list_of(:post) do | |
resolve &get_posts/3 | |
end | |
end | |
## GENERATES | |
def __absinthe_middleware__(:user, :full_name) do | |
[ | |
{{Absinthe.Resolution, :call}, | |
fn user, _, _ -> {:ok, "#{user.first_name()} #{user.last_name()}"} end} | |
] | |
end | |
def __absinthe_middleware__(:query, :user) do | |
[ | |
{{Absinthe.Resolution, :call}, | |
fn _, _ -> {:ok, %{first_name: "Bruce", last_name: "Williams"}} end} | |
] | |
end | |
def __absinthe_middleware__(:query, :hello) do | |
[{{Absinthe.Resolution, :call}, fn %{name: name}, _ -> {:ok, "hello #{name}"} end}] | |
end | |
def __absinthe_serialize__(:scalar, :string, :serialize)) do | |
&to_string/1 | |
end | |
def __absinthe_parse__(:scalar, :string, :parse) do | |
fn input, _ -> {:ok, to_string(input.value())} end | |
end | |
object :user do | |
field :blah, :string do | |
resolve &to_string/1 | |
end | |
is_type_of fn _, _ -> | |
true | |
end | |
end | |
union :test_result do | |
types [:pass, :fail] | |
resolve_type fn _, _ -> end | |
end | |
## What I want is | |
object :post do | |
field :title, :string | |
field :author, :user | |
end | |
object :user do | |
field :full_name, :string do | |
resolve fn user, _, _ -> | |
{:ok, "#{user.first_name} #{user.last_name}"} | |
end | |
end | |
field :posts, list_of(:post) do | |
resolve &get_posts/3 | |
end | |
end | |
%Absinthe.Blueprint.Schema.ObjectTypeDefinition{ | |
identifier: :post, | |
fields: [ | |
%Absinthe.Blueprint.Schema.InputValueDefinition{ | |
identifier: :title, | |
middleware_ast: ... | |
} | |
] | |
} | |
def __absinthe_function__(Absinthe.Type.Object, :post, {:title, :middleware}) do | |
[] | |
end | |
def __absinthe_function__(Absinthe.Type.Object, :user, {:full_name, :middleware}) do | |
[ | |
{{Absinthe.Resolution, :call}, | |
fn user, _, _ -> {:ok, "#{user.first_name()} #{user.last_name()}"} end} | |
] | |
end | |
def __absinthe_function__(Absinthe.Type.Object, :user, {:posts, :middleware}) do | |
[ | |
{{Absinthe.Resolution, :call}, &get_posts/3} | |
] | |
end | |
def __absinthe_function__(Absinthe.Type.Object, :query, {:hello, :middleware}) do | |
[{{Absinthe.Resolution, :call}, fn %{name: name}, _ -> {:ok, "hello #{name}"} end}] | |
end | |
def __absinthe_function__(Absinthe.Type.Object, :query, {:user, :middleware}) do | |
[ | |
{{Absinthe.Resolution, :call}, | |
fn _, _ -> {:ok, %{first_name: "Bruce", last_name: "Williams"}} end} | |
] | |
end | |
def __absinthe_function__(Absinthe.Type.Union, :test_result, :resolve_type) do | |
fn _, _ -> end | |
end | |
def __absinthe_function__(Absinthe.Type.Object, _identifier, :is_type_of) do | |
fn _, _ -> false end | |
end | |
def __absinthe_function__(Absinthe.Type.Scalar, :string, :serialize)) do | |
&to_string/1 | |
end | |
def __absinthe_function__(Absinthe.Type.Scalar, :string, :parse) do | |
fn input, _ -> {:ok, to_string(input.value())} end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment