Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

How to handle missing data? #27

Open
zimt28 opened this issue Dec 9, 2017 · 1 comment
Open

How to handle missing data? #27

zimt28 opened this issue Dec 9, 2017 · 1 comment

Comments

@zimt28
Copy link

zimt28 commented Dec 9, 2017

Using Phoenix alone I handled missing data ("not found") by just using Ecto's ! functions (one! etc.). These raise an Ecto.NoResultsError, which Phoenix can handle via a Plug.Exception implementation to show a 404 page.

I'm now changing my app to use Absinthe.Phoenix.Controller and would like to know what's the best way to handle these cases.

My current approach looks like this, but it's quite repetitive. I'm using the new action_fallback macro from Phoenix 1.3.

  @graphql """
  query ($id: ID!) {
    file(id: $id) @put {
      owner
    }
  }
  """
  def show(conn, %{data: %{file: nil}}), do: {:error, :not_found}
  def show(conn, %{data: data}) do
    render(conn, "show.html", file: data.file)
  end

Is there a better/ suggested way to do this properly?

@zimt28
Copy link
Author

zimt28 commented Dec 15, 2017

Just a thought: Maybe it's possible to build a directive, so that something which has been configured gets returned/ raised?

Just like

  @graphql """
  query ($id: ID!) {
    file(id: $id) @required @put {
      owner
    }
  }
  """

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant