Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 13 additions & 9 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -425,21 +425,25 @@ Note: This tutorial was updated on macOS 11.6.2.
defmodule ZeroPhoenixWeb.Graphql.Schema do
use Absinthe.Schema

import_types ZeroPhoenix.Graphql.Types.Person
import_types(ZeroPhoenixWeb.Graphql.Types.Person)

alias ZeroPhoenix.Repo
alias ZeroPhoenix.Account.Person
alias ZeroPhoenix.Account

query do
field :person, type: :person do
arg :id, non_null(:id)
resolve fn %{id: id}, _info ->
case ZeroPhoenix.Person|> Repo.get(id) do
nil -> {:error, "Person id #{id} not found"}
person -> {:ok, person}
arg(:id, non_null(:id))

resolve(fn %{id: id}, _info ->
case Account.get_person(id) do
%Person{} = person ->
{:ok, person}

_error ->
{:error, "Person id #{id} not found"}
end
end
end)
end
end
end
```

Expand Down
10 changes: 6 additions & 4 deletions lib/zero_phoenix_web/graphql/schema.ex
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ defmodule ZeroPhoenixWeb.Graphql.Schema do

import_types(ZeroPhoenixWeb.Graphql.Types.Person)

alias ZeroPhoenix.Repo
alias ZeroPhoenix.Account.Person
alias ZeroPhoenix.Account

Expand All @@ -12,9 +11,12 @@ defmodule ZeroPhoenixWeb.Graphql.Schema do
arg(:id, non_null(:id))

resolve(fn %{id: id}, _info ->
case Person |> Repo.get(id) do
nil -> {:error, "Person id #{id} not found"}
person -> {:ok, person}
case Account.get_person(id) do
%Person{} = person ->
{:ok, person}

_error ->
{:error, "Person id #{id} not found"}
end
end)
end
Expand Down